fix bugs
This commit is contained in:
parent
57c134b6ba
commit
bef2e35e41
38
instance.go
38
instance.go
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue