-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.go
40 lines (33 loc) · 937 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
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"log"
"net/http"
"github.com/W-ptra/2FA-Feature/controller"
"github.com/W-ptra/2FA-Feature/middleware"
)
type Server struct{
addr string
}
func NewServer(addr string) *Server{
return &Server{
addr: addr,
}
}
func (s *Server) run() error{
router := http.NewServeMux()
fs := http.FileServer(http.Dir("./public"))
router.Handle("/public/",fs)
router.HandleFunc("/",controller.RedirectToLogin)
router.HandleFunc("GET /login",controller.GetLogin)
router.HandleFunc("POST /login",controller.PostLogin)
router.HandleFunc("GET /register",controller.GetRegister)
router.HandleFunc("POST /register",controller.PostRegister)
router.HandleFunc("POST /otp",controller.PostOtp)
server := http.Server{
Addr: s.addr,
Handler: middleware.Logger(router),
}
log.Printf("Listening to %v\n",s.addr)
log.Printf("Open http://localhost:8001/login to proceed further\n")
return server.ListenAndServe()
}