-
Notifications
You must be signed in to change notification settings - Fork 341
/
config.go
41 lines (34 loc) · 992 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package shared
import (
"github.com/giongto35/cloud-game/v2/pkg/environment"
flag "github.com/spf13/pflag"
)
type Environment environment.Env
type Server struct {
Address string
Https bool
Tls struct {
Address string
Domain string
HttpsKey string
HttpsCert string
}
}
func (s *Server) WithFlags() {
flag.StringVar(&s.Address, "address", s.Address, "HTTP server address (host:port)")
flag.StringVar(&s.Tls.Address, "httpsAddress", s.Tls.Address, "HTTPS server address (host:port)")
flag.StringVar(&s.Tls.HttpsKey, "httpsKey", s.Tls.HttpsKey, "HTTPS key")
flag.StringVar(&s.Tls.HttpsCert, "httpsCert", s.Tls.HttpsCert, "HTTPS chain")
}
func (s *Server) GetAddr() string {
if s.Https {
return s.Tls.Address
}
return s.Address
}
func (env *Environment) Get() environment.Env {
return (environment.Env)(*env)
}
func (env *Environment) WithFlags() {
flag.StringVar((*string)(env), "env", string(*env), "Specify environment type: [dev, staging, prod]")
}