-
Notifications
You must be signed in to change notification settings - Fork 6
/
api.go
27 lines (23 loc) · 746 Bytes
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package main
import (
"fmt"
"net/http"
)
// NewHTTPHandler creates a http.Handler for handling HTTP requests.
// The default implementation creates a http.ServerMux. You may replace it with your favorite third-party
// HTTP routing object, such as ozzo-routing, echo, gin.
func NewHTTPHandler() http.Handler {
// set up the routing using the standard ServerMux or third-party HTTP router
mux := http.NewServeMux()
mux.HandleFunc("/foo", foo)
mux.HandleFunc("/bar", bar)
return mux
}
// foo handles the "/foo" request.
func foo(w http.ResponseWriter, req *http.Request) {
fmt.Fprintln(w, "Hello")
}
// bar handles the "/bar" request.
func bar(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "%v %v", req.Method, req.URL)
}