-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (48 loc) · 1.22 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
package main
import (
"fmt"
"flag"
"os"
"git.fuwafuwa.moe/x3/ngfshare/config"
"git.fuwafuwa.moe/x3/ngfshare/net"
"git.fuwafuwa.moe/x3/ngfshare/db"
"git.fuwafuwa.moe/x3/ngfshare/view"
);
func main() {
confFilePath := flag.String("config", "", "The path for the config.json file")
createAuthKey := flag.Bool("genauth", false, "Generate a new auth key and exit")
flag.Parse()
if *confFilePath == "" {
fmt.Println("Failure: --config argument is required")
os.Exit(1)
}
conf, err := config.LoadConfig(*confFilePath);
if err != nil {
fmt.Printf("Failed to load: %+v", err)
os.Exit(1)
}
err = view.LoadTemplates()
if err != nil {
return
}
dbctx, err := db.Open(conf.DBpath)
if err != nil {
return
}
defer dbctx.Close()
if *createAuthKey {
key, err := dbctx.CreateNewAuthKey()
if err != nil {
fmt.Println("Failed to create auth key:", err)
os.Exit(1)
}
fmt.Println(key)
return
}
err = net.Start(conf)
if err != nil {
fmt.Printf("Failed to start listen: ", err)
return
}
fmt.Println("Returning from main...")
}