generated from mchmarny/gorunstarter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
executable file
·60 lines (48 loc) · 1.14 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
package main
import (
"context"
"fmt"
"log"
"net"
"net/http"
"os"
ev "github.com/mchmarny/gcputil/env"
pj "github.com/mchmarny/gcputil/project"
)
const (
appName = "logo-identifier"
)
var (
logger = log.New(os.Stdout, "", 0)
projectID = pj.GetIDOrFail()
port = ev.MustGetEnvVar("PORT", "8080")
)
func main() {
ctx := context.Background()
initAuth(ctx)
initStore(ctx)
defer closeStore(ctx)
initHandlers()
mux := http.NewServeMux()
// Static
mux.Handle("/static/", http.StripPrefix("/static/",
http.FileServer(http.Dir("static"))))
// Handlers
mux.HandleFunc("/", defaultHandler)
mux.HandleFunc("/auth/login", authLoginHandler)
mux.HandleFunc("/auth/callback", authCallbackHandler)
mux.HandleFunc("/auth/logout", logOutHandler)
mux.HandleFunc("/view", viewHandler)
mux.HandleFunc("/logo", logoHandler)
mux.HandleFunc("/_health", func(w http.ResponseWriter, _ *http.Request) {
fmt.Fprint(w, "ok")
})
// Server
hostPort := net.JoinHostPort("0.0.0.0", port)
server := &http.Server{
Addr: hostPort,
Handler: mux,
}
logger.Printf("Server starting: %s \n", hostPort)
logger.Fatal(server.ListenAndServe())
}