-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (33 loc) · 1001 Bytes
/
main.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
33
34
35
36
37
38
39
40
package main
import (
"gitsee/api"
"log"
"net/http"
"net/http/httputil"
"os"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
func main() {
r := mux.NewRouter()
r.Use(loggingMiddleware)
r.HandleFunc("/user/{username}", api.GetUserInfo)
r.HandleFunc("/user/{username}/stats/{stat}", api.RepoStats)
r.HandleFunc("/user/{username}/colorSet", api.GetColorCodes)
if os.Getenv("PORT") == "" {
log.Fatal(http.ListenAndServe(":8000", handlers.CORS()(handlers.CompressHandler(r))))
} else {
log.Fatal(http.ListenAndServe(":"+os.Getenv("PORT"), handlers.CORS()(handlers.CompressHandler(r))))
}
}
func loggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
requestDump, err := httputil.DumpRequest(r, true)
if err != nil {
log.Fatal(err)
}
log.Println(string(requestDump))
// Call the next handler, which can be another middleware in the chain, or the final handler.
next.ServeHTTP(w, r)
})
}