MCPcopy Create free account
hub / github.com/BryanMwangi/pine / requireAPIKey

Function requireAPIKey

Examples/GroupExample/main.go:65–75  ·  view source on GitHub ↗

requireAPIKey checks for a valid X-API-Key header. Attach it to a group to gate an entire sub-tree without touching each handler.

()

Source from the content-addressed store, hash-verified

63// requireAPIKey checks for a valid X-API-Key header.
64// Attach it to a group to gate an entire sub-tree without touching each handler.
65func requireAPIKey() pine.Middleware {
66 const validKey = "super-secret-key"
67 return func(next pine.Handler) pine.Handler {
68 return func(c *pine.Ctx) error {
69 if c.Header("X-API-Key") != validKey {
70 return c.Status(401).JSON(map[string]string{"error": "unauthorized"})
71 }
72 return next(c)
73 }
74 }
75}

Callers 1

mainFunction · 0.85

Calls 3

HeaderMethod · 0.80
StatusMethod · 0.80
JSONMethod · 0.45

Tested by

no test coverage detected