aboutsummaryrefslogtreecommitdiff
path: root/internal/handlers
diff options
context:
space:
mode:
authorRaúl Benencia <id@rbenencia.name>2026-06-05 09:53:24 -0300
committerRaul Benencia <46945030+raul-te@users.noreply.github.com>2026-06-05 10:34:02 -0300
commita9f0622ed9750593ca6de12a27bb3a92c4e419e4 (patch)
tree604da45bf92642f77fd8774ae3cd8ae2a26abc94 /internal/handlers
parent4abb0469fd32c59da1af00c90887cabb59dd6e4c (diff)
Use slog logging
Drop go-kit/kit/log in favor of the now standard log/slog.
Diffstat (limited to 'internal/handlers')
-rw-r--r--internal/handlers/events.go2
-rw-r--r--internal/handlers/middleware.go2
-rw-r--r--internal/handlers/polling.go13
3 files changed, 8 insertions, 9 deletions
diff --git a/internal/handlers/events.go b/internal/handlers/events.go
index f794343..9480169 100644
--- a/internal/handlers/events.go
+++ b/internal/handlers/events.go
@@ -26,7 +26,7 @@ func ListEvents(w http.ResponseWriter, r *http.Request) {
env := envFromRequest(r)
eventList, err := json.Marshal(env.EventLog.Events)
if err != nil {
- env.Logger.Error("component", "handler", "err", err)
+ env.Logger.Error("marshal events failed", "component", "handler", "err", err)
os.Exit(1)
}
diff --git a/internal/handlers/middleware.go b/internal/handlers/middleware.go
index 9525efb..7ad00a0 100644
--- a/internal/handlers/middleware.go
+++ b/internal/handlers/middleware.go
@@ -55,7 +55,7 @@ func loggingMiddleware(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
logger := envFromRequest(r).Logger
- logger.Info("component", "http", "type", "request", "src", r.RemoteAddr, "method", r.Method, "url", r.URL)
+ logger.Info("http request", "component", "http", "type", "request", "src", r.RemoteAddr, "method", r.Method, "url", r.URL)
h.ServeHTTP(w, r)
})
}
diff --git a/internal/handlers/polling.go b/internal/handlers/polling.go
index 51fd8ad..c5aeb50 100644
--- a/internal/handlers/polling.go
+++ b/internal/handlers/polling.go
@@ -32,12 +32,11 @@ import (
func StartPollingHandler(w http.ResponseWriter, r *http.Request) {
env := envFromRequest(r)
- script := polling.GenStartScript(env.Logger, env.BaseURL)
+ script := polling.GenStartScript(env.Logger, env.BaseURL)
w.Write([]byte(script))
}
-
// PollHandler is called by iPXE boot agents. It returns the boot script
// specified on the configuration or, if the host is unknown, it makes it
// retry for a while until the user specifies alternative IPXE boot script.
@@ -84,7 +83,7 @@ func ServerListHandler(w http.ResponseWriter, r *http.Request) {
servers, err := json.Marshal(polling.ListServers(env.ServerStates))
if err != nil {
- env.Logger.Error("component", "handler", "err", err)
+ env.Logger.Error("marshal servers failed", "component", "handler", "err", err)
os.Exit(1)
}
@@ -147,16 +146,16 @@ func parsePostForm(form map[string][]string) (mac, scriptName, environment strin
func validateMACAndIP(logger log.Logger, mac string, ip string) (err error) {
if !utils.IsValidMAC(mac) {
- logger.Error("component", "polling", "msg", "Invalid MAC", "mac", mac)
+ logger.Error("invalid mac", "component", "polling", "mac", mac)
return fmt.Errorf("%s", "Invalid MAC")
}
if !utils.IsValidIP(ip) {
- logger.Error("component", "polling", "msg", "Invalid IP", "ip", ip)
+ logger.Error("invalid ip", "component", "polling", "ip", ip)
return fmt.Errorf("%s", "Invalid IP")
}
- logger.Debug("component", "polling", "msg", "MAC and IP validated", "mac", mac, "ip", ip)
+ logger.Debug("mac and ip validated", "component", "polling", "mac", mac, "ip", ip)
return nil
}
@@ -164,7 +163,7 @@ func validateMACAndIP(logger log.Logger, mac string, ip string) (err error) {
func resolveHostname(logger log.Logger, ip string) string {
host := utils.ResolveHostname(ip)
if host == "" {
- logger.Info("component", "polling", "msg", "Can't resolve IP", "ip", ip)
+ logger.Info("can't resolve ip", "component", "polling", "ip", ip)
}
return host
nihil fit ex nihilo