-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (49 loc) · 1.27 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
package main
import (
"regexp"
"github.com/akerl/github-auth-lambda/session"
"github.com/akerl/go-lambda/mux"
"golang.org/x/oauth2"
"golang.org/x/oauth2/github"
)
var (
config *configFile
sm *session.Manager
oauthCfg *oauth2.Config
scopes = []string{"read:org"}
authRegex = regexp.MustCompile(`^/auth$`)
logoutRegex = regexp.MustCompile(`^/logout$`)
callbackRegex = regexp.MustCompile(`^/callback$`)
indexRegex = regexp.MustCompile(`^/$`)
faviconRegex = regexp.MustCompile(`^/favicon.ico$`)
defaultRegex = regexp.MustCompile(`^/.*$`)
)
func main() {
var err error
config, err = loadConfig()
if err != nil {
panic(err)
}
sm = &session.Manager{
Name: "session",
SignKey: config.SignKey,
EncKey: config.EncKey,
Lifetime: config.Lifetime,
Domain: config.Domain,
}
oauthCfg = &oauth2.Config{
ClientID: config.ClientID,
ClientSecret: config.ClientSecret,
Endpoint: github.Endpoint,
Scopes: scopes,
}
d := mux.NewDispatcher(
mux.NewRoute(authRegex, authHandler),
mux.NewRoute(logoutRegex, logoutHandler),
mux.NewRoute(callbackRegex, callbackHandler),
mux.NewRoute(indexRegex, indexHandler),
mux.NewRoute(faviconRegex, faviconHandler),
mux.NewRoute(defaultRegex, defaultHandler),
)
mux.Start(d)
}