Add AMap location and weather header with warm mini program theme
ci-cd / verify (push) Successful in 1m54s
ci-cd / deploy (push) Skipped

This commit is contained in:
2026-10-04 11:03:34 +08:00
parent c2b51f96e0
commit 7fc50f9212
37 changed files with 568 additions and 122 deletions
+31
View File
@@ -0,0 +1,31 @@
package httpapi
import (
"errors"
"github.com/gin-gonic/gin"
"github.com/sundynix/pets-be/internal/environment"
"net/http"
"strconv"
)
func (a *API) environment(c *gin.Context) {
lat, latErr := strconv.ParseFloat(c.Query("latitude"), 64)
lon, lonErr := strconv.ParseFloat(c.Query("longitude"), 64)
if latErr != nil || lonErr != nil {
fail(c, http.StatusBadRequest, "请提供有效的定位坐标")
return
}
result, err := a.env.Lookup(c.Request.Context(), lat, lon)
if err != nil {
status := http.StatusBadGateway
if errors.Is(err, environment.ErrCoordinates) {
status = http.StatusBadRequest
}
if errors.Is(err, environment.ErrNotConfigured) {
status = http.StatusServiceUnavailable
}
fail(c, status, err.Error())
return
}
ok(c, result)
}