-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
61 lines (51 loc) · 1.35 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
package main
import (
"context"
"errors"
"fmt"
"os"
"os/signal"
"syscall"
hiddenlake "github.com/number571/hidden-lake"
"github.com/number571/hidden-lake/internal/composite/pkg/app"
"github.com/number571/hidden-lake/internal/utils/flag"
)
func main() {
args := os.Args[1:]
if flag.GetBoolFlagValue(args, []string{"v", "version"}) {
fmt.Println(hiddenlake.GVersion)
return
}
if flag.GetBoolFlagValue(args, []string{"h", "help"}) {
fmt.Print(
"Hidden Lake Composite (HLC)\n" +
"Description: runs many HL services as one application\n" +
"Arguments:\n" +
"[ -h, --help ] - print information about service\n" +
"[ -v, --version ] - print version of service\n" +
"[ -p, --path ] - set path to config, database files\n" +
"[ -n, --network ] - set network key for connections\n" +
"[ -t, --threads ] - set num of parallel functions to calculate PoW\n",
)
return
}
app, err := app.InitApp(args)
if err != nil {
panic(err)
}
shutdown := make(chan os.Signal, 1)
signal.Notify(shutdown, syscall.SIGINT, syscall.SIGTERM)
ctx, cancel := context.WithCancel(context.Background())
closed := make(chan struct{})
defer func() {
cancel()
<-closed
}()
go func() {
defer func() { closed <- struct{}{} }()
if err := app.Run(ctx); err != nil && !errors.Is(err, context.Canceled) {
panic(err)
}
}()
<-shutdown
}