ctx

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2026 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const MaxBodySize int64 = 1 << 20

MaxBodySize is the default maximum request body size (1 MB)

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component interface {
	Render(ctx context.Context, wr io.Writer) error
}

type Ctx

type Ctx struct {
	// contains filtered or unexported fields
}

func New

func New(wr http.ResponseWriter, req *http.Request, handlers ...Handler) Ctx

func (Ctx) Accept

func (c Ctx) Accept() string

func (Ctx) AcceptsHTML

func (c Ctx) AcceptsHTML() bool

func (Ctx) AcceptsJSON

func (c Ctx) AcceptsJSON() bool

func (Ctx) AcceptsPlainText

func (c Ctx) AcceptsPlainText() bool

func (Ctx) AddHeader

func (c Ctx) AddHeader(key, value string)

AddHeader appends a value to an existing header (multiple values for same key)

func (Ctx) Context

func (c Ctx) Context() context.Context

Context returns the request context.

func (Ctx) Error

func (c Ctx) Error(code int, message any) servererror.Error

helper to compose an HttpError to be used as error return

func (Ctx) GetCookie

func (c Ctx) GetCookie(name string) string

func (Ctx) GetCurrentAccount

func (c Ctx) GetCurrentAccount() adapter.Account

func (Ctx) GetRequestHeader

func (c Ctx) GetRequestHeader(key string) string

func (Ctx) ID

func (c Ctx) ID() string

func (Ctx) Method

func (c Ctx) Method() string

func (Ctx) Next

func (c Ctx) Next() error

func (Ctx) Param

func (c Ctx) Param(key string) string

func (Ctx) Path

func (c Ctx) Path() string

func (Ctx) Redirect

func (c Ctx) Redirect(code int, url string) error

Redirect sends an HTTP redirect to the given URL with the specified status code. Common codes: http.StatusMovedPermanently (301), http.StatusFound (302), http.StatusSeeOther (303), http.StatusTemporaryRedirect (307).

func (Ctx) Render

func (c Ctx) Render(f Component) error

func (Ctx) SendAttachment

func (c Ctx) SendAttachment(filename string, contents *bytes.Buffer) error

Content-type: filename extension mime type Content-Disposition: attachment; filename="logo.png" Status: http.StatusOK if no prior code is set

func (Ctx) SendHTML

func (c Ctx) SendHTML(s string) error

set content-type as text/html and write the html string set status to http.StatusOK if no prior code is set

func (Ctx) SendJSON

func (c Ctx) SendJSON(obj any) error

set content-type as application/html and write marshalled object as json string set status to http.StatusOK if no prior code is set

func (Ctx) SendString

func (c Ctx) SendString(s string) error

set content-type as text/plain and write the string set status to http.StatusOK if no prior code is set

func (Ctx) Session

func (c Ctx) Session() *session.Session

func (Ctx) SetContentType

func (c Ctx) SetContentType(contentType string)

func (Ctx) SetCookie

func (c Ctx) SetCookie(name, value string, expire time.Duration)

func (Ctx) SetCurrentAccount

func (c Ctx) SetCurrentAccount(a adapter.Account)

func (Ctx) SetHeader

func (c Ctx) SetHeader(key, value string)

func (Ctx) Status

func (c Ctx) Status() int

func (Ctx) Store

func (c Ctx) Store() *store.Service

func (Ctx) URL

func (c Ctx) URL() *url.URL

func (Ctx) UnmarshalAndValidate

func (c Ctx) UnmarshalAndValidate(dest any) error

UnmarshalAndValidate deserializes the JSON request body into dest and runs struct validation using go-playground/validator tags.

func (Ctx) UnmarshalBody

func (c Ctx) UnmarshalBody(dest any) error

UnmarshalBody deserializes the JSON request body into dest, limiting the body size to prevent abuse.

func (Ctx) UserIP

func (c Ctx) UserIP() string

func (Ctx) WithContext

func (c Ctx) WithContext(reqCtx context.Context) Ctx

WithContext returns a copy of Ctx with the request context replaced. Use this for deadlines, cancellation or passing values to downstream handlers.

func (Ctx) WithHeader

func (c Ctx) WithHeader(key, value string) Ctx

func (Ctx) WithStatus

func (c Ctx) WithStatus(code int) Ctx

explicit status code, set it before any write

func (Ctx) Write

func (c Ctx) Write(b []byte) error

type Handler

type Handler func(c Ctx) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL