kos/instance.go

78 lines
1.3 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 initialization(cbs ...Option) {
once.Do(func() {
std = New(cbs...)
})
}
func Init(cbs ...Option) Application {
initialization(cbs...)
return std
}
func Name() string {
initialization()
return std.opts.Name
}
func ShortName() string {
initialization()
return std.opts.ShortName()
}
func Version() string {
initialization()
return std.opts.Version
}
func Debug(args ...any) bool {
initialization()
if len(args) <= 0 {
return std.opts.EnableDebug
}
if b, ok := args[0].(bool); ok {
std.opts.EnableDebug = b
}
return std.opts.EnableDebug
}
func Node() *Info {
initialization()
return std.Info()
}
func Http() *http.Server {
initialization()
return std.Http()
}
func Command() *cli.Server {
initialization()
return std.Command()
}
func Handle(method string, cb HandleFunc) {
initialization()
std.Handle(method, cb)
}