This repository was archived by the owner on Dec 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.go
More file actions
64 lines (54 loc) · 1.2 KB
/
config.go
File metadata and controls
64 lines (54 loc) · 1.2 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
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"github.com/monoxane/nk"
)
type Configuration struct {
Server Server `json:"server"`
Router Router `json:"router"`
Probe Probe `json:"probe"`
Salvos []Salvo `json:"salvos"`
}
type Server struct {
Port int `json:"port"`
FirstProbeStreamPort int `json:"first_probe_stream_port"`
}
type Router struct {
IP string `json:"ip"`
Address int `json:"address"`
Model string `json:"model"`
}
type Probe struct {
Enabled bool `json:"enabled"`
RouterDestinations []int `json:"router_destinations"`
}
type Salvo struct {
Label string `json:"label"`
Destinations []nk.Destination `json:"destinations"`
}
func (c *Configuration) Save() {
file, err := json.MarshalIndent(c, "", " ")
if err != nil {
log.Printf("unable to marshal config: %s", err)
return
}
err = ioutil.WriteFile("config.json", file, 0777)
if err != nil {
log.Printf("unable to save config: %s", err)
return
}
log.Print("saved config")
}
var Config Configuration
func init() {
data, err := os.ReadFile("config.json")
if err == nil {
err = json.Unmarshal(data, &Config)
if err != nil {
log.Fatalln(err)
}
}
}