diff --git a/instance.go b/instance.go index f0c3b86..8e4762d 100644 --- a/instance.go +++ b/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) } diff --git a/pkg/cache/instance_test.go b/pkg/cache/instance_test.go deleted file mode 100644 index dbabda0..0000000 --- a/pkg/cache/instance_test.go +++ /dev/null @@ -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") - } -}