Compare commits

..

No commits in common. "32e62376809f2ee4de8a2585d55b143737d2c0a9" and "96f36577c34824b90f8aff76b2c190f3ea3aae0c" have entirely different histories.

53
main.go
View File

@ -16,7 +16,6 @@ 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 {
@ -32,7 +31,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, "Days", config.Days, "API URL", config.Horn["url"])) logger.Info("Config loaded", logger.Args("Times", config.Times, "API URL", config.Horn["url"]))
return config return config
} }
@ -48,7 +47,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.2") pterm.DefaultCenter.Println("v1.1")
pterm.Print("\n") pterm.Print("\n")
@ -61,34 +60,28 @@ func main() {
for { for {
ctime := time.Now().Format("15:04:05") ctime := time.Now().Format("15:04:05")
cday := time.Now().Weekday()
for _, day := range config.Days { for _, time := range config.Times {
if day == cday.String() { if time == ctime {
for _, time := range config.Times { http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
if time == ctime { client := &http.Client{
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} Transport: &digest.Transport{
client := &http.Client{ Username: config.Horn["username"],
Transport: &digest.Transport{ Password: config.Horn["password"],
Username: config.Horn["username"], },
Password: config.Horn["password"], }
}, req, err := http.NewRequest("GET", config.Horn["url"], nil)
} if err != nil {
req, err := http.NewRequest("GET", config.Horn["url"], nil) logger.Error(fmt.Sprintf("%s", err))
if err != nil { }
logger.Error(fmt.Sprintf("%s", err)) resp, err := client.Do(req)
} if err != nil {
resp, err := client.Do(req) logger.Error(fmt.Sprintf("%s", err))
if err != nil { }
logger.Error(fmt.Sprintf("%s", err)) if resp.StatusCode != 200 {
} logger.Error(fmt.Sprintf("HTTP request failed: %s", resp.Status))
if resp.StatusCode != 200 { } else {
logger.Error(fmt.Sprintf("HTTP request failed: %s", resp.Status)) logger.Info(fmt.Sprintf("Sending HTTP request to %s", config.Horn["url"]), logger.Args("Reason", "Config File", "Time", ctime, "Status Code", 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))
}
}
} }
} }
} }