18
18
package main
19
19
20
20
import (
21
- "fmt"
22
21
_ "net/http/pprof"
23
- "runtime"
24
22
"strconv"
25
23
"time"
26
24
)
@@ -30,45 +28,15 @@ import (
30
28
)
31
29
32
30
import (
33
- "github.com/apache/dubbo-go-pixiu/pixiu/pkg/common/constant"
34
- pxruntime "github.com/apache/dubbo-go-pixiu/pixiu/pkg/common/runtime"
35
- "github.com/apache/dubbo-go-pixiu/pixiu/pkg/config"
36
- "github.com/apache/dubbo-go-pixiu/pixiu/pkg/logger"
37
- "github.com/apache/dubbo-go-pixiu/pixiu/pkg/model"
31
+ "github.com/apache/dubbo-go-pixiu/pixiu/pkg/cmd"
38
32
_ "github.com/apache/dubbo-go-pixiu/pixiu/pkg/pluginregistry"
39
- "github.com/apache/dubbo-go-pixiu/pixiu/pkg/server"
40
33
)
41
34
42
- var (
35
+ const (
43
36
// Version pixiu version
44
- Version = "0.6.0"
45
-
46
- flagToLogLevel = map [string ]string {
47
- "trace" : "TRACE" ,
48
- "debug" : "DEBUG" ,
49
- "info" : "INFO" ,
50
- "warning" : "WARN" ,
51
- "error" : "ERROR" ,
52
- "critical" : "FATAL" ,
53
- }
54
-
55
- configPath string
56
- apiConfigPath string
57
- logConfigPath string
58
- logLevel string
59
-
60
- // CURRENTLY USELESS
61
- logFormat string
62
-
63
- limitCpus string
64
-
65
- // Currently default set to false, wait for up coming support
66
- initFromRemote = false
37
+ Version = "1.0.0"
67
38
)
68
39
69
- // deploy server deployment
70
- var deploy = & DefaultDeployer {}
71
-
72
40
// main pixiu run method
73
41
func main () {
74
42
app := getRootCmd ()
@@ -88,112 +56,8 @@ func getRootCmd() *cobra.Command {
88
56
Version : Version ,
89
57
}
90
58
91
- rootCmd .AddCommand (gatewayCmd )
92
- rootCmd .AddCommand (sideCarCmd )
59
+ rootCmd .AddCommand (cmd . GatewayCmd )
60
+ rootCmd .AddCommand (cmd . SideCarCmd )
93
61
94
62
return rootCmd
95
63
}
96
-
97
- type DefaultDeployer struct {
98
- bootstrap * model.Bootstrap
99
- configManger * config.ConfigManager
100
- }
101
-
102
- func (d * DefaultDeployer ) initialize () error {
103
-
104
- err := initLog ()
105
- if err != nil {
106
- logger .Warnf ("[startGatewayCmd] failed to init logger, %s" , err .Error ())
107
- }
108
-
109
- // load Bootstrap config
110
- d .bootstrap = d .configManger .LoadBootConfig (configPath )
111
- if err != nil {
112
- panic (fmt .Errorf ("[startGatewayCmd] failed to get api meta config, %s" , err .Error ()))
113
- }
114
-
115
- err = initLimitCpus ()
116
- if err != nil {
117
- logger .Errorf ("[startCmd] failed to get limit cpu number, %s" , err .Error ())
118
- }
119
-
120
- return err
121
- }
122
-
123
- func (d * DefaultDeployer ) start () error {
124
- server .Start (d .bootstrap )
125
- return nil
126
- }
127
-
128
- func (d * DefaultDeployer ) stop () error {
129
- //TODO implement me
130
- panic ("implement me" )
131
- }
132
-
133
- // initDefaultValue If not set both in args and env, set default values
134
- func initDefaultValue () {
135
- if configPath == "" {
136
- configPath = constant .DefaultConfigPath
137
- }
138
-
139
- if apiConfigPath == "" {
140
- apiConfigPath = constant .DefaultApiConfigPath
141
- }
142
-
143
- if logConfigPath == "" {
144
- logConfigPath = constant .DefaultLogConfigPath
145
- }
146
-
147
- if logLevel == "" {
148
- logLevel = constant .DefaultLogLevel
149
- }
150
-
151
- if limitCpus == "" {
152
- limitCpus = constant .DefaultLimitCpus
153
- }
154
-
155
- if logFormat == "" {
156
- logFormat = constant .DefaultLogFormat
157
- }
158
- }
159
-
160
- // initLog
161
- func initLog () error {
162
- err := logger .InitLog (logConfigPath )
163
- if err != nil {
164
- // cause `logger.InitLog` already handle init failed, so just use logger to log
165
- return err
166
- }
167
-
168
- if level , ok := flagToLogLevel [logLevel ]; ok {
169
- logger .SetLoggerLevel (level )
170
- } else {
171
- logger .SetLoggerLevel (flagToLogLevel [constant .DefaultLogLevel ])
172
- return fmt .Errorf ("logLevel is invalid, set log level to default: %s" , constant .DefaultLogLevel )
173
- }
174
- return nil
175
- }
176
-
177
- // initApiConfig return value of the bool is for the judgment of whether is a api meta data error, a kind of silly (?)
178
- func initApiConfig () (* model.Bootstrap , error ) {
179
- bootstrap := config .Load (configPath )
180
- return bootstrap , nil
181
- }
182
-
183
- func initLimitCpus () error {
184
- limitCpuNumberFromEnv , err := strconv .ParseInt (limitCpus , 10 , 64 )
185
- if err != nil {
186
- return err
187
- }
188
- limitCpuNumber := int (limitCpuNumberFromEnv )
189
- if limitCpuNumber <= 0 {
190
- limitCpuNumber = pxruntime .GetCPUNum ()
191
- }
192
- runtime .GOMAXPROCS (limitCpuNumber )
193
- logger .Infof ("GOMAXPROCS set to %v" , limitCpuNumber )
194
- return nil
195
- }
196
-
197
- func init () {
198
- deploy .configManger = config .NewConfigManger ()
199
- }
0 commit comments