forked from cookieY/Yearning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
104 lines (95 loc) · 2.61 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
// Copyright 2019 HenryYee.
//
// Licensed under the AGPL, Version 3.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.gnu.org/licenses/agpl-3.0.en.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"Yearning-go/src/lib"
"Yearning-go/src/model"
"Yearning-go/src/service"
"flag"
"fmt"
"google.golang.org/grpc"
"log"
"os"
)
var (
h bool
s bool
p string
m bool
b string
x bool
c string
k bool
f bool
)
func usage() {
_, err := fmt.Fprintf(os.Stderr, `version: Yearning/2.3.1 Interstellar author: HenryYee
Usage: Yearning [-m migrate] [-p port] [-s start] [-b web-bind] [-h help] [-c config file]
Options:
-s 启动Yearning
-m 数据初始化(第一次安装时执行)
-p 端口
-b 钉钉/邮件推送时显示的平台地址
-x 表结构修复,升级时可以操作。如出现错误可直接忽略。
-h 帮助
-c 配置文件路径
-k 用户权限变更为权限组(2.1.7以下升级至2.1.7及以上使用)
-f 初始化Admin用户密码
`)
if err != nil {
panic(err.Error())
}
}
func init() {
flag.BoolVar(&s, "s", false, "启动Yearning")
flag.BoolVar(&m, "m", false, "数据初始化(第一次安装时执行)")
flag.StringVar(&p, "p", "8000", "Yearning端口")
flag.BoolVar(&h, "h", false, "帮助")
flag.BoolVar(&f, "f", false, "初始化Admin用户密码")
flag.BoolVar(&x, "x", false, "表结构修复")
flag.StringVar(&b, "b", "127.0.0.1", "钉钉/邮件推送时显示的平台地址")
flag.StringVar(&c, "c", "conf.toml", "配置文件路径")
flag.BoolVar(&k, "k", false, "用户权限变更为权限组(2.1.7以下升级至2.1.7及以上使用)")
flag.Usage = usage
log.SetPrefix("Yearning_error: ")
log.SetFlags(log.Ldate | log.Lmicroseconds | log.Llongfile)
}
func main() {
flag.Parse()
if h {
flag.Usage()
} else {
model.DbInit(c)
if k {
service.MargeRuleGroup()
}
if s {
model.Conn, _ = grpc.Dial(model.Grpc, grpc.WithInsecure())
defer func() {
model.Conn.Close()
}()
service.UpdateData()
service.StartYearning(p, b)
}
if x {
service.DelCol()
}
if f {
model.DB().Model(model.CoreAccount{}).Where("username =?", "admin").Update(&model.CoreAccount{Password: lib.DjangoEncrypt("Yearning_admin", string(lib.GetRandom()))})
fmt.Println("admin密码已重新设置为:Yearning_admin")
}
}
if m {
service.Migrate()
}
}