-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
61 lines (46 loc) · 1.15 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
55
56
57
58
59
60
61
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"time"
"github.com/gorilla/mux"
cont "github.com/ashmintech/azurewithgo/controller"
)
const hostAddress = ":8080"
func main() {
r := mux.NewRouter()
r.HandleFunc("/logout", cont.Logout)
r.HandleFunc("/login", cont.Login)
cu := r.Methods(http.MethodGet).Subrouter()
cu.HandleFunc("/customer", cont.Customer)
cu.Use(cont.Middleware)
// Static Files
r.PathPrefix("/home").Handler(http.FileServer(http.Dir(".")))
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/home", http.StatusMovedPermanently)
})
srv := &http.Server{
Handler: r,
Addr: hostAddress,
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
IdleTimeout: 60 * time.Second,
}
go func() {
log.Println(("Starting Server on port 8080"))
if err := srv.ListenAndServe(); err != nil {
log.Println(err)
}
}()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
srv.Shutdown(ctx)
log.Println("Server shutting down")
os.Exit(0)
}