kos/instance.go

72 lines
1.2 KiB
Go
Raw Normal View History

2023-04-23 17:57:36 +08:00
package kos
import (
"git.nspix.com/golang/kos/entry/cli"
"git.nspix.com/golang/kos/entry/http"
2023-07-07 09:53:37 +08:00
_ "git.nspix.com/golang/kos/pkg/request"
2023-08-23 14:13:45 +08:00
_ "git.nspix.com/golang/kos/util/arrays"
2023-07-07 09:53:37 +08:00
_ "git.nspix.com/golang/kos/util/bs"
2023-06-30 14:16:16 +08:00
_ "git.nspix.com/golang/kos/util/fetch"
2023-08-07 14:57:16 +08:00
_ "git.nspix.com/golang/kos/util/humanize"
2023-06-30 14:16:16 +08:00
_ "git.nspix.com/golang/kos/util/random"
_ "git.nspix.com/golang/kos/util/reflection"
2023-08-23 14:13:45 +08:00
_ "git.nspix.com/golang/kos/util/sys"
2023-04-23 17:57:36 +08:00
"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()
}
2023-10-23 15:44:44 +08:00
func Name() string {
initApplication()
return std.opts.Name
}
func Version() string {
initApplication()
return std.opts.Version
}
2023-10-23 15:43:46 +08:00
func Debug() bool {
initApplication()
return std.opts.EnableDebug
}
2023-04-23 17:57:36 +08:00
func Command() *cli.Server {
initApplication()
return std.Command()
}
2023-10-23 15:47:37 +08:00
func ShortName() string {
initApplication()
return std.opts.ShortName()
}
2023-04-23 17:57:36 +08:00
func Handle(method string, cb HandleFunc) {
initApplication()
std.Handle(method, cb)
}