forked from heybeachboy/trx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
80 lines (68 loc) · 1.49 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
package main
import (
"context"
"fmt"
"os"
"time"
"tron/daemon"
"tron/trx"
)
const (
// name of the service
name = "tronrpc"
description = "tron contract rpcservice"
)
var sigChan = make(chan os.Signal, 1) //用于系统信息接收处理的通道
var ctx, cancel = context.WithCancel(context.Background())
var exit = make(chan struct{}, 1)
func main() {
showVersion()
daemon.Charge(name, description)
preFun()
defer sufFun()
// 阻塞
go daemon.HandleSystemSignal(sigChan, stop)
<-exit
}
// go build -ldflags "-X \"main.BuildDate=%BUILD_DATE%\""
var (
BuildVersion string
BuildDate string
)
// Version .
const Version = "tronrpc version --v1.0.0"
func timePrint() string {
return time.Now().Local().Format("2006-01-02T15:04:05.000Z07:00")
}
func preFun() {
trx.Init()
trx.InitAllContarctServer(ctx, exit)
fmt.Printf("tronrpc start, time=%s\n", timePrint())
}
func sufFun() {
fmt.Printf("tronrpc exit, time=%s\n", timePrint())
}
//显示版本信息
func showVersion() {
if len(os.Args) < 2 {
return
}
if os.Args[1] == "-v" || os.Args[1] == "-V" || os.Args[1] == "--version" || os.Args[1] == "version" {
pintVersion()
os.Exit(0)
}
return
}
func pintVersion() {
fmt.Println(Version)
if BuildDate != "" {
fmt.Println("tronrpc BuildDate --" + BuildDate)
}
if BuildVersion != "" {
fmt.Println("tronrpc BuildVersion --" + BuildVersion)
}
}
func stop() {
cancel()
close(sigChan)
}