This repository has been archived by the owner on May 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (57 loc) · 1.81 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
61
62
63
64
65
66
67
68
package main
import (
"fmt"
log "github.com/Sirupsen/logrus"
flags "github.com/jessevdk/go-flags"
_ "github.com/mattn/go-sqlite3"
"math/rand"
"net/http"
"os"
"path"
"time"
)
const coreOSAppID = "{e96281a6-d1af-4bde-9a0a-97b76e56dc57}"
var db *userDB
var fileBE fileBackend
var opts struct {
ListenAddr string `short:"l" long:"listenaddr" default:"0.0.0.0" description:"address to listen on"`
Port int `short:"P" long:"port" default:"8080" description:"port to listen on"`
DisableTimestamps bool `short:"t" long:"disabletimestamps" description:"disable timestamps in logs (useful when using journald)"`
Debug bool `short:"d" long:"debug" description:"run in debug mode"`
}
func main() {
var err error
flags.Parse(&opts)
log.SetFormatter(&log.TextFormatter{DisableTimestamp: opts.DisableTimestamps})
if opts.Debug {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
log.Info("COmaha update server starting")
// seed the RNG
rand.Seed(time.Now().UnixNano())
// open db
db, err = newUserDB("users.sqlite")
if err != nil {
log.Errorf("Could not open database: %v", err.Error())
os.Exit(1)
}
defer db.Close()
cwd, err := os.Getwd()
if err != nil {
log.Errorf("Could not cwd: %v", err.Error())
}
lfbe := newLocalFileBackend(path.Join(cwd, "storage"))
fileBE = &lfbe
http.HandleFunc("/file", fileHandler)
http.HandleFunc("/update", updateHandler)
http.HandleFunc("/shutdown", shutdownHandler)
//http.HandleFunc("/admin/add_group", addGroupHandler)
http.HandleFunc("/admin/add_payload", addPayloadHandler)
http.HandleFunc("/panel", panelHandler)
//http.HandleFunc("/admin/add_user", addUserHandler)
http.HandleFunc("/", homeHandler)
listenString := fmt.Sprintf("%v:%v", opts.ListenAddr, opts.Port)
http.ListenAndServe(listenString, nil)
}