Skip to content

Commit 2afb038

Browse files
cmd: specify config path
1 parent eef3eee commit 2afb038

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

exec/http/main.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,20 @@ var (
2929
func init() {
3030
log.Printf("network-measure HTTP %s, built at %s\n", fullVersion, buildDate)
3131
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 {
3338
if err = toml.Unmarshal(c, &config); err != nil {
3439
log.Printf("Failed loading config: %s, use default settings.\n", err)
3540
config.SetDefault()
3641
} else {
3742
log.Println("Config loaded.")
3843
}
44+
} else if len(os.Args) > 1 {
45+
log.Fatalf("Can't open config for read: %s.\n", err)
3946
} else {
4047
log.Println("No config found. use default settings.")
4148
}
@@ -248,14 +255,14 @@ func limit(enable bool) gin.HandlerFunc {
248255
}
249256
}
250257

251-
//func _(c *gin.Context) {
258+
// func _(c *gin.Context) {
252259
// fmt.Printf("[DBG] %v | %15s | %-7s %#v\n",
253260
// time.Now().Format("2006/01/02 - 15:04:05"),
254261
// c.ClientIP(),
255262
// c.Request.Method,
256263
// c.Request.URL.Path,
257264
// )
258-
//}
265+
// }
259266

260267
func main() {
261268
router := gin.Default()

exec/ws/main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,20 @@ func init() {
215215
log.Printf("network-measure Websocket %s, built at %s\n", fullVersion, buildDate)
216216

217217
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 {
219224
if err = toml.Unmarshal(c, &config); err != nil {
220225
log.Printf("Failed loading config: %s, use default settings.\n", err)
221226
config.SetDefault()
222227
} else {
223228
log.Println("Config loaded.")
224229
}
230+
} else if len(os.Args) > 1 {
231+
log.Fatalf("Can't open config for read: %s.\n", err)
225232
} else {
226233
log.Println("No config found. use default settings.")
227234
}

0 commit comments

Comments
 (0)