{"modulePath":"github.com/vidyesh95/Go-Tutorial","version":"v0.0.0-20261123112932-610d9af314ca","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package httpapi\n\nPackage httpapi is the HTTP transport layer: routing, middleware, JSON encoding and the mapping from domain errors to status codes. It contains NO business rules; handlers decode a request, call a service, and encode the result.\n\nRequest flow (outermost middleware first):\n\n\trequestID -\u003e accessLog -\u003e metrics -\u003e recoverer -\u003e cors -\u003e rateLimit -\u003e ServeMux\n\t                                                                          |\n\t                       (per route) [csrf, strict rate limit] requireAuth -\u003e handler -\u003e service -\u003e store\n\nrequireAuth accepts a Bearer JWT or a session cookie; see its documentation.\n\nOrder matters:\n\n  - requestID is outermost so every later log line carries the id.\n  - accessLog and metrics sit outside recoverer so they see the 500 that a panic becomes.\n  - rateLimit runs before routing and auth, so floods are rejected cheaply, before any token parsing or database work.\n  - Nothing between metrics and the mux may replace the \\*http.Request (see routeOf).\n\n## Functions\n\n```go\nfunc NewHandler(ctx context.Context, d Deps) http.Handler\n```\nNewHandler builds the complete HTTP handler. ctx bounds background goroutines started here (the rate limiter's janitor): cancel it on shutdown.\n\n## Types\n\n```go\ntype Deps struct {\n\tLogger   *slog.Logger\n\tAuth     *service.AuthService\n\tProjects *service.ProjectService\n\tTasks    *service.TaskService\n\tTokens   TokenVerifier\n\tDB       Pinger\n\n\t// SessionAuth (required) powers the cookie-session mode and the /v1/session-auth/* endpoints.\n\tSessionAuth *service.SessionAuthService\n\t// GitHub enables \"Sign in with GitHub\" when non-nil; the OAuth routes are 404 otherwise.\n\tGitHub *auth.GitHub\n\t// CookieSecure sets the Secure attribute on cookies. true in production; false only for\n\t// plain-http local development.\n\tCookieSecure bool\n\n\t// Draining flips to true when shutdown begins; /readyz then returns 503 so the load balancer\n\t// stops sending new traffic while in-flight requests finish. May be nil.\n\tDraining *atomic.Bool\n\n\tRateRPS     float64\n\tRateBurst   int\n\tCORSOrigins []string\n\n\t// AuthRateRPS/AuthRateBurst are the (much stricter) per-IP limit for credential endpoints:\n\t// sign-in, sign-up, password reset, verification mail. Zero falls back to RateRPS/RateBurst.\n\tAuthRateRPS   float64\n\tAuthRateBurst int\n\n\t// CleanupInterval is how often expired sessions and tokens are deleted (default 1 hour).\n\tCleanupInterval time.Duration\n}\n```\nDeps is everything the HTTP layer needs, passed explicitly (no globals, no init()).\n\n```go\ntype Pinger interface {\n\tPingContext(ctx context.Context) error\n}\n```\nPinger is the slice of \\*sql.DB the readiness probe needs.\n\n```go\ntype SessionVerifier interface {\n\tAuthenticate(ctx context.Context, token string) (service.SessionState, error)\n}\n```\nSessionVerifier resolves a session cookie value. \\*service.SessionAuthService satisfies it.\n\n```go\ntype TokenVerifier interface {\n\tParse(token string) (auth.Claims, error)\n}\n```\nTokenVerifier validates a bearer token. \\*auth.Issuer satisfies it.\n\n","path":"github.com/vidyesh95/Go-Tutorial/05-projects/taskapi/internal/httpapi","name":"httpapi","synopsis":"Package httpapi is the HTTP transport layer: routing, middleware, JSON encoding and the mapping from domain errors to status codes.","isRedistributable":true}
