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
|
|
|
|
)
|
|
|
|
|
2024-04-29 10:52:19 +08:00
|
|
|
func initialization(cbs ...Option) {
|
2023-04-23 17:57:36 +08:00
|
|
|
once.Do(func() {
|
|
|
|
std = New(cbs...)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-04-29 10:52:19 +08:00
|
|
|
func Init(cbs ...Option) Application {
|
|
|
|
initialization(cbs...)
|
2023-04-23 17:57:36 +08:00
|
|
|
return std
|
|
|
|
}
|
|
|
|
|
2023-10-23 15:44:44 +08:00
|
|
|
func Name() string {
|
2024-04-29 10:52:19 +08:00
|
|
|
initialization()
|
2023-10-23 15:44:44 +08:00
|
|
|
return std.opts.Name
|
|
|
|
}
|
|
|
|
|
2024-04-29 10:52:19 +08:00
|
|
|
func ShortName() string {
|
|
|
|
initialization()
|
|
|
|
return std.opts.ShortName()
|
|
|
|
}
|
|
|
|
|
2023-10-23 15:44:44 +08:00
|
|
|
func Version() string {
|
2024-04-29 10:52:19 +08:00
|
|
|
initialization()
|
2023-10-23 15:44:44 +08:00
|
|
|
return std.opts.Version
|
|
|
|
}
|
|
|
|
|
2024-04-29 10:52:19 +08:00
|
|
|
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
|
|
|
|
}
|
2023-10-23 15:43:46 +08:00
|
|
|
return std.opts.EnableDebug
|
|
|
|
}
|
|
|
|
|
2024-04-29 10:52:19 +08:00
|
|
|
func Node() *Info {
|
|
|
|
initialization()
|
|
|
|
return std.Info()
|
2023-04-23 17:57:36 +08:00
|
|
|
}
|
|
|
|
|
2024-04-29 10:52:19 +08:00
|
|
|
func Http() *http.Server {
|
|
|
|
initialization()
|
|
|
|
return std.Http()
|
|
|
|
}
|
|
|
|
|
|
|
|
func Command() *cli.Server {
|
|
|
|
initialization()
|
|
|
|
return std.Command()
|
2023-10-23 15:47:37 +08:00
|
|
|
}
|
|
|
|
|
2023-04-23 17:57:36 +08:00
|
|
|
func Handle(method string, cb HandleFunc) {
|
2024-04-29 10:52:19 +08:00
|
|
|
initialization()
|
2023-04-23 17:57:36 +08:00
|
|
|
std.Handle(method, cb)
|
|
|
|
}
|