Skip to content

Commit

Permalink
feat: update namespace for code style (polarismesh#730)
Browse files Browse the repository at this point in the history
* feat: update namespace for code style

* feat: update for Server interface check
  • Loading branch information
daheige committed Oct 11, 2022
1 parent e6083c1 commit ed3d7a0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
9 changes: 4 additions & 5 deletions namespace/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions namespace/namespace_authability.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}

Expand Down
2 changes: 2 additions & 0 deletions namespace/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"github.com/polarismesh/polaris/store"
)

var _ NamespaceOperateServer = (*Server)(nil)

type Server struct {
storage store.Store

Expand Down
2 changes: 1 addition & 1 deletion namespace/server_authability.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (

// serverAuthAbility 带有鉴权能力的 discoverServer
//
// 该层会对请求参数做一些调整,根据具体的请求发起人,设置为数据对应的 owner,不可为为别人进行创建资源
// 该层会对请求参数做一些调整,根据具体的请求发起人,设置为数据对应的 owner,不可为为别人进行创建资源
type serverAuthAbility struct {
targetServer *Server
authSvr auth.AuthServer
Expand Down
6 changes: 2 additions & 4 deletions namespace/test_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ed3d7a0

Please sign in to comment.