Files
axis_timelapse/camera/camera.go
2025-10-05 22:13:51 +00:00

34 lines
615 B
Go

package camera
import (
"axis_timelapse/config"
"os"
"strconv"
"time"
"github.com/gofiber/fiber/v2"
"github.com/rs/zerolog/log"
)
func CaptureImage() bool {
request := fiber.Get(config.FullURL)
code, body, err := request.Bytes()
if err != nil {
log.Error().Msgf("Error getting image.")
}
if code != 200 {
log.Error().Msg("Unexpected status code: " + strconv.Itoa(code))
}
timestamp := time.Now()
filename := timestamp.Format("/axis-2006-01-02_15-04-05.jpg")
err1 := os.WriteFile(config.StoragePath+filename, body, 0644)
if err1 != nil {
log.Fatal().Err(err1).Msgf("")
}
return true
}