-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (53 loc) · 1.59 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
package main
import (
"github.com/jessevdk/go-flags"
"github.com/v4lproik/simple-blockchain-quickstart/common/services"
Logger "github.com/v4lproik/simple-blockchain-quickstart/log"
)
var env EnvVal
// @title Simple Blockchain Quickstart
// @version 1.0
// @description About
// This is an experimental repository which aims at shipping a decent skeleton for anyone who wants to get into the blockchain world via the Golang programming language
// @contact.name API Support
// @contact.email [email protected]
// @host localhost:8080
func main() {
// parse cli arguments
parser := flags.NewParser(&opts, flags.IgnoreUnknown)
// parse command line arguments which set up the application
_, err := parser.Parse()
if err != nil {
Logger.Panicf("main: failed to parse cli args: %s", err)
}
// check environment
err = checkArgs()
if err != nil {
Logger.Panicf("main: failed to verify cli args: %s", err)
}
// init Logger
Logger.InitLogger(env.isProd(), opts.LogFilePath)
defer Logger.Sync()
// display program configuration
displayAppConfiguration()
// run as a node
if opts.RunAsHttpserver {
// add specific json validators used by endpoints
validatorService := new(services.ValidatorService)
validatorService.AddValidators()
// run the http server
runHttpServer()
} else {
// run as client
// add commands and subcommands. eg. ./bin transaction list
err = addCommands(parser)
if err != nil {
panic(err)
}
// parse command line for the requested actions (eg. transaction list, transaction add, etc...)
_, err = parser.Parse()
if err != nil {
panic(err)
}
}
}