-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
59 lines (50 loc) · 1.04 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 (
"flag"
"fmt"
"log"
"os"
"os/signal"
"github.com/boltdb/bolt"
)
var (
DB *bolt.DB
portPtr *string
dbPathPtr *string
DBPath string
)
func catchSignals() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func(){
<- c
fmt.Println("\n* Interrupt received, stopping...")
fmt.Print("[..] Closing DB\r")
CloseDB()
fmt.Println("[OK] Closing DB")
fmt.Println()
os.Exit(0)
}()
}
func main() {
portPtr = flag.String("port", "3000", "The port to listen on.")
dbPathPtr = flag.String("dbpath", "./gerph.db", "The path to the file to save the keystore in.")
flag.Parse()
DBPath = *dbPathPtr
fmt.Print("[..] Setting up DB in \"" + *dbPathPtr + "\"\r")
db, err := SetupDB(*dbPathPtr)
DB = db
if err != nil {
log.Fatal(err)
}
defer CloseDB()
fmt.Println("[OK] Setting up DB in \"" + *dbPathPtr + "\"")
catchSignals()
fmt.Print("[..] Listening on port " + *portPtr + "\r")
go func() {
Listen(*portPtr)
}()
fmt.Println("[OK] Listening on port " + *portPtr)
fmt.Println("\n* Ready!")
select{}
}