fix pointer error aguments
This commit is contained in:
63
args/args.go
63
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
|
||||
}
|
||||
|
Reference in New Issue
Block a user