-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (47 loc) · 1.12 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
package main
import (
"context"
"log"
"net/http"
"net/url"
"os"
"github.com/vaultvision/go-auth-example/pkg/config"
"github.com/vaultvision/go-auth-example/pkg/handler"
)
func main() {
if err := Run(context.Background(), os.Args...); err != nil {
log.Fatal(err)
}
os.Exit(0)
}
func Run(ctx context.Context, args ...string) error {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
cfg, err := config.New()
if err != nil {
return err
}
log.Printf("config BASE_URL=%q", cfg.BaseURL)
log.Printf("config STATIC_DIR=%q", cfg.StaticDir)
log.Printf("config SESSION_SECRET.is_set=%v", cfg.SessionSecret != "")
log.Printf("config VV_ISSUER_URL=%q", cfg.VVIssuerURL)
log.Printf("config VV_CLIENT_ID=%q", cfg.VVClientID)
log.Printf("config VV_CLIENT_SECRET.is_set=%v", cfg.VVClientSecret != "")
hr, err := handler.New(ctx, cfg)
if err != nil {
return err
}
baseURL, err := url.Parse(cfg.BaseURL)
if err != nil {
return err
}
httpSrv := &http.Server{
Addr: baseURL.Host,
Handler: hr,
}
if err != nil {
return err
}
log.Printf("HTTP Server running at %v", baseURL)
return httpSrv.ListenAndServe()
}