From 1c4b8a59954f776eb80e8f57670eb38ade03d412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Z=C3=BCrcher?= Date: Wed, 28 May 2025 22:02:36 +0200 Subject: [PATCH] fix pointer error aguments --- args/args.go | 63 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/args/args.go b/args/args.go index f53178c..0f4e1a2 100644 --- a/args/args.go +++ b/args/args.go @@ -2,6 +2,7 @@ package args import ( "flag" + "strings" "github.com/tecamino/tecamino-dbm/cert" "github.com/tecamino/tecamino-dbm/models" @@ -9,30 +10,64 @@ import ( // DBM cli arguments type Args struct { - Port models.Port - Cert cert.Cert - RootDir string - DBMFile string - Debug bool + Ip string + Port models.Port + Cert cert.Cert + AllowOrigins []string + RootDir string + DBMFile string + Debug bool +} + +type StringSlice []string + +func (s *StringSlice) String() string { + return strings.Join(*s, ",") +} + +func (s *StringSlice) Set(value string) error { + *s = append(*s, value) + return nil } // initialte cli arguments func Init() *Args { + var allowOrigins StringSlice + + flag.Var(&allowOrigins, "allowOrigin", "Allowed origin (can repeat this flag)") + + ip := flag.String("ip", "0.0.0.0", "local ip address") + organization := flag.String("org", "tecamino", "name of organization for certificate") + certFile := flag.String("certFile", "./cert/cert.pem", "path of certfile") + keyFile := flag.String("keyFile", "./cert/key.pem", "path of keyfile") + portHttp := flag.Uint("http-port", 8100, "json server communication for http/ws") + portHttps := flag.Uint("https-port", 8101, "json server communication for http/wss") + rootDir := flag.String("workingDir", "./", "working directory") + dbmFile := flag.String("dbm", "/test/test", "dbm file name") + debug := flag.Bool("debug", false, "debug flag") + flag.Parse() + a := Args{ + Ip: *ip, Cert: cert.Cert{ - Organization: *flag.String("org", "tecamino", "name of organization for certificate"), - CertFile: *flag.String("certFile", "./cert/cert.pem", "path of certfile"), - KeyFile: *flag.String("keyFile", "./cert/key.pem", "path of keyfile"), + Organization: *organization, + CertFile: *certFile, + KeyFile: *keyFile, }, Port: models.Port{ - Http: *flag.Uint("http-port", 8100, "json server communication for http/ws"), - Https: *flag.Uint("https-port", 8101, "json server communication for http/wss"), + Http: *portHttp, + Https: *portHttps, }, - RootDir: *flag.String("workingDir", "./", "working directory"), - DBMFile: *flag.String("dbm", "/test/test", "dbm file name"), - Debug: *flag.Bool("debug", false, "debug flag"), + RootDir: *rootDir, + DBMFile: *dbmFile, + Debug: *debug, } - flag.Parse() + + if len(allowOrigins) == 0 { + allowOrigins = StringSlice{"http://localhost:9500"} + } + + a.AllowOrigins = allowOrigins return &a }