添加地址端口
This commit is contained in:
parent
b91e28a512
commit
809c45c301
|
@ -5,6 +5,7 @@ const (
|
|||
EnvAppVersion = "VOX_VERSION"
|
||||
EnvAppPort = "VOX_PORT"
|
||||
EnvAppAddress = "VOX_ADDRESS"
|
||||
EnvAppDebug = "VOX_DEBUG"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -40,6 +40,11 @@ func Http() *http.Server {
|
|||
return std.Http()
|
||||
}
|
||||
|
||||
func Debug() bool {
|
||||
initApplication()
|
||||
return std.opts.EnableDebug
|
||||
}
|
||||
|
||||
func Command() *cli.Server {
|
||||
initApplication()
|
||||
return std.Command()
|
||||
|
|
15
options.go
15
options.go
|
@ -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
|
||||
}
|
||||
|
|
|
@ -345,10 +345,7 @@ func (app *application) Run() (err error) {
|
|||
}
|
||||
|
||||
func New(cbs ...Option) *application {
|
||||
opts := NewOptions()
|
||||
for _, cb := range cbs {
|
||||
cb(opts)
|
||||
}
|
||||
opts := NewOptions(cbs...)
|
||||
app := &application{
|
||||
opts: opts,
|
||||
uptime: time.Now(),
|
||||
|
|
Loading…
Reference in New Issue