-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
35 lines (30 loc) · 966 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
package main
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
"github.com/luoruofeng/go-jwt-demo/basic"
)
func main() {
mainRouter := mux.NewRouter()
authRouter := mainRouter.PathPrefix("/auth").Subrouter()
authRouter.HandleFunc("/signup", basic.SignupHandler)
// The Signin will send the JWT back as we are making microservices.
// The JWT token will make sure that other services are protected.
// So, ultimately, we would need a middleware
authRouter.HandleFunc("/signin", basic.SigninHandler)
// Add the middleware to different subrouter
otherRouter := mainRouter.PathPrefix("/other").Subrouter()
otherRouter.HandleFunc("/home", basic.HomeHandler)
otherRouter.Use(basic.TokenValidationMiddleware)
// HTTP server
// Add time outs
server := &http.Server{
Addr: "0.0.0.0:8888",
Handler: mainRouter,
}
err := server.ListenAndServe()
if err != nil {
fmt.Println("Error Booting the Server")
}
}