package cfg import ( "fmt" "github.com/alecthomas/kong" ) type AppSettings struct { ServerAddress string `name:"listen-address" env:"GEOIP_LISTEN_ADDRESS" help:"Address to use for the metrics server" default:"${default_address}"` DataFile string `name:"data-file" env:"GEOIP_DATA_FILE" help:"path to data file" default:"${default_file_path}"` DataURL string `name:"data-url" env:"GEOIP_DATA_URL" help:"url to data file"` } func NewAppSettings() *AppSettings { return &AppSettings{} } func (s *AppSettings) Parse() error { ctx := kong.Parse( s, kong.Vars{ "default_address": ":8080", "default_file_path": "./data.csv", }, kong.Name("country_geo_locations"), kong.Description("🚀 Start a simple web server for GeoIP data"), kong.UsageOnError(), ) err := validateFlags(*s) if err != nil { ctx.PrintUsage(false) fmt.Println() return err } return nil } func validateFlags(settings AppSettings) error { if settings.DataURL == "" { return fmt.Errorf("error: invalid data url, must not be blank") } return nil }