fix pointer error aguments
This commit is contained in:
63
args/args.go
63
args/args.go
@@ -2,6 +2,7 @@ package args
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/tecamino/tecamino-dbm/cert"
|
"github.com/tecamino/tecamino-dbm/cert"
|
||||||
"github.com/tecamino/tecamino-dbm/models"
|
"github.com/tecamino/tecamino-dbm/models"
|
||||||
@@ -9,30 +10,64 @@ import (
|
|||||||
|
|
||||||
// DBM cli arguments
|
// DBM cli arguments
|
||||||
type Args struct {
|
type Args struct {
|
||||||
Port models.Port
|
Ip string
|
||||||
Cert cert.Cert
|
Port models.Port
|
||||||
RootDir string
|
Cert cert.Cert
|
||||||
DBMFile string
|
AllowOrigins []string
|
||||||
Debug bool
|
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
|
// initialte cli arguments
|
||||||
func Init() *Args {
|
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{
|
a := Args{
|
||||||
|
Ip: *ip,
|
||||||
Cert: cert.Cert{
|
Cert: cert.Cert{
|
||||||
Organization: *flag.String("org", "tecamino", "name of organization for certificate"),
|
Organization: *organization,
|
||||||
CertFile: *flag.String("certFile", "./cert/cert.pem", "path of certfile"),
|
CertFile: *certFile,
|
||||||
KeyFile: *flag.String("keyFile", "./cert/key.pem", "path of keyfile"),
|
KeyFile: *keyFile,
|
||||||
},
|
},
|
||||||
Port: models.Port{
|
Port: models.Port{
|
||||||
Http: *flag.Uint("http-port", 8100, "json server communication for http/ws"),
|
Http: *portHttp,
|
||||||
Https: *flag.Uint("https-port", 8101, "json server communication for http/wss"),
|
Https: *portHttps,
|
||||||
},
|
},
|
||||||
RootDir: *flag.String("workingDir", "./", "working directory"),
|
RootDir: *rootDir,
|
||||||
DBMFile: *flag.String("dbm", "/test/test", "dbm file name"),
|
DBMFile: *dbmFile,
|
||||||
Debug: *flag.Bool("debug", false, "debug flag"),
|
Debug: *debug,
|
||||||
}
|
}
|
||||||
flag.Parse()
|
|
||||||
|
if len(allowOrigins) == 0 {
|
||||||
|
allowOrigins = StringSlice{"http://localhost:9500"}
|
||||||
|
}
|
||||||
|
|
||||||
|
a.AllowOrigins = allowOrigins
|
||||||
return &a
|
return &a
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user