Created
September 5, 2017 20:33
-
-
Save m-x-k/e8e521c26a388865ba60a83936efa8ab to your computer and use it in GitHub Desktop.
Golang http request method alternative response
This file contains hidden or 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 "net/http" | |
func main() { | |
mainMux := http.NewServeMux() | |
mainMux.HandleFunc("/speak", func(res http.ResponseWriter, req *http.Request) { | |
if req.Method == "GET" { | |
res.Write([]byte("Hello, World!\n")) | |
} else if req.Method == "POST" { | |
res.Write([]byte("Thank You!\n")) | |
} else if req.Method == "DELETE" { | |
res.Write([]byte("Goodbye, World!\n")) | |
} | |
}) | |
http.ListenAndServe(":3000", mainMux) | |
} |
This file contains hidden or 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
curl http://localhost:3000/speak | |
curl -X POST http://localhost:3000/speak | |
curl -X DELETE http://localhost:3000/speak |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment