Documentation
¶
Index ¶
- Constants
- func AddUserInfo(userService *userSvc.Service) gin.HandlerFunc
- func Auth(secret string) gin.HandlerFunc
- func AuthWithOptions(opts AuthOption) gin.HandlerFunc
- func ClearDashboardCookie(c *gin.Context)
- func DashboardAuth(secret string, users UserProvider) gin.HandlerFunc
- func GetClientIP(c *gin.Context) string
- func IPRateLimit(opts IPRateLimitOption) gin.HandlerFunc
- func Idempotency(repo storage.IdempotencyRepository, log *zap.Logger) gin.HandlerFunc
- func IsPrivateIP(ip string) bool
- func RateLimit(opts RateLimitOption) gin.HandlerFunc
- func RequestID() gin.HandlerFunc
- func RequireAdmin(userService *userSvc.Service) gin.HandlerFunc
- func RequireRole(userService *userSvc.Service, requiredRole string) gin.HandlerFunc
- func SentryReport() gin.HandlerFunc
- func SetDashboardCookie(c *gin.Context, token string)
- type AuthOption
- type IPRateLimitOption
- type RateLimitOption
- type UserProvider
Constants ¶
const ( IdempotencyHeader = "Idempotency-Key" // Tells the caller the response came from the store, not from a new send. IdempotencyReplayHeader = "X-Idempotent-Replay" IdempotencyTTL = 24 * time.Hour )
const HeaderRequestID = "X-Request-ID"
Variables ¶
This section is empty.
Functions ¶
func AddUserInfo ¶
func AddUserInfo(userService *userSvc.Service) gin.HandlerFunc
func Auth ¶
func Auth(secret string) gin.HandlerFunc
func AuthWithOptions ¶
func AuthWithOptions(opts AuthOption) gin.HandlerFunc
func ClearDashboardCookie ¶
func DashboardAuth ¶
func DashboardAuth(secret string, users UserProvider) gin.HandlerFunc
func GetClientIP ¶
func IPRateLimit ¶
func IPRateLimit(opts IPRateLimitOption) gin.HandlerFunc
IPRateLimit enforces per-IP limits for public routes.
func Idempotency ¶ added in v1.2.0
func Idempotency(repo storage.IdempotencyRepository, log *zap.Logger) gin.HandlerFunc
Idempotency makes a retried POST safe: the first request stores its result under the caller's key and a repeat replays it, instead of sending the same message to WhatsApp twice. Follows draft-ietf-httpapi-idempotency-key-header: 409 while the original still runs, 422 when the key comes back with a different payload.
Without the header the request goes straight through, so callers that do not send a key behave exactly as before.
func IsPrivateIP ¶
func RateLimit ¶
func RateLimit(opts RateLimitOption) gin.HandlerFunc
RateLimit counts requests per token using Redis.
func RequestID ¶
func RequestID() gin.HandlerFunc
func RequireAdmin ¶
func RequireAdmin(userService *userSvc.Service) gin.HandlerFunc
func RequireRole ¶
func RequireRole(userService *userSvc.Service, requiredRole string) gin.HandlerFunc
func SentryReport ¶ added in v1.2.0
func SentryReport() gin.HandlerFunc
SentryReport reports to Sentry any errors accumulated via c.Error() and any 5xx responses, tagged with the route and request-id. It only runs when Sentry is enabled (conditional registration in the router).
func SetDashboardCookie ¶
Types ¶
type AuthOption ¶
type AuthOption struct {
JWTSecret string
APITokenService *apiTokenSvc.Service
InstanceRepo storage.InstanceRepository
}
AuthOption configures the authentication middleware.