kos/instance.go

72 lines
1.2 KiB
Go

package kos
import (
"git.nspix.com/golang/kos/entry/cli"
"git.nspix.com/golang/kos/entry/http"
_ "git.nspix.com/golang/kos/pkg/request"
_ "git.nspix.com/golang/kos/util/arrays"
_ "git.nspix.com/golang/kos/util/bs"
_ "git.nspix.com/golang/kos/util/fetch"
_ "git.nspix.com/golang/kos/util/humanize"
_ "git.nspix.com/golang/kos/util/random"
_ "git.nspix.com/golang/kos/util/reflection"
_ "git.nspix.com/golang/kos/util/sys"
"sync"
)
var (
once sync.Once
std *application
)
func initApplication(cbs ...Option) {
once.Do(func() {
std = New(cbs...)
})
}
func Init(cbs ...Option) *application {
initApplication(cbs...)
return std
}
func Node() *Info {
initApplication()
return std.Info()
}
func Http() *http.Server {
initApplication()
return std.Http()
}
func Name() string {
initApplication()
return std.opts.Name
}
func Version() string {
initApplication()
return std.opts.Version
}
func Debug() bool {
initApplication()
return std.opts.EnableDebug
}
func Command() *cli.Server {
initApplication()
return std.Command()
}
func ShortName() string {
initApplication()
return std.opts.ShortName()
}
func Handle(method string, cb HandleFunc) {
initApplication()
std.Handle(method, cb)
}