Skip to content

Instantly share code, notes, and snippets.

@weaming
Created March 10, 2022 08:39
Show Gist options
  • Save weaming/c8ada49de7c92b9e26f65acd096f7cc2 to your computer and use it in GitHub Desktop.
Save weaming/c8ada49de7c92b9e26f65acd096f7cc2 to your computer and use it in GitHub Desktop.
package main
import (
"io/ioutil"
"log"
"net/http"
)
func index(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"status": "error", "code": 20, "desc": "Database not ready"}`))
if r.Body != nil {
req, e := ioutil.ReadAll(r.Body)
if e != nil {
panic(e)
}
log.Println("request body:", string(req))
}
}
func main() {
http.HandleFunc("/", index)
log.Println("listen 127.0.0.1:8080")
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment