Skip to content

Commit 412d17a

Browse files
committed
cli/context/store: New(): return concrete type
Go conventions are for interfaces to be defined on the receiver side, and for producers to return concrete types. This patch changes the constructor to return a concrete type. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent f80e316 commit 412d17a

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

cli/context/store/store.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ type ContextTLSData struct {
9494

9595
// New creates a store from a given directory.
9696
// If the directory does not exist or is empty, initialize it
97-
func New(dir string, cfg Config) Store {
97+
func New(dir string, cfg Config) *ContextStore {
9898
metaRoot := filepath.Join(dir, metadataDir)
9999
tlsRoot := filepath.Join(dir, tlsDir)
100100

101-
return &store{
101+
return &ContextStore{
102102
meta: &metadataStore{
103103
root: metaRoot,
104104
config: cfg,
@@ -109,12 +109,12 @@ func New(dir string, cfg Config) Store {
109109
}
110110
}
111111

112-
type store struct {
112+
type ContextStore struct {
113113
meta *metadataStore
114114
tls *tlsStore
115115
}
116116

117-
func (s *store) List() ([]Metadata, error) {
117+
func (s *ContextStore) List() ([]Metadata, error) {
118118
return s.meta.list()
119119
}
120120

@@ -131,22 +131,22 @@ func Names(s Lister) ([]string, error) {
131131
return names, nil
132132
}
133133

134-
func (s *store) CreateOrUpdate(meta Metadata) error {
134+
func (s *ContextStore) CreateOrUpdate(meta Metadata) error {
135135
return s.meta.createOrUpdate(meta)
136136
}
137137

138-
func (s *store) Remove(name string) error {
138+
func (s *ContextStore) Remove(name string) error {
139139
if err := s.meta.remove(name); err != nil {
140140
return err
141141
}
142142
return s.tls.removeAllContextData(name)
143143
}
144144

145-
func (s *store) GetMetadata(name string) (Metadata, error) {
145+
func (s *ContextStore) GetMetadata(name string) (Metadata, error) {
146146
return s.meta.get(name)
147147
}
148148

149-
func (s *store) ResetTLSMaterial(name string, data *ContextTLSData) error {
149+
func (s *ContextStore) ResetTLSMaterial(name string, data *ContextTLSData) error {
150150
if err := s.tls.removeAllContextData(name); err != nil {
151151
return err
152152
}
@@ -163,7 +163,7 @@ func (s *store) ResetTLSMaterial(name string, data *ContextTLSData) error {
163163
return nil
164164
}
165165

166-
func (s *store) ResetEndpointTLSMaterial(contextName string, endpointName string, data *EndpointTLSData) error {
166+
func (s *ContextStore) ResetEndpointTLSMaterial(contextName string, endpointName string, data *EndpointTLSData) error {
167167
if err := s.tls.removeAllEndpointData(contextName, endpointName); err != nil {
168168
return err
169169
}
@@ -178,23 +178,23 @@ func (s *store) ResetEndpointTLSMaterial(contextName string, endpointName string
178178
return nil
179179
}
180180

181-
func (s *store) ListTLSFiles(name string) (map[string]EndpointFiles, error) {
181+
func (s *ContextStore) ListTLSFiles(name string) (map[string]EndpointFiles, error) {
182182
res, err := s.tls.listContextData(name)
183183
if err != nil {
184184
return res, errors.Wrapf(err, "failed to list TLS files for context %s", name)
185185
}
186186
return res, nil
187187
}
188188

189-
func (s *store) GetTLSData(contextName, endpointName, fileName string) ([]byte, error) {
189+
func (s *ContextStore) GetTLSData(contextName, endpointName, fileName string) ([]byte, error) {
190190
res, err := s.tls.getData(contextName, endpointName, fileName)
191191
if err != nil {
192192
return res, errors.Wrapf(err, "failed to read TLS data for context %s", contextName)
193193
}
194194
return res, nil
195195
}
196196

197-
func (s *store) GetStorageInfo(contextName string) StorageInfo {
197+
func (s *ContextStore) GetStorageInfo(contextName string) StorageInfo {
198198
dir := contextdirOf(contextName)
199199
return StorageInfo{
200200
MetadataPath: s.meta.contextDir(dir),

cli/context/store/storeconfig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func EndpointTypeGetter(name string, getter TypeGetter) NamedTypeGetter {
1919
}
2020
}
2121

22-
// Config is used to configure the metadata marshaler of the context store
22+
// Config is used to configure the metadata marshaler of the context ContextStore
2323
type Config struct {
2424
contextType TypeGetter
2525
endpointTypes map[string]TypeGetter

cli/context/store/storeconfig_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import (
66
"gotest.tools/v3/assert"
77
)
88

9-
type testCtx struct{}
10-
type testEP1 struct{}
11-
type testEP2 struct{}
12-
type testEP3 struct{}
9+
type (
10+
testCtx struct{}
11+
testEP1 struct{}
12+
testEP2 struct{}
13+
testEP3 struct{}
14+
)
1315

1416
func TestConfigModification(t *testing.T) {
1517
cfg := NewConfig(func() interface{} { return &testCtx{} }, EndpointTypeGetter("ep1", func() interface{} { return &testEP1{} }))
@@ -24,7 +26,7 @@ func TestConfigModification(t *testing.T) {
2426
assert.Equal(t, &testCtx{}, cfg.contextType())
2527
assert.Equal(t, &testEP2{}, cfg.endpointTypes["ep1"]())
2628
assert.Equal(t, &testEP3{}, cfg.endpointTypes["ep2"]())
27-
// check it applied on already initialized store
29+
// check it applied on already initialized ContextStore
2830
assert.Equal(t, &testCtx{}, cfgCopy.contextType())
2931
assert.Equal(t, &testEP2{}, cfgCopy.endpointTypes["ep1"]())
3032
assert.Equal(t, &testEP3{}, cfgCopy.endpointTypes["ep2"]())

0 commit comments

Comments
 (0)