-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (43 loc) · 1.29 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"github.com/gorilla/mux"
"github.com/joho/godotenv"
"fmt"
"os"
"net/http"
"io"
"github.com/devigner/authorisation/auth"
"github.com/devigner/authorisation/user"
"github.com/devigner/authorisation/di"
)
func handler(w http.ResponseWriter, r *http.Request) {
di.Container().Logger.Info("Uncaugh:", r.RequestURI)
io.WriteString(w,fmt.Sprintf("You reach page %s",r.RequestURI))
}
func NotFound(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(404)
io.WriteString(w,fmt.Sprintf("404 %s",r.RequestURI))
}
func main() {
err := godotenv.Load()
if err != nil {
fmt.Errorf("Error env",err.Error())
}
dc := di.Setup()
port := os.Getenv("APP_PORT")
r := dc.Router.StrictSlash(false)
r.HandleFunc("/", handler)
auth.Router()
user.Router()
r.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
t, err := route.GetPathTemplate()
if err != nil {
return err
}
dc.Logger.Info(fmt.Sprintf("Route: %s ; %s", t, route.GetName()))
return nil
})
r.NotFoundHandler = http.HandlerFunc(NotFound)
dc.Logger.Info("App running on port:", port)
dc.Logger.Fatal(http.ListenAndServe(fmt.Sprintf(":%s",port),r))
}