-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
54 lines (44 loc) · 1.07 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
package main
import (
logger "log"
"net/http"
"github.com/kelseyhightower/envconfig"
)
type configuration struct {
PrivateKey string `envconfig:"PRIVATE_KEY" default:"id_rsa"`
LoaderScript string `envconfig:"LOADER_SCRIPT" default:"loader.sh"`
PublicURL string `envconfig:"PUBLIC_URL" required:"true"`
AuthModule string `envconfig:"AUTH_MODULE" default:"yubikey"`
Port string `envconfig:"PORT" default:"8000"`
}
func main() {
server, err := initialize()
if err != nil {
logger.Fatal(err)
}
http.ListenAndServe(":"+server.config.Port, server.router)
}
func initialize() (server, error) {
var c configuration
err := envconfig.Process("KG", &c)
if err != nil {
envconfig.Usage("KG", &c)
logger.Fatal(err)
}
var auth authenticator
switch c.AuthModule {
case "yubikey":
auth, err = NewYubiAuthenticator()
if err != nil {
logger.Fatal(err)
}
default:
logger.Fatal("no such authenticator: " + c.AuthModule)
}
server := newServer(c, auth)
server.routes()
return server, nil
}
func log(message interface{}) {
logger.Println(message)
}