-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
69 lines (55 loc) · 1.76 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
package main
import (
"encoding/json"
"fmt"
)
type ConfigSettings struct {
Host string `json:"host"`
Protocol string `json:"protocol"`
Interval string `json:"interval"`
ApiKey string `json:"api_key"`
}
type Config interface {
fetchJobUrl(string) string
fetchJobPostbackUrl() string
agentCheckinUrl() string
agentPingUrl() string
unregisterAgentUrl() string
SetProtocol(string)
Config() ConfigSettings
}
type SyswardConfig struct {
AgentConfig ConfigSettings
}
func NewConfig(filepath string) ConfigSettings {
var err error
config := ConfigSettings{}
file, err := fileReader.ReadFile(filepath)
// config_json := string(file)
err = json.Unmarshal(file, &config)
if err != nil {
panic(err)
}
return config
}
func (c SyswardConfig) Config() ConfigSettings {
return c.AgentConfig
}
func (c SyswardConfig) SetProtocol(protocol string) {
c.AgentConfig.Protocol = protocol
}
func (c SyswardConfig) fetchJobUrl(uid string) string {
return fmt.Sprintf("%s://%s/api/v1/jobs?uid=%s&api_key=%s", c.AgentConfig.Protocol, c.AgentConfig.Host, uid, c.AgentConfig.ApiKey)
}
func (c SyswardConfig) unregisterAgentUrl() string {
return fmt.Sprintf("%s://%s/api/v1/unregister?api_key=%s", c.AgentConfig.Protocol, c.AgentConfig.Host, c.AgentConfig.ApiKey)
}
func (c SyswardConfig) fetchJobPostbackUrl() string {
return fmt.Sprintf("%s://%s/api/v1/postback?api_key=%s", c.AgentConfig.Protocol, c.AgentConfig.Host, c.AgentConfig.ApiKey)
}
func (c SyswardConfig) agentPingUrl() string {
return fmt.Sprintf("%s://%s/api/v1/ping?api_key=%s", c.AgentConfig.Protocol, c.AgentConfig.Host, c.AgentConfig.ApiKey)
}
func (c SyswardConfig) agentCheckinUrl() string {
return fmt.Sprintf("%s://%s/api/v1/agent?api_key=%s", c.AgentConfig.Protocol, c.AgentConfig.Host, c.AgentConfig.ApiKey)
}