Skip to content

Instantly share code, notes, and snippets.

@ara-ta3
Created September 20, 2017 11:11
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 ara-ta3/1484851d780fb35988d957c8d4f4cc94 to your computer and use it in GitHub Desktop.
Save ara-ta3/1484851d780fb35988d957c8d4f4cc94 to your computer and use it in GitHub Desktop.
sample code using net/http in golang
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
b := ResponseBody{
OK: false,
Message: "Not Implemented",
}
j, e := json.Marshal(b)
if e != nil {
log.Fatalf("%+v", e)
}
fmt.Fprintln(w, string(j))
})
log.Fatal(http.ListenAndServe(":8080", mux))
}
type ResponseBody struct {
OK bool `json:"ok"`
Message string `json:"message"`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment