Skip to content

Instantly share code, notes, and snippets.

@nickajacks1
nickajacks1 / ctx_proposed.go
Created January 4, 2024 03:23
Proposal for clarifying Request and Response APIs.
// Sample proposed changes to have Ctx act as an alias to req and res methods where possible
// The Ctx API remains as-is for the most part. The implementation in DefaultCtx would be delegated
// to new Request and Response objects.
// Certain portions of the Ctx API exist because of the lack of distinct Request and Response APIs.
// GetRespHeader, for example, is an artifact of overlap between request and response functionality (Get() was taken!).
// It wouldn't need to exist if users could instead call `c.Res().Get("Content-Type")`
// Gets the request's cookies
func (c *DefaultCtx) Cookies(key string, defaultValue ...string) string {
return c.req.Cookies(key, defaultValue)