-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
99 lines (84 loc) · 2.53 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"fmt"
"gopkg.in/yaml.v3"
"strconv"
)
type configuration struct {
RootDomain string `yaml:"root_domain,omitempty"`
Timezone string `yaml:"timezone,omitempty"`
LocalEnvironment bool `yaml:"local_environment,omitempty"`
Security struct {
RootDomainPolicy string `yaml:"root_domain_policy,omitempty"`
} `yaml:"security,omitempty"`
Smtp struct {
Username string `yaml:"username,omitempty"`
Password string `yaml:"password,omitempty"`
Host string `yaml:"host,omitempty"`
Port int `yaml:"port,omitempty"`
Sender string `yaml:"sender,omitempty"`
StartupAddress string `yaml:"startup_address,omitempty"`
} `yaml:"smtp,omitempty"`
TraefikHub struct {
Enabled bool `yaml:"enabled,omitempty"`
Key string `yaml:"key,omitempty"`
} `yaml:"traefik_hub,omitempty"`
Cloudflare struct {
Enabled bool `yaml:"enabled,omitempty"`
Email string `yaml:"email,omitempty"`
ApiKey string `yaml:"api_key,omitempty"`
} `yaml:"cloudflare,omitempty"`
}
/*
Write config to file
*/
func (c *configuration) writeConfig() {
yamlData, err := yaml.Marshal(&c)
if err != nil {
fmt.Printf("Error while Marshaling. %v", err)
}
writeFile("AppData", "traefik-installer.yaml", yamlData, 0644)
}
/*
Read config file
*/
func (c *configuration) readConfig() *configuration {
content := readFile("AppData", "traefik-installer.yaml")
err := yaml.Unmarshal(content, c)
if err != nil {
return c
}
return c
}
/*
list configuration with println
*/
func (c *configuration) toText() {
fmt.Println("Root-Domain: " + c.RootDomain)
fmt.Println("Timezone: " + c.Timezone)
if c.LocalEnvironment {
fmt.Println("Is local environment: yes")
} else {
fmt.Println("Is local environment: no")
}
fmt.Println("Root-Domain-Policy: " + c.Security.RootDomainPolicy)
fmt.Println("Smtp-Username: " + c.Smtp.Username)
fmt.Println("Smtp-Password: " + c.Smtp.Password)
fmt.Println("Smtp-Host: " + c.Smtp.Host)
fmt.Println("Smtp-Port: " + strconv.Itoa(c.Smtp.Port))
fmt.Println("Smtp-Sender: " + c.Smtp.Sender)
fmt.Println("Smtp-Startup Address: " + c.Smtp.StartupAddress)
if c.TraefikHub.Enabled {
fmt.Println("Traefik-Hub enabled: yes")
fmt.Println("Traefik-Hub Key: " + c.TraefikHub.Key)
} else {
fmt.Println("Traefik-Hub enabled: no")
}
if c.Cloudflare.Enabled {
fmt.Println("Cloudflare enabled: yes")
fmt.Println("Cloudflare Email: " + c.Cloudflare.Email)
fmt.Println("Cloudflare Api-Key: " + c.Cloudflare.ApiKey)
} else {
fmt.Println("Cloudflare enabled: no")
}
}