Skip to content

Commit 3eccbd1

Browse files
committed
chore(veinmind-common): update conf service func field
1 parent c72d266 commit 3eccbd1

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

plugins/go/veinmind-sensitive/go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ module github.com/chaitin/veinmind-tools/plugins/go/veinmind-sensitive
22

33
go 1.18
44

5-
replace github.com/chaitin/veinmind-tools/veinmind-common/go v1.0.0 => ../../../veinmind-common/go
65

76
require (
87
github.com/BurntSushi/toml v0.3.1
98
github.com/chaitin/libveinmind v1.1.0
10-
github.com/chaitin/veinmind-tools/veinmind-common/go v1.0.0
9+
github.com/chaitin/veinmind-tools/veinmind-common/go v0.0.0-20220613062319-ac5c6e55bfe4
1110
github.com/stretchr/testify v1.7.0
1211
)
1312

veinmind-common/go/service/conf/default_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,23 @@ import (
55
"testing"
66
)
77

8-
func TestDefaultClient(t *testing.T) {
8+
func TestDefaultClient(t *testing.T) {
99
c := DefaultConfClient()
10-
_, err := c.Pull(Sensitive)
10+
_, err := c.Pull(Sensitive)
1111
assert.Error(t, err)
1212
}
1313

14+
func TestNewConfService(t *testing.T) {
15+
s, err := NewConfService()
16+
if err != nil {
17+
t.Error(err)
18+
}
1419

20+
s.Store(Sensitive, []byte{0x01})
21+
b, err := s.Pull(Sensitive)
22+
if err != nil {
23+
t.Error(err)
24+
}
25+
26+
assert.Equal(t, b, []byte{0x01})
27+
}

veinmind-common/go/service/conf/service.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,35 @@ import (
1010
const Namespace = "github.com/chaitin/veinmind-tools/veinmind-common/go/service/conf"
1111

1212
type ConfService struct {
13-
store map[string][]byte
13+
store map[PluginConfNS][]byte
1414
}
1515

1616
type confClient struct {
17-
ctx context.Context
18-
group *errgroup.Group
19-
Pull func(ns PluginConfNS) ([]byte, error)
17+
ctx context.Context
18+
group *errgroup.Group
19+
Pull func(ns PluginConfNS) ([]byte, error)
2020
}
2121

22-
func (c *ConfService) Pull(pluginName string) ([]byte, error){
23-
if b, ok := c.store[pluginName]; ok {
22+
func NewConfService() (*ConfService, error) {
23+
c := new(ConfService)
24+
c.store = make(map[PluginConfNS][]byte)
25+
return c, nil
26+
}
27+
28+
func (c *ConfService) Pull(ns PluginConfNS) ([]byte, error) {
29+
if b, ok := c.store[ns]; ok {
2430
return b, nil
25-
}else{
31+
} else {
2632
return nil, errors.New("conf: plugin conf doesn't exist")
2733
}
2834
}
2935

30-
func (c *ConfService) Store(pluginName string, b []byte) error {
31-
c.store[pluginName] = b
36+
func (c *ConfService) Store(ns PluginConfNS, b []byte) error {
37+
c.store[ns] = b
3238
return nil
3339
}
3440

35-
func (c *ConfService) Add(registry *service.Registry) {
36-
registry.Define(Namespace, struct {}{})
41+
func (c *ConfService) Add(registry *service.Registry) {
42+
registry.Define(Namespace, struct{}{})
3743
registry.AddService(Namespace, "pull", c.Pull)
3844
}

0 commit comments

Comments
 (0)