-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
73 lines (61 loc) · 1.71 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"encoding/json"
"errors"
"io/ioutil"
"os"
"path/filepath"
)
type CustomCommand struct {
Command string `json:"command"`
Force bool `json:"force"`
}
type Config struct {
Name string `json:"name"`
Key string `json:"key"`
Path string `json:"path"`
ExternalPort int `json:"externalPort"`
InternalPort int `json:"internalPort"`
ContainerName string `json:"containerName"`
GithubToken string `json:"githubToken"`
DockerVolume bool `json:"dockerVolume"`
CustomVolume string `json:"customVolume"`
Branch string `json:"branch"`
Seamless bool `json:"seamless"`
ReadyForUpdateURL string `json:"readyForUpdateWebhook"`
Commands []CustomCommand `json:"commands"`
}
func FindConfigWithSpecificValue(name string) (*Config, error) {
var foundConfig *Config
err := filepath.Walk("/projects/configs", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if filepath.Ext(path) == ".json" {
if info.IsDir() {
return nil
}
rawJson, err := ioutil.ReadFile(path)
if err != nil {
return err
}
var config Config
err = json.Unmarshal(rawJson, &config)
if err != nil {
return err
}
if config.Name == name {
foundConfig = &config
return errors.New("desired config found")
}
}
return nil
})
if foundConfig != nil {
return foundConfig, nil
} else if err != nil && err.Error() == "desired config found" {
return foundConfig, nil
} else {
return nil, errors.New("desired config not found")
}
}