From 130cd06dc4c96299e7212d7c08be7d0a0ac1e2c1 Mon Sep 17 00:00:00 2001 From: ditatompel Date: Thu, 30 May 2024 13:40:57 +0700 Subject: [PATCH] Make X-Prober-Api-Key as constant --- cmd/client/probe.go | 4 ++-- handler/middlewares.go | 2 +- internal/monero/prober.go | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/client/probe.go b/cmd/client/probe.go index 81d4b17..7fcc83d 100644 --- a/cmd/client/probe.go +++ b/cmd/client/probe.go @@ -99,7 +99,7 @@ func (p *proberClient) fetchJob() (monero.Node, error) { if err != nil { return node, err } - req.Header.Add("X-Prober-Api-Key", p.config.ApiKey) + req.Header.Add(monero.ProberAPIKey, p.config.ApiKey) req.Header.Set("User-Agent", RPCUserAgent) client := &http.Client{} @@ -285,7 +285,7 @@ func (p *proberClient) reportResult(node monero.Node, tookTime float64) error { if err != nil { return err } - req.Header.Add("X-Prober-Api-Key", p.config.ApiKey) + req.Header.Add(monero.ProberAPIKey, p.config.ApiKey) req.Header.Set("Content-Type", "application/json; charset=UTF-8") req.Header.Set("User-Agent", RPCUserAgent) diff --git a/handler/middlewares.go b/handler/middlewares.go index 3597275..c8c596d 100644 --- a/handler/middlewares.go +++ b/handler/middlewares.go @@ -7,7 +7,7 @@ import ( ) func CheckProber(c *fiber.Ctx) error { - key := c.Get("X-Prober-Api-Key") + key := c.Get(monero.ProberAPIKey) if key == "" { return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{ "status": "error", diff --git a/internal/monero/prober.go b/internal/monero/prober.go index 8925f29..92cd101 100644 --- a/internal/monero/prober.go +++ b/internal/monero/prober.go @@ -9,6 +9,8 @@ import ( "github.com/google/uuid" ) +const ProberAPIKey = "X-Prober-Api-Key" // HTTP header key + type ProberRepository interface { Add(name string) (Prober, error) Edit(id int, name string) error