From ed3d7a03cce0c6a6d5fc6f5cd79f8b2ce1e8394c Mon Sep 17 00:00:00 2001 From: heige Date: Tue, 11 Oct 2022 11:15:06 +0800 Subject: [PATCH] feat: update namespace for code style (#730) * feat: update namespace for code style * feat: update for Server interface check --- namespace/default.go | 9 ++++----- namespace/namespace_authability.go | 6 ++++-- namespace/server.go | 2 ++ namespace/server_authability.go | 2 +- namespace/test_export.go | 6 ++---- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/namespace/default.go b/namespace/default.go index f6cecd526..5a0a4633b 100644 --- a/namespace/default.go +++ b/namespace/default.go @@ -32,9 +32,9 @@ import ( var ( server NamespaceOperateServer - namespaceServer *Server = new(Server) - once = sync.Once{} - finishInit = false + namespaceServer = &Server{} + once sync.Once + finishInit bool ) type Config struct { @@ -56,8 +56,7 @@ func Initialize(ctx context.Context, nsOpt *Config, storage store.Store, cacheMg return nil } -func initialize(ctx context.Context, nsOpt *Config, storage store.Store, cacheMgn *cache.CacheManager) error { - +func initialize(_ context.Context, nsOpt *Config, storage store.Store, cacheMgn *cache.CacheManager) error { namespaceServer.caches = cacheMgn namespaceServer.storage = storage namespaceServer.cfg = *nsOpt diff --git a/namespace/namespace_authability.go b/namespace/namespace_authability.go index 2a2554040..a3e9ec177 100644 --- a/namespace/namespace_authability.go +++ b/namespace/namespace_authability.go @@ -25,6 +25,9 @@ import ( "github.com/polarismesh/polaris/common/utils" ) +var _ NamespaceOperateServer = (*serverAuthAbility)(nil) + +// CreateNamespaceIfAbsent Create a single name space func (svr *serverAuthAbility) CreateNamespaceIfAbsent(ctx context.Context, req *api.Namespace) error { return svr.targetServer.CreateNamespaceIfAbsent(ctx, req) } @@ -42,8 +45,7 @@ func (svr *serverAuthAbility) CreateNamespace(ctx context.Context, req *api.Name ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) // 填充 ownerId 信息数据 - ownerId := utils.ParseOwnerID(ctx) - if len(ownerId) > 0 { + if ownerId := utils.ParseOwnerID(ctx); len(ownerId) > 0 { req.Owners = utils.NewStringValue(ownerId) } diff --git a/namespace/server.go b/namespace/server.go index f037ca2e3..bae408eb0 100644 --- a/namespace/server.go +++ b/namespace/server.go @@ -29,6 +29,8 @@ import ( "github.com/polarismesh/polaris/store" ) +var _ NamespaceOperateServer = (*Server)(nil) + type Server struct { storage store.Store diff --git a/namespace/server_authability.go b/namespace/server_authability.go index 90bece17b..8b43e8dbe 100644 --- a/namespace/server_authability.go +++ b/namespace/server_authability.go @@ -32,7 +32,7 @@ import ( // serverAuthAbility 带有鉴权能力的 discoverServer // -// 该层会对请求参数做一些调整,根据具体的请求发起人,设置为数据对应的 owner,不可为为别人进行创建资源 +// 该层会对请求参数做一些调整,根据具体的请求发起人,设置为数据对应的 owner,不可为为别人进行创建资源 type serverAuthAbility struct { targetServer *Server authSvr auth.AuthServer diff --git a/namespace/test_export.go b/namespace/test_export.go index 689c57c23..c66b2384c 100644 --- a/namespace/test_export.go +++ b/namespace/test_export.go @@ -28,11 +28,9 @@ import ( "github.com/polarismesh/polaris/store" ) -func TestInitialize(ctx context.Context, nsOpt *Config, storage store.Store, cacheMgn *cache.CacheManager, +func TestInitialize(_ context.Context, nsOpt *Config, storage store.Store, cacheMgn *cache.CacheManager, authSvr auth.AuthServer) (NamespaceOperateServer, error) { - - namespaceServer := new(Server) - + namespaceServer := &Server{} namespaceServer.caches = cacheMgn namespaceServer.storage = storage namespaceServer.cfg = *nsOpt