Use http method in route pattern
This commit is contained in:
2
main.go
2
main.go
@@ -38,7 +38,7 @@ func init() {
|
||||
|
||||
func main() {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", handler.Handler)
|
||||
mux.HandleFunc("POST /", handler.Handler)
|
||||
|
||||
server := &http.Server{
|
||||
Addr: fmt.Sprintf(":%d", port),
|
||||
|
||||
@@ -19,11 +19,6 @@ import (
|
||||
)
|
||||
|
||||
func Handler(w http.ResponseWriter, req *http.Request) {
|
||||
// only accept POST requests
|
||||
if req.Method != http.MethodPost {
|
||||
utils.SendResponse(nil, "only POST is allowed", w)
|
||||
return
|
||||
}
|
||||
|
||||
// read request body
|
||||
requestBody, err := io.ReadAll(req.Body)
|
||||
|
||||
Reference in New Issue
Block a user