-
Notifications
You must be signed in to change notification settings - Fork 1
/
passwordless.go
49 lines (38 loc) · 1016 Bytes
/
passwordless.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
package main
import (
"flag"
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
passwordless "github.com/iamjem/go-passwordless-demo/lib"
"github.com/stretchr/graceful"
"net/http"
"os"
"path"
"time"
)
var port = flag.String("port", "8080", "listen address")
func main() {
flag.Parse()
listen := fmt.Sprintf(":%s", *port)
router := mux.NewRouter()
// static files
root, _ := os.Getwd()
router.PathPrefix("/static").Handler(http.StripPrefix("/static", http.FileServer(http.Dir(path.Join(root, "public")))))
// web routes
router.PathPrefix("/").Handler(passwordless.BuildRoutes())
// setup server
var handler http.Handler
// if Debug is true, enable logging
if os.Getenv("DEBUG") == "true" {
log.SetLevel(log.DebugLevel)
handler = handlers.CombinedLoggingHandler(os.Stdout, router)
} else {
handler = router
}
log.WithFields(log.Fields{
"listen": listen,
}).Info("Server running")
graceful.Run(listen, 10*time.Second, handler)
}