getting there
This commit is contained in:
31
camera/camera.go
Normal file
31
camera/camera.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package camera
|
||||
|
||||
import (
|
||||
"axis_timelapse/config"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"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))
|
||||
}
|
||||
|
||||
// Write the bytes to a file
|
||||
err1 := os.WriteFile("downloaded_image.jpg", body, 0644)
|
||||
if err1 != nil {
|
||||
log.Fatal().Err(err1).Msgf("")
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user