Documentation
¶
Index ¶
- Variables
- func BadRequestResponse(w http.ResponseWriter, r *http.Request)
- func CreateErrorResponse(w http.ResponseWriter, r *http.Request, err error)
- func DeleteErrorResponse(w http.ResponseWriter, r *http.Request, err error)
- func ForbiddenResponse(w http.ResponseWriter, r *http.Request)
- func GetContextAccount(r *http.Request) (*model.Account, bool)
- func GetContextConfig(r *http.Request) (config.Config, bool)
- func HashUserID(userID, key string) string
- func InternalServerErrorResponse(w http.ResponseWriter, r *http.Request, err error)
- func IsHTMXRequest(r *http.Request) bool
- func ListErrorResponse(w http.ResponseWriter, r *http.Request, err error)
- func NewBaseCookie() http.Cookie
- func NewExpiredCookie(name string) http.Cookie
- func NewPermanentCookie(name, value string, ttl time.Duration) http.Cookie
- func NewSessionCookie(name, value string) http.Cookie
- func NotFoundResponse(w http.ResponseWriter, r *http.Request)
- func PageSizeToLimitOffset(page, size int) (int, int)
- func ReadErrorResponse(w http.ResponseWriter, r *http.Request, err error)
- func Render(w http.ResponseWriter, r *http.Request, code int, render RenderFunc)
- func RenderError(w http.ResponseWriter, r *http.Request, code int, render RenderFunc)
- func SetContextAccount(r *http.Request, account *model.Account) *http.Request
- func SetContextConfig(r *http.Request, conf config.Config) *http.Request
- func TemplateBaseData(r *http.Request, w http.ResponseWriter) layout.BaseData
- func UpdateErrorResponse(w http.ResponseWriter, r *http.Request, err error)
- type RenderFunc
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ( // Permanents cookies. SessionCookieName = "bloggulus_session" SessionCookieTTL = 7 * 24 * time.Hour // Session cookies. NextCookieName = "bloggulus_next" StateCookieName = "bloggulus_state" ToastCookieName = "bloggulus_toast" )
Functions ¶
func BadRequestResponse ¶
func BadRequestResponse(w http.ResponseWriter, r *http.Request)
Render a 400 Bad Request error page.
func CreateErrorResponse ¶ added in v0.4.0
func CreateErrorResponse(w http.ResponseWriter, r *http.Request, err error)
Handle errors that arise from creating a new row in the database.
func DeleteErrorResponse ¶ added in v0.4.0
func DeleteErrorResponse(w http.ResponseWriter, r *http.Request, err error)
Handle errors that arise from deleting a single row from the database.
func ForbiddenResponse ¶ added in v0.3.7
func ForbiddenResponse(w http.ResponseWriter, r *http.Request)
Render a 403 Forbidden error page.
func GetContextAccount ¶ added in v0.4.0
The GetContextAccount() retrieves the model.Account and an "exists" bool from the request context.
func GetContextConfig ¶ added in v0.5.0
func HashUserID ¶ added in v0.5.0
Hash a user ID with a given key (via HMAC).
func InternalServerErrorResponse ¶ added in v0.4.0
func InternalServerErrorResponse(w http.ResponseWriter, r *http.Request, err error)
Render a 500 Internal Server Error page.
func IsHTMXRequest ¶ added in v0.4.0
func ListErrorResponse ¶ added in v0.4.0
func ListErrorResponse(w http.ResponseWriter, r *http.Request, err error)
Handle errors that arise from reading many (zero or more) rows from the database.
func NewBaseCookie ¶ added in v0.4.0
Return a base cookie with secure defaults.
func NewExpiredCookie ¶ added in v0.4.0
Create a cookie that is instantly expired.
func NewPermanentCookie ¶ added in v0.4.0
Create a permanent (not session) cookie with a given time-to-live.
func NewSessionCookie ¶ added in v0.4.0
Create a session (not permanent) cookie that expires when the user's session ends.
func NotFoundResponse ¶
func NotFoundResponse(w http.ResponseWriter, r *http.Request)
Render a 404 Not Found error page.
func PageSizeToLimitOffset ¶
Convert user-friendly "page/size" pagination to DB-friendly "limit/offset".
func ReadErrorResponse ¶ added in v0.4.0
func ReadErrorResponse(w http.ResponseWriter, r *http.Request, err error)
Handle errors that arise from reading a single row from the database.
func Render ¶ added in v0.4.0
func Render(w http.ResponseWriter, r *http.Request, code int, render RenderFunc)
Render an HTML template based on a given RenderFunc.
func RenderError ¶ added in v0.4.0
func RenderError(w http.ResponseWriter, r *http.Request, code int, render RenderFunc)
Render an HTML error template based on a given RenderFunc. This function differs from Render in that it doesn't call InternalServerErrorResponse if something goes wrong since that could cause an infinite recursion.
func SetContextAccount ¶ added in v0.4.0
The SetContextAccount() method returns a new copy of the request with the provided model.Account added to the context. Note that we use our accountContextKey constant as the key.
func SetContextConfig ¶ added in v0.5.0
func TemplateBaseData ¶ added in v0.4.0
func UpdateErrorResponse ¶ added in v0.4.0
func UpdateErrorResponse(w http.ResponseWriter, r *http.Request, err error)
Handle errors that arise from updating a single row in the database.
Types ¶
type RenderFunc ¶ added in v0.4.0
Generic function type for rendering data to an io.Writer.
type Validator ¶ added in v0.4.0
func NewValidator ¶ added in v0.4.0
func NewValidator() Validator