Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 3891c8c

Browse files
committed
Put all magic strings in variables in context store
1 parent 0bd1898 commit 3891c8c

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

context/store/store.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ const (
4848
)
4949

5050
const (
51-
contextsDir = "contexts"
52-
metadataDir = "meta"
53-
metaFile = "meta.json"
51+
dockerEndpointKey = "docker"
52+
configDir = ".docker"
53+
contextsDir = "contexts"
54+
metadataDir = "meta"
55+
metaFile = "meta.json"
5456
)
5557

5658
type contextStoreKey struct{}
@@ -103,7 +105,7 @@ func New(opts ...Opt) (Store, error) {
103105
return nil, err
104106
}
105107
s := &store{
106-
root: filepath.Join(home, ".docker"),
108+
root: filepath.Join(home, configDir),
107109
}
108110
if _, err := os.Stat(s.root); os.IsNotExist(err) {
109111
if err = os.Mkdir(s.root, 0755); err != nil {
@@ -190,11 +192,12 @@ func parse(payload []byte, getter func() interface{}) (interface{}, error) {
190192

191193
func (s *store) GetType(meta *Metadata) string {
192194
for k := range meta.Endpoints {
193-
if k != "docker" {
195+
if k != dockerEndpointKey {
194196
return k
195197
}
196198
}
197-
return "docker"
199+
200+
return dockerEndpointKey
198201
}
199202

200203
func (s *store) Create(name string, data TypedContext) error {
@@ -220,8 +223,8 @@ func (s *store) Create(name string, data TypedContext) error {
220223
Name: name,
221224
Metadata: data,
222225
Endpoints: map[string]interface{}{
223-
"docker": dummyContext{},
224-
(data.Type): dummyContext{},
226+
(dockerEndpointKey): dummyContext{},
227+
(data.Type): dummyContext{},
225228
},
226229
}
227230

0 commit comments

Comments
 (0)