Skip to content

Instantly share code, notes, and snippets.

@calderonroberto
Created October 24, 2015 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calderonroberto/2e6a60c9ca59eef4f485 to your computer and use it in GitHub Desktop.
Save calderonroberto/2e6a60c9ca59eef4f485 to your computer and use it in GitHub Desktop.
A very simple Golang Microservice
package main
import (
"net/http"
"log"
"encoding/json"
)
// The Thing Model, mapping the URL.Query() contents
type Thing struct {
Values map[string][]string
}
// Handles get requests for the /things service
func things(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
thing := Thing{Values: query}
json.NewEncoder(w).Encode(thing)
}
func main() {
http.HandleFunc("/things", things)
log.Fatal(http.ListenAndServe(":9090", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment