This is an automated email from the ASF dual-hosted git repository.

juzhiyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 49224ef  refactor: entity interface format (#2156)
49224ef is described below

commit 49224ef758a4b5d8b98a66beeec37324357bee1c
Author: bzp2010 <[email protected]>
AuthorDate: Fri Oct 8 04:11:53 2021 -0500

    refactor: entity interface format (#2156)
---
 api/internal/core/entity/entity.go    |  8 --------
 api/internal/core/entity/interface.go | 21 +++++++++++++++++++++
 api/internal/core/store/store.go      | 14 +++++++-------
 3 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/api/internal/core/entity/entity.go 
b/api/internal/core/entity/entity.go
index 5564ec5..4328bec 100644
--- a/api/internal/core/entity/entity.go
+++ b/api/internal/core/entity/entity.go
@@ -58,14 +58,6 @@ func (info *BaseInfo) KeyCompat(key string) {
        }
 }
 
-type BaseInfoSetter interface {
-       GetBaseInfo() *BaseInfo
-}
-
-type BaseInfoGetter interface {
-       GetBaseInfo() *BaseInfo
-}
-
 type Status uint8
 
 // swagger:model Route
diff --git a/api/internal/core/entity/interface.go 
b/api/internal/core/entity/interface.go
new file mode 100644
index 0000000..d38978b
--- /dev/null
+++ b/api/internal/core/entity/interface.go
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package entity
+
+type GetBaseInfo interface {
+       GetBaseInfo() *BaseInfo
+}
diff --git a/api/internal/core/store/store.go b/api/internal/core/store/store.go
index c4675cf..a7eba74 100644
--- a/api/internal/core/store/store.go
+++ b/api/internal/core/store/store.go
@@ -171,8 +171,8 @@ func NewListOutput() *ListOutput {
 }
 
 var defLessFunc = func(i, j interface{}) bool {
-       iBase := i.(entity.BaseInfoGetter).GetBaseInfo()
-       jBase := j.(entity.BaseInfoGetter).GetBaseInfo()
+       iBase := i.(entity.GetBaseInfo).GetBaseInfo()
+       jBase := j.(entity.GetBaseInfo).GetBaseInfo()
        if iBase.CreateTime != jBase.CreateTime {
                return iBase.CreateTime < jBase.CreateTime
        }
@@ -259,7 +259,7 @@ func (s *GenericStore) ingestValidate(obj interface{}) (err 
error) {
 
 func (s *GenericStore) CreateCheck(obj interface{}) ([]byte, error) {
 
-       if setter, ok := obj.(entity.BaseInfoSetter); ok {
+       if setter, ok := obj.(entity.GetBaseInfo); ok {
                info := setter.GetBaseInfo()
                info.Creating()
        }
@@ -288,7 +288,7 @@ func (s *GenericStore) CreateCheck(obj interface{}) 
([]byte, error) {
 }
 
 func (s *GenericStore) Create(ctx context.Context, obj interface{}) 
(interface{}, error) {
-       if setter, ok := obj.(entity.BaseInfoSetter); ok {
+       if setter, ok := obj.(entity.GetBaseInfo); ok {
                info := setter.GetBaseInfo()
                info.Creating()
        }
@@ -323,8 +323,8 @@ func (s *GenericStore) Update(ctx context.Context, obj 
interface{}, createIfNotE
                return nil, fmt.Errorf("key: %s is not found", key)
        }
 
-       if setter, ok := obj.(entity.BaseInfoGetter); ok {
-               storedGetter := storedObj.(entity.BaseInfoGetter)
+       if setter, ok := obj.(entity.GetBaseInfo); ok {
+               storedGetter := storedObj.(entity.GetBaseInfo)
                storedInfo := storedGetter.GetBaseInfo()
                info := setter.GetBaseInfo()
                info.Updating(storedInfo)
@@ -365,7 +365,7 @@ func (s *GenericStore) StringToObjPtr(str, key string) 
(interface{}, error) {
                return nil, fmt.Errorf("json unmarshal failed\n\tRelated 
Key:\t\t%s\n\tError Description:\t%s", key, err)
        }
 
-       if setter, ok := ret.(entity.BaseInfoSetter); ok {
+       if setter, ok := ret.(entity.GetBaseInfo); ok {
                info := setter.GetBaseInfo()
                info.KeyCompat(key)
        }

Reply via email to