forked from hootrhino/rulex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
101 lines (93 loc) · 2.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
package main
import (
"context"
"fmt"
"log"
_ "net/http/pprof"
"os"
"runtime"
"time"
"github.com/urfave/cli/v2"
"github.com/hootrhino/rulex/engine"
"github.com/hootrhino/rulex/glogger"
"github.com/hootrhino/rulex/typex"
"github.com/hootrhino/rulex/utils"
)
func init() {
go func() {
for {
select {
case <-context.Background().Done():
return
default:
time.Sleep(30 * time.Second)
runtime.GC()
}
}
}()
dist, err := utils.GetOSDistribution()
if err != nil {
panic(err)
}
typex.DefaultVersion.Dist = dist
arch := fmt.Sprintf("%s-%s-%s", runtime.GOOS, typex.DefaultVersion.Dist, runtime.GOARCH)
typex.DefaultVersion.Arch = arch
}
/*
*
* !!!注意:这个 main 函数仅仅是用来做启动测试用,并非真正的应用,具体的应用需要开发者自己去开发。
* 详情需要关注:http://rulex.pages.dev
*
*/
//
//go:generate ./gen_info.sh
func main() {
//--------------------------------------
app := &cli.App{
Name: "RULEX FrameWork",
Usage: "Goto Document: http://rulex.pages.dev",
Commands: []*cli.Command{
{
Name: "run",
Usage: "Start rulex",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "db",
Usage: "Database of rulex",
Value: "rulex.db",
},
&cli.StringFlag{
Name: "config",
Usage: "Config of rulex",
Value: "rulex.ini",
},
},
Action: func(c *cli.Context) error {
fmt.Println(typex.Banner)
engine.RunRulex(c.String("config"))
glogger.GLogger.Info("Run rulex successfully.")
return nil
},
},
// version
{
Name: "version",
Usage: "Rulex version",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "version",
Usage: "Rulex version",
},
},
Action: func(*cli.Context) error {
version := fmt.Sprintf("[%v-%v-%v]", runtime.GOOS, runtime.GOARCH, typex.DefaultVersion.Version)
fmt.Println("|> Current Version is: " + version)
return nil
},
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}