Compare commits
2 Commits
96f36577c3
...
32e6237680
Author | SHA1 | Date | |
---|---|---|---|
32e6237680 | |||
3662b458aa |
53
main.go
53
main.go
@ -16,6 +16,7 @@ import (
|
|||||||
type config struct {
|
type config struct {
|
||||||
Horn map[string]string `yaml:"horn"`
|
Horn map[string]string `yaml:"horn"`
|
||||||
Times []string `yaml:"times"`
|
Times []string `yaml:"times"`
|
||||||
|
Days []string `yaml:"days"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *config) getConf() *config {
|
func (config *config) getConf() *config {
|
||||||
@ -31,7 +32,7 @@ func (config *config) getConf() *config {
|
|||||||
logger.Error("Unmarshal", logger.Args(":", err))
|
logger.Error("Unmarshal", logger.Args(":", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Info("Config loaded", logger.Args("Times", config.Times, "API URL", config.Horn["url"]))
|
logger.Info("Config loaded", logger.Args("Times", config.Times, "Days", config.Days, "API URL", config.Horn["url"]))
|
||||||
|
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
@ -47,7 +48,7 @@ func main() {
|
|||||||
|
|
||||||
pterm.DefaultCenter.Println(s)
|
pterm.DefaultCenter.Println(s)
|
||||||
pterm.DefaultCenter.Println("By Cody (" + pterm.LightBlue("https://oki.cx/tree") + ")")
|
pterm.DefaultCenter.Println("By Cody (" + pterm.LightBlue("https://oki.cx/tree") + ")")
|
||||||
pterm.DefaultCenter.Println("v1.1")
|
pterm.DefaultCenter.Println("v1.2")
|
||||||
|
|
||||||
pterm.Print("\n")
|
pterm.Print("\n")
|
||||||
|
|
||||||
@ -60,28 +61,34 @@ func main() {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
ctime := time.Now().Format("15:04:05")
|
ctime := time.Now().Format("15:04:05")
|
||||||
|
cday := time.Now().Weekday()
|
||||||
|
|
||||||
for _, time := range config.Times {
|
for _, day := range config.Days {
|
||||||
if time == ctime {
|
if day == cday.String() {
|
||||||
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
for _, time := range config.Times {
|
||||||
client := &http.Client{
|
if time == ctime {
|
||||||
Transport: &digest.Transport{
|
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||||
Username: config.Horn["username"],
|
client := &http.Client{
|
||||||
Password: config.Horn["password"],
|
Transport: &digest.Transport{
|
||||||
},
|
Username: config.Horn["username"],
|
||||||
}
|
Password: config.Horn["password"],
|
||||||
req, err := http.NewRequest("GET", config.Horn["url"], nil)
|
},
|
||||||
if err != nil {
|
}
|
||||||
logger.Error(fmt.Sprintf("%s", err))
|
req, err := http.NewRequest("GET", config.Horn["url"], nil)
|
||||||
}
|
if err != nil {
|
||||||
resp, err := client.Do(req)
|
logger.Error(fmt.Sprintf("%s", err))
|
||||||
if err != nil {
|
}
|
||||||
logger.Error(fmt.Sprintf("%s", err))
|
resp, err := client.Do(req)
|
||||||
}
|
if err != nil {
|
||||||
if resp.StatusCode != 200 {
|
logger.Error(fmt.Sprintf("%s", err))
|
||||||
logger.Error(fmt.Sprintf("HTTP request failed: %s", resp.Status))
|
}
|
||||||
} else {
|
if resp.StatusCode != 200 {
|
||||||
logger.Info(fmt.Sprintf("Sending HTTP request to %s", config.Horn["url"]), logger.Args("Reason", "Config File", "Time", ctime, "Status Code", resp.Status))
|
logger.Error(fmt.Sprintf("HTTP request failed: %s", resp.Status))
|
||||||
|
} else {
|
||||||
|
logger.Info(fmt.Sprintf("Sending HTTP request to %s", config.Horn["url"]),
|
||||||
|
logger.Args("Reason", "Config File", "Time", ctime, "Status Code", resp.Status))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user