Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package main
import (
type coord struct {
Lat float64 `json:"lat"`
Lon float64 `json:"lon"`
type owmResponse struct {
Name string `json:"name"`
Coordinants coord `json:"coord"`
Main struct {
Min float64 `json:"temp_min"`
Max float64 `json:"temp_max"`
} `json:"main"`
var listenOn = ""
func init() {
flag.StringVar(&listenOn, "listen", listenOn, "The address to listen on for web requests")
func handleRequest(w http.ResponseWriter, r *http.Request) {
var owmData owmResponse
vars := mux.Vars(r)
resp, _ := http.Get(fmt.Sprintf(
vars["lat"], vars["lon"]))
dec := json.NewDecoder(resp.Body)
log.Printf("%#v", owmData)
enc, _ := json.Marshal(owmData)
w.Header().Set("Content-Type", "application/json")
func main() {
r := mux.NewRouter()
r.HandleFunc("/get/{lat}/{lon}", handleRequest)
log.Fatal(http.ListenAndServe(listenOn, r))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.