/
main.go
107 lines (83 loc) · 3.02 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/instance-id/GoVerifier-dgo/appconfig"
. "github.com/instance-id/GoVerifier-dgo/rpcserver"
"github.com/sarulabs/di/v2"
"go.uber.org/zap"
"github.com/instance-id/GoVerifier-dgo/services"
"github.com/instance-id/GoVerifier-dgo/verifier"
)
type appContext struct {
Verifier *verifier.Verifier
}
var log *zap.SugaredLogger
func init() {
}
func main() {
var appContext appContext
var port *string
useRPC := flag.Bool("rpc", false, "Run RPC server for UI communication?")
port = flag.String("port", "14555", "Port for RPC commands")
flag.Parse()
if !*useRPC {
outPath := "./logs/verifier.log"
outPathLast := "./logs/verifierlastrun.log"
if err := os.Rename(outPath, outPathLast); err != nil {
log.Infof("Could not rotate log file")
}
}
log, app := DISetup()
defer app.Delete()
message := []string{
"██╗ ██╗███████╗██████╗ ██╗███████╗██╗███████╗██████╗",
"██║ ██║██╔════╝██╔══██╗██║██╔════╝██║██╔════╝██╔══██╗",
"██║ ██║█████╗ ██████╔╝██║█████╗ ██║█████╗ ██████╔╝",
"╚██╗ ██╔╝██╔══╝ ██╔══██╗██║██╔══╝ ██║██╔══╝ ██╔══██╗",
" ╚████╔╝ ███████╗██║ ██║██║██║ ██║███████╗██║ ██║",
" ╚═══╝ ╚══════╝╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ v0.1"}
for s := range message {
msg := fmt.Sprintf("%s", message[s])
log.Infof("%s", msg)
}
config := app.Get("configData").(*appconfig.MainSettings)
verifierRun, err := appContext.Verifier.VerifierRun(config, app)
ErrCheck("error creating Bot session: ", err)
if *useRPC {
log.Infof("Configuration import complete. Starting Verifier RPC server.")
var rpcServer = RpcServer{
Data: &ServerData{
Port: port,
Log: log,
Verifier: verifierRun,
Phrase: config.Discord.Guild,
Key: config.System.Token[len(config.System.Token)-13:],
},
}
RunServer(&rpcServer, log)
} else {
log.Infof("Configuration import complete. Starting Verifier in standalone mode.")
defer verifierRun.Close()
err = verifierRun.Start()
ErrCheck("Couldn't start verifierRun: ", err)
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
}
}
func DISetup() (*zap.SugaredLogger, di.Container) {
builder, _ := di.NewBuilder()
_ = builder.Add(services.Services...)
app := builder.Build()
log := app.Get("logData").(*zap.SugaredLogger)
return log, app
}
func ErrCheck(msg string, err error) {
if err != nil {
log.Fatalf("%s %s\n", msg, err)
}
}