hh

package module
v0.0.0-...-87c1b77 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(message string) error

BadRequest returns an error that will respond with HTTP 400 Bad Request.

func ConvertToInt

func ConvertToInt(value string) (int, error)

func ConvertToPtrUrlURL

func ConvertToPtrUrlURL(value string) (*url.URL, error)

func ConvertToString

func ConvertToString(value string) (string, error)

func ConvertToUuidUUID

func ConvertToUuidUUID(value string) (uuid.UUID, error)

func ExtractFromCookie

func ExtractFromCookie(r *http.Request, name string) (string, bool)

func ExtractFromFile

func ExtractFromFile(r *http.Request, name string) (*multipart.FileHeader, bool)

func ExtractFromForm

func ExtractFromForm(r *http.Request, name string) (string, bool)

func ExtractFromHeader

func ExtractFromHeader(r *http.Request, name string) (string, bool)

func ExtractFromPath

func ExtractFromPath(r *http.Request, name string) (string, bool)

func Forbidden

func Forbidden(message string) error

Forbidden returns an error that will respond with HTTP 403 Forbidden.

func NotFound

func NotFound() error

NotFound returns an error that will respond with HTTP 404 Not Found.

func RespondError

func RespondError(err error, w http.ResponseWriter, r *http.Request)

RespondError writes an error response to the client. If the error is an HttpError, it uses the specified status code and message. Otherwise, it logs the error and returns a generic 500 Internal Server Error with a unique ID.

func Unauthorized

func Unauthorized() error

Unauthorized returns an error that will respond with HTTP 401 Unauthorized.

Types

type HandlerValue

type HandlerValue struct{ http.Handler }

func Handler

func Handler(h http.Handler) HandlerValue

Handler wraps an http.Handler so it can be returned from hh route handlers. The wrapped handler will process the request further when Respond is called.

func (HandlerValue) Respond

func (h HandlerValue) Respond(w http.ResponseWriter, r *http.Request)

type HttpError

type HttpError struct {
	Message    string
	StatusCode int
}

HttpError represents an HTTP error with a status code and message.

func (HttpError) Error

func (h HttpError) Error() string

type JSONValue

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

func JSON

func JSON(a any) JSONValue

func (JSONValue) Respond

func (j JSONValue) Respond(w http.ResponseWriter, r *http.Request)

type ToResponse

type ToResponse interface {
	Respond(w http.ResponseWriter, r *http.Request)
}

Source Files

  • converters.go
  • errors.go
  • extractors.go
  • response.go

Directories

Path Synopsis
cmd
generate command

Jump to

Keyboard shortcuts

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