-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
32 lines (29 loc) · 859 Bytes
/
app.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
28
29
30
31
32
package main
import (
"github.com/gorilla/mux"
"log"
"net/http"
)
type App struct {
Router *mux.Router
}
func (a *App) Initialize() {
a.Router = mux.NewRouter()
a.initializeRouters()
}
func (a *App) initializeRouters() {
//findUserByIdHandler := a.Router.HandlerFunc(HandleFindUserById)
//a.Router.HandleFunc("/users/findUserById", loggingHandler(findUserByIdHandler))
a.Router.Use(loggingHandler)
a.Router.HandleFunc("/users/findByName", HandleFindUserByName)
a.Router.HandleFunc("/users/updateUser", HandleUpdateUser)
a.Router.HandleFunc("/users/addUser", HandleAddUser)
a.Router.HandleFunc("/users/delUser", HandleDelUser)
}
func loggingHandler(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
next.ServeHTTP(w, r)
log.Printf("[%s] %q", r.Method, r.URL.String())
}
return http.HandlerFunc(fn)
}