Documentation ¶
Index ¶
- func Prefix(path string) string
- type API
- type APIListener
- type Controller
- type ErrorHandler
- type MalformedRequestContext
- type Param
- type Params
- type ParseError
- type Push
- type RequestBody
- type RequestContext
- func (c RequestContext) AddCookie(cookie *http.Cookie)
- func (c RequestContext) Cookie(name string) (*http.Cookie, error)
- func (c RequestContext) Cookies() []*http.Cookie
- func (c RequestContext) GetPathParam(name string) (string, bool)
- func (c RequestContext) GetQueries(name string) []string
- func (c RequestContext) GetQuery(name string) (string, bool)
- func (c RequestContext) MustGetPathParam(name string) string
- func (c RequestContext) MustGetQuery(name string) string
- type RequestListener
- type ResponseEntity
- type ResponseListener
- type Route
- func DELETE(path string, api API) Route
- func GET(path string, api API) Route
- func Handle(method string, path string, api API) Route
- func OPTIONS(path string, api API) Route
- func PATCH(path string, api API) Route
- func POST(path string, api API) Route
- func PUT(path string, api API) Route
- func StaticDir(pattern string, dir string) Route
- type RouteCreationStage
- func OnDelete(path string) RouteCreationStage
- func OnGET(path string) RouteCreationStage
- func OnOptions(path string) RouteCreationStage
- func OnPOST(path string) RouteCreationStage
- func OnPUT(path string) RouteCreationStage
- func OnPatch(path string) RouteCreationStage
- func OnPath(path string) RouteCreationStage
- type Server
- func (server *Server) AddAPIListeners(listeners ...APIListener)
- func (server *Server) AddRequestListeners(listeners ...RequestListener)
- func (server *Server) AddResponseListeners(listeners ...ResponseListener)
- func (server *Server) AddRoutes(routes ...Route)
- func (server *Server) NotFoundAction(action API)
- func (server *Server) Register(controllers ...*Controller)
- func (server *Server) SetErrorHandler(action ErrorHandler)
- func (server *Server) Start() error
- type Status
- func BadRequest(body ResponseEntity) Status
- func CreateResponse(statusCode int, body ResponseEntity) Status
- func Created(body ResponseEntity) Status
- func Dir(fs string) Status
- func File(path string) Status
- func Forbidden(body ResponseEntity) Status
- func Found(location string) Status
- func InternalServerError(body ResponseEntity) Status
- func MethodNotAllowed(body ResponseEntity) Status
- func MovedPermanently(location string) Status
- func NotFound(body ResponseEntity) Status
- func Ok(body ResponseEntity) Status
- func PermanentRedirect(location string) Status
- func Unauthorized(body ResponseEntity) Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type API ¶
type API = func(c RequestContext) Status
type APIListener ¶ added in v0.2.3
type APIListener = func(RequestContext, Status)
var WatchAPIs APIListener = func(request RequestContext, status Status) { now := time.Now() difference := fmt.Sprint(now.Sub(request.receivedAt)) statusString := fmt.Sprintf("%v%d%v", getColor(status.StatusCode), status.StatusCode, colored.ResetPrevColor) _ = stginLogger.InfoF("%v -> %v\t\t| %v | %v", request.Method, request.Url, statusString, difference) }
type Controller ¶
type Controller struct { Name string // contains filtered or unexported fields }
func NewController ¶
func NewController(name string, prefix string) *Controller
func (*Controller) AddAPIListeners ¶ added in v0.2.3
func (controller *Controller) AddAPIListeners(listeners ...APIListener)
func (*Controller) AddRequestListeners ¶
func (controller *Controller) AddRequestListeners(listeners ...RequestListener)
func (*Controller) AddResponseListener ¶
func (controller *Controller) AddResponseListener(listeners ...ResponseListener)
func (*Controller) AddRoutes ¶
func (controller *Controller) AddRoutes(routes ...Route)
type ErrorHandler ¶ added in v0.2.4
type ErrorHandler = func(request RequestContext, err any) Status
type MalformedRequestContext ¶ added in v0.2.5
type MalformedRequestContext struct {
// contains filtered or unexported fields
}
func (MalformedRequestContext) Error ¶ added in v0.2.5
func (mrc MalformedRequestContext) Error() string
type ParseError ¶ added in v0.2.5
type ParseError struct {
// contains filtered or unexported fields
}
func (ParseError) Error ¶ added in v0.2.5
func (ije ParseError) Error() string
type Push ¶ added in v0.4.5
type Push struct { IsSupported bool // contains filtered or unexported fields }
type RequestBody ¶
type RequestBody struct {
// contains filtered or unexported fields
}
func (*RequestBody) JSONInto ¶ added in v0.2.5
func (body *RequestBody) JSONInto(a any)
func (*RequestBody) SafeJSONInto ¶ added in v0.2.5
func (body *RequestBody) SafeJSONInto(a any) error
func (*RequestBody) SafeXMLInto ¶ added in v0.2.5
func (body *RequestBody) SafeXMLInto(a any) error
func (*RequestBody) XMLInto ¶ added in v0.2.5
func (body *RequestBody) XMLInto(a any)
type RequestContext ¶
type RequestContext struct { Url string QueryParams map[string][]string PathParams Params Headers http.Header Body *RequestBody Method string ContentLength int64 Host string MultipartForm func() *multipart.Form Scheme string RemoteAddr string HttpPush Push // contains filtered or unexported fields }
func (RequestContext) AddCookie ¶ added in v0.4.1
func (c RequestContext) AddCookie(cookie *http.Cookie)
func (RequestContext) Cookie ¶ added in v0.4.1
func (c RequestContext) Cookie(name string) (*http.Cookie, error)
func (RequestContext) Cookies ¶ added in v0.4.1
func (c RequestContext) Cookies() []*http.Cookie
func (RequestContext) GetPathParam ¶
func (c RequestContext) GetPathParam(name string) (string, bool)
func (RequestContext) GetQueries ¶
func (c RequestContext) GetQueries(name string) []string
func (RequestContext) MustGetPathParam ¶ added in v0.3.2
func (c RequestContext) MustGetPathParam(name string) string
func (RequestContext) MustGetQuery ¶ added in v0.5.3
func (c RequestContext) MustGetQuery(name string) string
type RequestListener ¶
type RequestListener = func(RequestContext) RequestContext
type ResponseEntity ¶ added in v0.4.1
func Json ¶ added in v0.4.1
func Json(a any) ResponseEntity
func Text ¶ added in v0.4.1
func Text(text string) ResponseEntity
func Xml ¶ added in v0.4.1
func Xml(a any) ResponseEntity
type ResponseListener ¶
type Route ¶
type RouteCreationStage ¶
type RouteCreationStage struct {
// contains filtered or unexported fields
}
func OnDelete ¶
func OnDelete(path string) RouteCreationStage
func OnGET ¶
func OnGET(path string) RouteCreationStage
func OnOptions ¶ added in v0.2.2
func OnOptions(path string) RouteCreationStage
func OnPOST ¶
func OnPOST(path string) RouteCreationStage
func OnPUT ¶
func OnPUT(path string) RouteCreationStage
func OnPatch ¶
func OnPatch(path string) RouteCreationStage
func OnPath ¶
func OnPath(path string) RouteCreationStage
func (RouteCreationStage) Do ¶
func (stage RouteCreationStage) Do(api API) Route
func (RouteCreationStage) WithMethod ¶
func (stage RouteCreationStage) WithMethod(method string) RouteCreationStage
type Server ¶
type Server struct { Controllers []*Controller // contains filtered or unexported fields }
func DefaultServer ¶ added in v0.4.1
func (*Server) AddAPIListeners ¶ added in v0.2.3
func (server *Server) AddAPIListeners(listeners ...APIListener)
func (*Server) AddRequestListeners ¶
func (server *Server) AddRequestListeners(listeners ...RequestListener)
func (*Server) AddResponseListeners ¶
func (server *Server) AddResponseListeners(listeners ...ResponseListener)
func (*Server) NotFoundAction ¶ added in v0.2.2
func (*Server) Register ¶
func (server *Server) Register(controllers ...*Controller)
func (*Server) SetErrorHandler ¶ added in v0.2.5
func (server *Server) SetErrorHandler(action ErrorHandler)
type Status ¶
type Status struct { StatusCode int Entity ResponseEntity Headers http.Header // contains filtered or unexported fields }
func BadRequest ¶
func BadRequest(body ResponseEntity) Status
func CreateResponse ¶
func CreateResponse(statusCode int, body ResponseEntity) Status
func Created ¶
func Created(body ResponseEntity) Status
func Forbidden ¶
func Forbidden(body ResponseEntity) Status
func InternalServerError ¶
func InternalServerError(body ResponseEntity) Status
func MethodNotAllowed ¶ added in v0.2.2
func MethodNotAllowed(body ResponseEntity) Status
func MovedPermanently ¶
func NotFound ¶
func NotFound(body ResponseEntity) Status
func Ok ¶
func Ok(body ResponseEntity) Status
func PermanentRedirect ¶
func Unauthorized ¶
func Unauthorized(body ResponseEntity) Status
func (Status) WithCookies ¶ added in v0.4.1
Source Files ¶
Click to show internal directories.
Click to hide internal directories.