-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinit.go
117 lines (97 loc) · 2.41 KB
/
init.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
105
106
107
108
109
110
111
112
113
114
115
116
117
/*********************************************
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' | |
\ .-\__ `-` ___/-. /
___`. .' /--.--\ `. . __
."" '< `.___\_<|>_/___.' >'"".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `-. \_ __\ /__ _/ .-` / /
======`-.____`-.___\_____/___.-`____.-'======
`=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
佛祖保佑 永无BUG
心外无法 法外无心
三宝弟子 飞猪宏愿
*********************************************/
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"runtime"
_ "github.com/SAP/go-hdb/driver"
_ "github.com/denisenkom/go-mssqldb"
_ "github.com/go-sql-driver/mysql"
_ "github.com/kshvakov/clickhouse"
_ "github.com/lib/pq"
"github.com/go-redis/redis"
"github.com/dgrijalva/jwt-go"
)
func init() {
supportDatabases = []string{
"postgres(PostgresQL)",
"mysql(MySQL)",
"mssql(SQLServer)",
"hdb(SAP HANA)",
"clickhouse(Yandex ClickHouse)",
}
preLoadSQLite3()
preLoadOci8()
usage := flag.Usage
flag.Usage = func() {
fmt.Println(serverBrand)
usage()
}
flag.Parse()
runtime.GOMAXPROCS(*flagWorkers)
//https://github.com/go-redis/redis
if *flagRedisURL != "" {
_, err := redis.ParseURL(*flagRedisURL)
if err != nil {
fmt.Println(fmt.Sprintf("redis url(%s) error:%v", *flagRedisURL, err))
os.Exit(0)
}
}
if *flagRSAPrivkey != "" {
if *flagJWTSecret == "" {
fmt.Println("jwt secret is empty!")
os.Exit(0)
}
rsaKeyData, err := ioutil.ReadFile(*flagRSAPrivkey)
if err != nil {
fmt.Println("load rsa private key error:", err.Error())
os.Exit(0)
}
_, err = jwt.ParseRSAPrivateKeyFromPEM(rsaKeyData)
if err != nil {
fmt.Println("jwt rsa private key error:", err.Error())
os.Exit(0)
}
if *flagJWTExpires < int(10) {
*flagJWTExpires = 1800
}
}
if *flagAPIFile == "" {
flag.Usage()
os.Exit(0)
}
{
InitEndpointRegistry()
manager, err := NewManager(*flagAPIFile)
if err != nil {
fmt.Printf("Run SQLRestful macro error: %v!", err)
os.Exit(0)
}
macrosManager = manager
}
}