capture/config.go

47 lines
1.7 KiB
Go
Raw Normal View History

2017-11-08 00:10:54 +01:00
package main
2018-09-16 16:18:39 +02:00
import (
"flag"
"fmt"
)
2017-11-08 00:10:54 +01:00
2018-12-01 23:59:33 +01:00
// Config has all the configuration parsed from the command line
2018-09-16 16:21:36 +02:00
type Config struct {
2018-09-16 16:18:39 +02:00
TargetURL string `json:"targetURL"`
ProxyPort string `json:"proxyPort"`
MaxCaptures int `json:"maxCaptures"`
Dashboard string `json:"dashboard"`
DashboardPath string `json:"dashboardPath"`
2018-11-22 22:52:02 +01:00
DashboardConnPath string `json:"dashboardConnPath"`
2018-09-16 16:18:39 +02:00
DashboardClearPath string `json:"dashboardClearPath"`
2018-11-25 22:24:59 +01:00
DashboardRetryPath string `json:"dashboardRetryPath"`
2018-09-16 16:18:39 +02:00
DashboardItemInfoPath string `json:"dashboardItemInfoPath"`
2018-07-21 19:50:53 +02:00
}
2018-12-01 23:59:33 +01:00
// ReadConfig reads the arguments from the command line
2018-09-16 16:21:36 +02:00
func ReadConfig() Config {
2018-08-04 01:53:54 +02:00
targetURL := flag.String("url", "https://jsonplaceholder.typicode.com", "Required. Set the base url you want to capture")
proxyPort := flag.String("port", "9000", "Set the proxy port")
2017-11-08 00:10:54 +01:00
dashboard := flag.String("dashboard", "dashboard", "Set the dashboard name")
2017-11-18 12:05:41 +01:00
maxCaptures := flag.Int("max-captures", 16, "Set the max number of captures to show in the dashboard")
2017-11-08 00:10:54 +01:00
flag.Parse()
2018-09-16 16:18:39 +02:00
dashboardPath := fmt.Sprintf("/%s/", *dashboard)
2018-11-25 18:10:10 +01:00
dashboardConnPath := fmt.Sprintf("/%s/conn/", *dashboard)
2018-09-16 16:18:39 +02:00
dashboardClearPath := fmt.Sprintf("/%s/clear/", *dashboard)
2018-11-25 22:24:59 +01:00
dashboardRetryPath := fmt.Sprintf("/%s/retry/", *dashboard)
2018-09-16 16:18:39 +02:00
dashboardItemInfoPath := fmt.Sprintf("/%s/items/", *dashboard)
2018-09-16 16:21:36 +02:00
return Config{
2018-09-16 16:18:39 +02:00
TargetURL: *targetURL,
ProxyPort: *proxyPort,
MaxCaptures: *maxCaptures,
Dashboard: *dashboard,
DashboardPath: dashboardPath,
2018-11-22 22:52:02 +01:00
DashboardConnPath: dashboardConnPath,
2018-09-16 16:18:39 +02:00
DashboardClearPath: dashboardClearPath,
2018-11-25 22:24:59 +01:00
DashboardRetryPath: dashboardRetryPath,
2018-09-16 16:18:39 +02:00
DashboardItemInfoPath: dashboardItemInfoPath,
}
2017-11-08 00:10:54 +01:00
}