forked from utmstack/UTMStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
77 lines (60 loc) · 1.27 KB
/
Copy pathconfig.go
File metadata and controls
77 lines (60 loc) · 1.27 KB
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
74
75
76
77
package main
import (
"fmt"
"os"
"path"
"gopkg.in/yaml.v2"
)
type Config struct {
MainServer string `yaml:"main_server"`
Branch string `yaml:"branch"`
Password string `yaml:"password"`
DataDir string `yaml:"data_dir"`
ServerType string `yaml:"server_type"`
ServerName string `yaml:"server_name"`
InternalKey string `yaml:"internal_key"`
}
var configPath = path.Join("/root", "utmstack.yml")
func (c *Config) Get() error {
config, err := os.ReadFile(configPath)
if err != nil {
return err
}
err = yaml.UnmarshalStrict(config, c)
if err != nil {
return err
}
if c.DataDir == "" {
return fmt.Errorf("data_dir is empty")
}
if c.Password == "" {
return fmt.Errorf("password is empty")
}
if c.Branch == "" {
return fmt.Errorf("branch is empty")
}
if c.MainServer == "" {
return fmt.Errorf("main_server is empty")
}
if c.ServerType == "" {
return fmt.Errorf("server_type is empty")
}
if c.ServerName == "" {
return fmt.Errorf("server_name is empty")
}
if c.InternalKey == "" {
return fmt.Errorf("internal_key is empty")
}
return nil
}
func (c *Config) Set() error {
config, err := yaml.Marshal(c)
if err != nil {
return err
}
err = os.WriteFile(configPath, config, 0644)
if err != nil {
return err
}
return nil
}