diff --git a/charts/reverse-geocoding/Chart.yaml b/charts/reverse-geocoding/Chart.yaml index 1d539bd..dae1d74 100644 --- a/charts/reverse-geocoding/Chart.yaml +++ b/charts/reverse-geocoding/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: reverse-geocoding description: Reverse GeoCode Helm chart for Kubernetes type: application -version: &version 0.2.13 +version: &version 0.2.14 appVersion: *version kubeVersion: ">= 1.22" keywords: diff --git a/charts/reverse-geocoding/values.yaml b/charts/reverse-geocoding/values.yaml index a810743..b4c327c 100644 --- a/charts/reverse-geocoding/values.yaml +++ b/charts/reverse-geocoding/values.yaml @@ -3,7 +3,7 @@ replicaCount: 1 image: repository: ghcr.io/saidsef/faas-reverse-geocoding pullPolicy: IfNotPresent - tag: "v2024.02" + tag: "v2024.04" imagePullSecrets: [] nameOverride: "geocode" diff --git a/geocode.go b/geocode.go index 476e6a7..37dcdf9 100644 --- a/geocode.go +++ b/geocode.go @@ -8,7 +8,6 @@ import ( "flag" "fmt" "html/template" - "io" "log" "net/http" "os" @@ -26,6 +25,9 @@ var ( // port defines the port on which the server listens. It can be set via command-line flag. port int + // location response json interface + location interface{} + // logger provides a logging instance prefixed with "[http]" and standard flags. logger = log.New(os.Stdout, "[http] ", log.LstdFlags) @@ -84,20 +86,22 @@ func latitudeLongitude(w http.ResponseWriter, r *http.Request) { } defer resp.Body.Close() - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { + if err := json.NewDecoder(resp.Body).Decode(&location); err != nil { http.Error(w, fmt.Sprintf("Error reading response body: %s", err), http.StatusInternalServerError) return } if resp.StatusCode != http.StatusOK { - http.Error(w, fmt.Sprintf("External API error: %s", string(bodyBytes)), resp.StatusCode) + http.Error(w, fmt.Sprintf("External API error: %s", location), resp.StatusCode) return } // Define a template that safely escapes data. tmpl := template.Must(template.New("safeTemplate").Parse("{{.}}")) - tmpl.Execute(w, bodyBytes) + if err := tmpl.Execute(w, json.NewEncoder(w).Encode(location)); err != nil { + http.Error(w, "Error rendering template", http.StatusInternalServerError) + return + } default: http.Error(w, `{"status": "method not allowed"}`, http.StatusMethodNotAllowed) }