This is an automated email from the ASF dual-hosted git repository.
bzp2010 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 e432392 feat: add Type function to store interface (#2160)
e432392 is described below
commit e432392932dcaf362ab6866ee9dc184b25cf527b
Author: bzp2010 <[email protected]>
AuthorDate: Sun Oct 10 21:56:25 2021 -0500
feat: add Type function to store interface (#2160)
* feat: add Type function to store interface
* chore: remove unused code
---
api/internal/core/store/store.go | 6 ++++++
api/internal/core/store/store_mock.go | 5 +++++
api/internal/core/store/storehub.go | 1 +
3 files changed, 12 insertions(+)
diff --git a/api/internal/core/store/store.go b/api/internal/core/store/store.go
index a7eba74..176c261 100644
--- a/api/internal/core/store/store.go
+++ b/api/internal/core/store/store.go
@@ -42,6 +42,7 @@ type Pagination struct {
}
type Interface interface {
+ Type() HubKey
Get(ctx context.Context, key string) (interface{}, error)
List(ctx context.Context, input ListInput) (*ListOutput, error)
Create(ctx context.Context, obj interface{}) (interface{}, error)
@@ -64,6 +65,7 @@ type GenericStoreOption struct {
KeyFunc func(obj interface{}) string
StockCheck func(obj interface{}, stockObj interface{}) error
Validator Validator
+ HubKey HubKey
}
func NewGenericStore(opt GenericStoreOption) (*GenericStore, error) {
@@ -142,6 +144,10 @@ func (s *GenericStore) Init() error {
return nil
}
+func (s *GenericStore) Type() HubKey {
+ return s.opt.HubKey
+}
+
func (s *GenericStore) Get(_ context.Context, key string) (interface{}, error)
{
ret, ok := s.cache.Load(key)
if !ok {
diff --git a/api/internal/core/store/store_mock.go
b/api/internal/core/store/store_mock.go
index c6801d6..10fc5b3 100644
--- a/api/internal/core/store/store_mock.go
+++ b/api/internal/core/store/store_mock.go
@@ -25,6 +25,11 @@ import (
type MockInterface struct {
mock.Mock
+ HubKey HubKey
+}
+
+func (m *MockInterface) Type() HubKey {
+ return m.HubKey
}
func (m *MockInterface) Get(_ context.Context, key string) (interface{},
error) {
diff --git a/api/internal/core/store/storehub.go
b/api/internal/core/store/storehub.go
index db14196..4ab9962 100644
--- a/api/internal/core/store/storehub.go
+++ b/api/internal/core/store/storehub.go
@@ -60,6 +60,7 @@ func InitStore(key HubKey, opt GenericStoreOption) error {
}
opt.Validator = validator
}
+ opt.HubKey = key
s, err := NewGenericStore(opt)
if err != nil {
log.Errorf("NewGenericStore error: %s", err)