-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
48 lines (41 loc) · 992 Bytes
/
main.go
File metadata and controls
48 lines (41 loc) · 992 Bytes
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
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"runtime"
"time"
)
func Info() string {
goVersion := runtime.Version()
tstamp := time.Now()
return fmt.Sprintf("git={{VERSION}} go=%s date=%s", goVersion, tstamp)
}
func main() {
var version bool
flag.BoolVar(&version, "version", false, "Show version")
var config string
cfile := fmt.Sprintf("%s/.beampass.json", os.Getenv("HOME"))
flag.StringVar(&config, "config", cfile, "server config file")
flag.Parse()
if version {
fmt.Println("server version:", Info())
return
}
conf, err := parseConfig(config)
if err != nil {
log.Fatal(err)
}
// initialize connection to beampass user db with dbURI, e.g.
initDB(conf.DBUri)
defer db.Close()
// Register handlers
http.HandleFunc("/btr", BtrHandler)
http.HandleFunc("/affiliations", AffHandler)
// Start the web server
port := fmt.Sprintf(":%d", conf.Port)
fmt.Printf("Server listening on port %s\n", port)
log.Fatal(http.ListenAndServe(port, nil))
}