File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -29,13 +29,20 @@ var (
29
29
func init () {
30
30
log .Printf ("network-measure HTTP %s, built at %s\n " , fullVersion , buildDate )
31
31
config .SetDefault ()
32
- if c , err := os .ReadFile ("./config.toml" ); err == nil {
32
+
33
+ var configFile = "./config.toml"
34
+ if len (os .Args ) > 1 {
35
+ configFile = os .Args [1 ]
36
+ }
37
+ if c , err := os .ReadFile (configFile ); err == nil {
33
38
if err = toml .Unmarshal (c , & config ); err != nil {
34
39
log .Printf ("Failed loading config: %s, use default settings.\n " , err )
35
40
config .SetDefault ()
36
41
} else {
37
42
log .Println ("Config loaded." )
38
43
}
44
+ } else if len (os .Args ) > 1 {
45
+ log .Fatalf ("Can't open config for read: %s.\n " , err )
39
46
} else {
40
47
log .Println ("No config found. use default settings." )
41
48
}
@@ -248,14 +255,14 @@ func limit(enable bool) gin.HandlerFunc {
248
255
}
249
256
}
250
257
251
- //func _(c *gin.Context) {
258
+ // func _(c *gin.Context) {
252
259
// fmt.Printf("[DBG] %v | %15s | %-7s %#v\n",
253
260
// time.Now().Format("2006/01/02 - 15:04:05"),
254
261
// c.ClientIP(),
255
262
// c.Request.Method,
256
263
// c.Request.URL.Path,
257
264
// )
258
- //}
265
+ // }
259
266
260
267
func main () {
261
268
router := gin .Default ()
Original file line number Diff line number Diff line change @@ -215,13 +215,20 @@ func init() {
215
215
log .Printf ("network-measure Websocket %s, built at %s\n " , fullVersion , buildDate )
216
216
217
217
config .SetDefault ()
218
- if c , err := os .ReadFile ("./config.toml" ); err == nil {
218
+
219
+ var configFile = "./config.toml"
220
+ if len (os .Args ) > 1 {
221
+ configFile = os .Args [1 ]
222
+ }
223
+ if c , err := os .ReadFile (configFile ); err == nil {
219
224
if err = toml .Unmarshal (c , & config ); err != nil {
220
225
log .Printf ("Failed loading config: %s, use default settings.\n " , err )
221
226
config .SetDefault ()
222
227
} else {
223
228
log .Println ("Config loaded." )
224
229
}
230
+ } else if len (os .Args ) > 1 {
231
+ log .Fatalf ("Can't open config for read: %s.\n " , err )
225
232
} else {
226
233
log .Println ("No config found. use default settings." )
227
234
}
You can’t perform that action at this time.
0 commit comments