-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
85 lines (72 loc) · 1.78 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"fmt"
"os"
"path/filepath"
log "github.com/sirupsen/logrus"
"github.com/IoTPanic/pixelpusher/internal/api"
"github.com/IoTPanic/pixelpusher/internal/db"
)
var helptext = `
___ _ _ _ ____ _ ____ ____ ____ ____ _ _ ____ ____
|__] | \/ |___ | | |__/ |__| [__ |__| |___ |__/
| | _/\_ |___ |___ |___ | \ | | ___] | | |___ | \
========================================================
Help Text
This is the help menu for pixelcrasher, we recommend
you read the README.md file if you have access to the git
repository.
`
// Used to scan docker filesystem to try to find db issues; now fixed, just keeping in here
func scanf() {
var files []string
root := "/go/src/github.com/IoTPanic/pixelpusher/"
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
files = append(files, path)
return nil
})
if err != nil {
panic(err)
}
for _, file := range files {
fmt.Println(file)
}
}
func main() {
log.Println("Launching PixelPusher...")
// Get the standard variables
arguments := os.Args[1:]
if len(arguments) > 0 {
switch arguments[0] {
case "help":
fmt.Println(helptext)
os.Exit(1)
case "dev":
os.Setenv("DBDIR", "./db/")
break
}
}
// Setup the database
dbPath := os.Getenv("DBDIR")
os.MkdirAll(dbPath, 0700) // Create db dir if nonexistant
dbPath = dbPath + "pixelsDB.db"
err := db.Connect(dbPath)
if err != nil {
panic(err)
}
// Start the API
go api.Start("0.0.0.0:8080")
// Setup code to allow for a graceful termination
sigs := make(chan os.Signal, 1)
done := make(chan bool, 1)
log.Println("Waiting for sigterm")
go func() {
sig := <-sigs
fmt.Println()
fmt.Println(sig)
done <- true
}()
<-done
db.Close()
log.Println("Terminating Pixel Pusher instance gracefully")
}