Created
March 10, 2022 08:39
-
-
Save weaming/c8ada49de7c92b9e26f65acd096f7cc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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