fix lint error

Kim committed Mar 6, 2026 at 15:55 UTC 3d66144ec367a599891f31bc42f2fd1593739535
5 files changed +22 -38
cmd/relay-server/serve.go
+4 -10
@@ -56,17 +56,11 @@ func runServer(cfg relayServerConfig) error {
56 }
57
58 frontend := NewFrontend(cfg.PortalURL)
59 - adminHandler := portaladmin.NewHandler(portaladmin.Config{
60 - PortalURL: cfg.PortalURL,
61 - Secret: cfg.AdminSecretKey,
62 - TrustProxy: cfg.TrustProxyHeaders,
63 - SettingsPath: "admin_settings.json",
64 - ServeAppStatic: func(w http.ResponseWriter, r *http.Request, appPath string) {
65 - frontend.ServeAppStatic(w, r, appPath)
66 - },
59 + adminHandler := portaladmin.NewHandler(cfg.PortalURL, cfg.AdminSecretKey, "admin_settings.json", cfg.TrustProxyHeaders, func(w http.ResponseWriter, r *http.Request, appPath string) {
60 + frontend.ServeAppStatic(w, r, appPath)
61 })
68 - if err := adminHandler.LoadSettings(); err != nil {
69 - logger.Warn().Err(err).Msg("load admin settings")
62 + if loadErr := adminHandler.LoadSettings(); loadErr != nil {
63 + logger.Warn().Err(loadErr).Msg("load admin settings")
64 }
65
66 server, err := portal.NewServer(portal.ServerConfig{
portal/admin/handler.go
+13 -19
@@ -14,34 +14,28 @@ import (
14
15 const cookieName = "portal_admin"
16
17 -type Config struct {
18 - PortalURL string
19 - Secret string
20 - SettingsPath string
21 - TrustProxy bool
22 - ServeAppStatic func(http.ResponseWriter, *http.Request, string)
23 -}
24 -
17 type Handler struct {
18 auth *policy.Authenticator
19 runtime *policy.Runtime
20 server *portal.Server
21 settings *stateStore
30 - portalURL string
31 - trustProxy bool
22 serveAppStatic func(http.ResponseWriter, *http.Request, string)
23 + buildLeaseRows func(*portal.Server, bool) []LeaseRow
24 + trustProxy bool
25 }
26
35 -func NewHandler(cfg Config) *Handler {
27 +func NewHandler(portalURL, secret, settingsPath string, trustProxy bool, serveAppStatic func(http.ResponseWriter, *http.Request, string)) *Handler {
28 h := &Handler{
37 - auth: policy.NewAuthenticator(strings.TrimSpace(cfg.Secret)),
38 - runtime: policy.NewRuntime(),
39 - settings: newStateStore(cfg.SettingsPath),
40 - portalURL: strings.TrimSpace(cfg.PortalURL),
41 - trustProxy: cfg.TrustProxy,
29 + auth: policy.NewAuthenticator(strings.TrimSpace(secret)),
30 + runtime: policy.NewRuntime(),
31 + settings: newStateStore(settingsPath),
32 + buildLeaseRows: func(serv *portal.Server, includeAdmin bool) []LeaseRow {
33 + return BuildLeaseRows(serv, includeAdmin, portalURL)
34 + },
35 + trustProxy: trustProxy,
36 }
43 - if cfg.ServeAppStatic != nil {
44 - h.serveAppStatic = cfg.ServeAppStatic
37 + if serveAppStatic != nil {
38 + h.serveAppStatic = serveAppStatic
39 } else {
40 h.serveAppStatic = func(w http.ResponseWriter, r *http.Request, _ string) {
41 http.NotFound(w, r)
@@ -205,7 +199,7 @@ func (h *Handler) handleLeases(w http.ResponseWriter, r *http.Request) {
199 writeAPIError(w, http.StatusMethodNotAllowed, "method_not_allowed", "method not allowed")
200 return
201 }
208 - writeAPIData(w, http.StatusOK, BuildLeaseRows(h.server, true, h.portalURL))
202 + writeAPIData(w, http.StatusOK, h.buildLeaseRows(h.server, true))
203 }
204
205 func (h *Handler) handleBannedLeases(w http.ResponseWriter, r *http.Request) {
portal/admin/handler_test.go
+2 -6
@@ -15,12 +15,8 @@ import (
15 func TestLoginAndProtectedActions(t *testing.T) {
16 t.Parallel()
17
18 - handler := NewHandler(Config{
19 - Secret: "secret-key",
20 - SettingsPath: filepath.Join(t.TempDir(), "admin_settings.json"),
21 - ServeAppStatic: func(w http.ResponseWriter, _ *http.Request, _ string) {
22 - w.WriteHeader(http.StatusOK)
23 - },
18 + handler := NewHandler("https://portal.example.com", "secret-key", filepath.Join(t.TempDir(), "admin_settings.json"), false, func(w http.ResponseWriter, _ *http.Request, _ string) {
19 + w.WriteHeader(http.StatusOK)
20 })
21
22 loginRecorder := httptest.NewRecorder()
portal/policy/authenticator.go
+1 -1
@@ -169,8 +169,8 @@ func (a *Authenticator) enforceFailedLoginCapLocked() {
169 }
170
171 type failedEntry struct {
172 - ip string
172 lastSeenAt time.Time
173 + ip string
174 }
175
176 entries := make([]failedEntry, 0, len(a.failedLogins))
portal/server.go
+2 -2
@@ -396,8 +396,8 @@ func (s *Server) handleConnect(w http.ResponseWriter, r *http.Request) {
396 writeAPIError(w, http.StatusForbidden, "lease_rejected", "lease is not approved for routing")
397 return
398 }
399 - if err := s.authorizeLeaseToken(lease, token); err != nil {
400 - writeAPIError(w, http.StatusForbidden, "unauthorized", err.Error())
399 + if authErr := s.authorizeLeaseToken(lease, token); authErr != nil {
400 + writeAPIError(w, http.StatusForbidden, "unauthorized", authErr.Error())
401 return
402 }
403