This commit is contained in:
fancl 2024-04-29 14:58:03 +08:00
parent 57c134b6ba
commit bef2e35e41
2 changed files with 22 additions and 40 deletions

View File

@ -16,62 +16,68 @@ import (
var (
once sync.Once
std *application
app Application
)
func initialization(cbs ...Option) {
once.Do(func() {
std = New(cbs...)
app = New(cbs...)
})
}
func Init(cbs ...Option) Application {
initialization(cbs...)
return std
return app
}
func Name() string {
initialization()
return std.opts.Name
return app.Info().Name
}
func ShortName() string {
initialization()
return std.opts.ShortName()
if entry, ok := app.(*application); ok {
return entry.opts.ShortName()
}
return app.Info().Name
}
func Version() string {
initialization()
return std.opts.Version
return app.Info().Version
}
func Debug(args ...any) bool {
initialization()
if len(args) <= 0 {
return std.opts.EnableDebug
if entry, ok := app.(*application); ok {
if len(args) <= 0 {
return entry.opts.EnableDebug
}
if b, ok := args[0].(bool); ok {
entry.opts.EnableDebug = b
}
return entry.opts.EnableDebug
}
if b, ok := args[0].(bool); ok {
std.opts.EnableDebug = b
}
return std.opts.EnableDebug
return false
}
func Node() *Info {
initialization()
return std.Info()
return app.Info()
}
func Http() *http.Server {
initialization()
return std.Http()
return app.Http()
}
func Command() *cli.Server {
initialization()
return std.Command()
return app.Command()
}
func Handle(method string, cb HandleFunc) {
initialization()
std.Handle(method, cb)
app.Handle(method, cb)
}

View File

@ -1,24 +0,0 @@
package cache
import (
"context"
"testing"
)
func TestStore(t *testing.T) {
ctx := context.Background()
var (
n int
name string
)
Store(ctx, "age", 1)
Load(ctx, "age", &n)
if n != 1 {
t.Errorf("not equal")
}
Store(ctx, "name", "zhansan")
Load(ctx, "name", &name)
if name != "zhansan" {
t.Errorf("not equal")
}
}