Skip to content

Instantly share code, notes, and snippets.

@chilijung
Last active August 29, 2015 14:03
Show Gist options
  • Save chilijung/b64cf2dfbe6dd5c882a6 to your computer and use it in GitHub Desktop.
Save chilijung/b64cf2dfbe6dd5c882a6 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"net/http"
"encoding/json"
)
type Response map[string]interface{}
func (r Response) String() (s string) {
b, err := json.Marshal(r)
if err != nil {
s = ""
return
}
s = string(b)
return
}
func myHandler (w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
fmt.Fprint(w, Response{"success": true, "message": "Hello"})
return
}
func main() {
http.HandleFunc("/", myHandler)
err := http.ListenAndServe(":3000", nil)
if err != nil {
log.Fatal("Listen and serve error: ", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment