diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-04-22 16:29:59 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-04-22 16:29:59 +0200 |
| commit | b1d92b395322f2164ccfb44b0f7caebbaece6b62 (patch) | |
| tree | 2133e4045b4af4d07a98674b7ae3a234670f0305 /src/config.go | |
| parent | 3a4ae2942b43923ff98fd2eca8878c3cf145686c (diff) | |
Refactor: Restructure project
- Add an internal folder where all the internal code lives
- Make a state.go and state_test.go for the public interface
This gives a more clear separation between functions and modules. It
also makes this a more typical Go project setup.
Diffstat (limited to 'src/config.go')
| -rw-r--r-- | src/config.go | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/src/config.go b/src/config.go deleted file mode 100644 index 6db3cb2..0000000 --- a/src/config.go +++ /dev/null @@ -1,42 +0,0 @@ -package eduvpn - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "os" - "path" -) - -func (eduvpn *VPNState) EnsureConfigDir() error { - mkdirErr := os.MkdirAll(eduvpn.ConfigDirectory, os.ModePerm) - if mkdirErr != nil { - return mkdirErr - } - return nil -} - -func (eduvpn *VPNState) GetConfigName() string { - pathString := path.Join(eduvpn.ConfigDirectory, eduvpn.Name) - return fmt.Sprintf("%s.json", pathString) -} - -func (eduvpn *VPNState) WriteConfig() error { - configDirErr := eduvpn.EnsureConfigDir() - if configDirErr != nil { - return configDirErr - } - jsonString, marshalErr := json.Marshal(eduvpn) - if marshalErr != nil { - return marshalErr - } - return ioutil.WriteFile(eduvpn.GetConfigName(), jsonString, 0o644) -} - -func (eduvpn *VPNState) LoadConfig() error { - bytes, readErr := ioutil.ReadFile(eduvpn.GetConfigName()) - if readErr != nil { - return readErr - } - return json.Unmarshal(bytes, eduvpn) -} |
