The go language simply handles function instances of http requests

  • 2020-05-26 09:19:20
  • OfStack

This example demonstrates the simple functions of the go language for handling http requests. Share with you for your reference. The specific implementation method is as follows:


func someHandler(w http.ResponseWriter, r *http.Request) {
    // read form value
    value := r.FormValue("value")
    if r.Method == "POST" {
        // receive posted data
        body, err := ioutil.ReadAll(r.Body)
}
func main() {
    http.HandleFunc("/", someHandler)
    http.ListenAndServe(":8080", nil)
}

I hope this article has been helpful to your programming of Go language.


Related articles: