|
@@ -6,16 +6,17 @@ import (
|
|
|
"git.nspix.com/golang/kos/util/ip"
|
|
|
"git.nspix.com/golang/kos/util/sys"
|
|
|
"os"
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
|
"syscall"
|
|
|
)
|
|
|
|
|
|
type (
|
|
|
Options struct {
|
|
|
- Name string
|
|
|
- Version string
|
|
|
- Address string
|
|
|
- Port int
|
|
|
+ Name string //名称
|
|
|
+ Version string //版本号
|
|
|
+ Address string //绑定地址
|
|
|
+ Port int //端口
|
|
|
EnableDebug bool //开启调试模式
|
|
|
DisableHttp bool //禁用HTTP入口
|
|
|
EnableDirectHttp bool //启用HTTP直连模式
|
|
@@ -83,7 +84,7 @@ func WithDirectCommand() Option {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func NewOptions() *Options {
|
|
|
+func NewOptions(cbs ...Option) *Options {
|
|
|
opts := &Options{
|
|
|
Name: env.Get(EnvAppName, sys.Hostname()),
|
|
|
Version: env.Get(EnvAppVersion, "0.0.1"),
|
|
@@ -93,5 +94,9 @@ func NewOptions() *Options {
|
|
|
}
|
|
|
opts.Port = int(env.Integer(18080, EnvAppPort, "HTTP_PORT", "KOS_PORT"))
|
|
|
opts.Address = env.Getter(ip.Internal(), EnvAppAddress, "KOS_ADDRESS")
|
|
|
+ opts.EnableDebug, _ = strconv.ParseBool(env.Getter("false", EnvAppDebug, "KOS_DEBUG"))
|
|
|
+ for _, cb := range cbs {
|
|
|
+ cb(opts)
|
|
|
+ }
|
|
|
return opts
|
|
|
}
|