Skip to content

Commit

Permalink
Fix call
Browse files Browse the repository at this point in the history
  • Loading branch information
scheibling committed Feb 4, 2024
1 parent 08ec247 commit 77201d5
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,13 @@ func ListemSmtps(tlss *smtp.Server) {
func ListenHealthcheck(cfg *Config) {
updateToken := os.Getenv("X_UPDATE_TOKEN")

handleAccountsFunc := func(w http.ResponseWriter, r *http.Request) {
http.ListenAndServe(":8080", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "accounts.json" && r.Method != "POST" {
w.WriteHeader(200)
w.Write([]byte("OK"))
return
}

if updateToken == "" {
w.WriteHeader(500)
w.Write([]byte("X_UPDATE_TOKEN not set"))
Expand Down Expand Up @@ -250,16 +256,7 @@ func ListenHealthcheck(cfg *Config) {
cfg.Credentials = updatedAccounts
fmt.Println("Updated accounts: ")
fmt.Println(cfg.Credentials)
}

http.HandleFunc("/accounts.json", handleAccountsFunc)

http.ListenAndServe(":8080", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/accounts.json" && r.Method == "POST" {
handleAccountsFunc(w, r)
}
w.WriteHeader(200)
w.Write([]byte("OK"))
})) // nolint:errcheck
}

Expand Down

0 comments on commit 77201d5

Please sign in to comment.