diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 622efad..e032f4b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -34,6 +34,6 @@ jobs: fail_ci_if_error: true - name: Run linter - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v6 with: version: latest \ No newline at end of file diff --git a/cmd/rota/main.go b/cmd/rota/main.go index 0e33166..258e3cd 100644 --- a/cmd/rota/main.go +++ b/cmd/rota/main.go @@ -25,6 +25,8 @@ const ( msgFailedToLoadProxies = "failed to load proxies" msgWatchingProxyFile = "watching proxy file" msgMissingProxyFile = "missing proxy file" + msgFailedToCheckProxies = "failed to check proxies" + msgFailedToServeApi = "failed to serve api" msgFailedToListen = "failed to listen" msgReceivedSignal = "received signal, shutting down..." ) @@ -53,7 +55,11 @@ func main() { if cfgManager.Check { proxyChecker := proxy.NewProxyChecker(cfg, proxyServer) - proxyChecker.Check() + err = proxyChecker.Check() + if err != nil { + slog.Error(msgFailedToCheckProxies, "error", err) + os.Exit(1) + } return } @@ -106,5 +112,9 @@ func runApi(cfg *config.Config) { } api := api.NewApi(cfg) - api.Serve() + err := api.Serve() + if err != nil { + slog.Error(msgFailedToServeApi, "error", err) + os.Exit(1) + } } diff --git a/internal/api/api.go b/internal/api/api.go index 6de0b57..c17ad2e 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -22,6 +22,7 @@ const ( msgMetricsRequested = "metrics requested" msgMethodNotAllowed = "method not allowed" msgFailedToCollectMetrics = "failed to collect metrics" + msgFailedToWriteMetrics = "failed to write metrics" ) type Api struct { @@ -105,7 +106,12 @@ func (a *Api) handleMetrics(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(metrics) + err = json.NewEncoder(w).Encode(metrics) + if err != nil { + slog.Error(msgFailedToWriteMetrics, "error", err) + http.Error(w, msgFailedToWriteMetrics, http.StatusInternalServerError) + return + } } func collectMetrics() (*metrics, error) { diff --git a/internal/proxy/check.go b/internal/proxy/check.go index e83fb98..3d47e7f 100644 --- a/internal/proxy/check.go +++ b/internal/proxy/check.go @@ -22,6 +22,7 @@ const ( msgFailedToCreateRequest = "failed to create request" msgDeadProxy = "dead proxy" msgAliveProxy = "alive proxy" + msgFailedToWriteOutputFile = "failed to write output file" ) type ProxyChecker struct { @@ -92,6 +93,9 @@ func (pl *ProxyChecker) checkProxy(proxy *Proxy, outputFile *os.File) { slog.Info(msgAliveProxy, "proxy", proxy.Host) if outputFile != nil { - outputFile.WriteString(proxy.Host + "\n") + _, err = outputFile.WriteString(proxy.Host + "\n") + if err != nil { + slog.Error(msgFailedToWriteOutputFile, "error", err) + } } }