Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultErrorMiddleware(ctx *Ctx) error
- func GetAuth[authType any](ctx *Ctx) authType
- type App
- func (a *App) Listen(port string) error
- func (a *App) PrintRoutes()
- func (a *App) Protected() *App
- func (a *App) Router(relativePath string) *Router
- func (a *App) Shutdown()
- func (a *App) Static(prefix, root string, config ...*Static)
- func (a *App) Test(req *http.Request, port ...string) (*http.Response, error)
- func (a *App) Use(middleware Handler) *App
- type AuthHandler
- type Authorizer
- type Config
- type Ctx
- func (c *Ctx) Attachment(filename ...string)
- func (c *Ctx) Get(key string) string
- func (c *Ctx) GetCookie(key string) (*http.Cookie, error)
- func (c *Ctx) GetCookies() []*http.Cookie
- func (c *Ctx) GetReqHeaders() map[string][]string
- func (c *Ctx) GetRespHeaders() map[string][]string
- func (c *Ctx) Hostname() string
- func (c *Ctx) IP() string
- func (c *Ctx) Links(link ...string)
- func (c *Ctx) Method(override ...string) string
- func (c *Ctx) Next() error
- func (c *Ctx) Path(override ...string) string
- func (c *Ctx) Protocol() string
- func (c *Ctx) SendString(str string) error
- func (c *Ctx) Set(key, value string)
- func (c *Ctx) SetCookie(cookie *http.Cookie)
- type DefaultResError
- type Error
- type ErrorResponse
- type Handler
- type Header
- type Map
- type Method
- type Mutation
- type Procedure
- func (p *Procedure[query, input, output]) AcceptedContentType(contentTypes ...string)
- func (proc *Procedure[query, input, output]) Attach(route Route, slug string)
- func (p *Procedure[query, input, output]) Authorizer(a *Authorizer) *Procedure[query, input, output]
- func (p *Procedure[query, input, output]) Protected() *Procedure[query, input, output]
- func (p *Procedure[query, input, output]) Validator(fn validatorFn) *Procedure[query, input, output]
- type ProcedureInfo
- type Query
- type Res
- type Route
- type Router
- func (router *Router) Authorizer(a *Authorizer) *Router
- func (r *Router) PrintInfo()
- func (router *Router) Protected() *Router
- func (r *Router) Router(slug string) *Router
- func (r *Router) Static(prefix, root string, config ...*Static)
- func (r *Router) Use(middlewares ...Handler)
- func (r *Router) Validator(fn validatorFn)
- type Static
Constants ¶
const ( TextXML = "text/xml" TextHTML = "text/html" TextPlain = "text/plain" ApplicationXML = "application/xml" ApplicationJSON = "application/json" ApplicationJavaScript = "application/javascript" ApplicationForm = "application/x-www-form-urlencoded" OctetStream = "application/octet-stream" MultipartForm = "multipart/form-data" TextXMLCharsetUTF8 = "text/xml; charset=utf-8" TextHTMLCharsetUTF8 = "text/html; charset=utf-8" TextPlainCharsetUTF8 = "text/plain; charset=utf-8" ApplicationXMLCharsetUTF8 = "application/xml; charset=utf-8" ApplicationJSONCharsetUTF8 = "application/json; charset=utf-8" ApplicationJavaScriptCharsetUTF8 = "application/javascript; charset=utf-8" )
copied from fiber https://docs.gofiber.io/api/constants
Variables ¶
var DefaultColors = struct { Red string Green string Reset string }{ Red: "\x1b[31m", Green: "\x1b[32m", Reset: "\x1b[0m", }
DefaultColors contains ANSI escape codes for default colors.
Functions ¶
func DefaultErrorMiddleware ¶
Simple middleware that always returns json
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
func (*App) PrintRoutes ¶
func (a *App) PrintRoutes()
type AuthHandler ¶
type Authorizer ¶
type Authorizer struct {
Handler AuthHandler
}
Struct that handles all of the settings related to authorizing for routes and procedures
func NewAuth ¶
func NewAuth(handler AuthHandler) *Authorizer
Creates a new authorizer struct with the defaults set
type Config ¶
type Config struct { //Authorizer is the default authorization middleware that your app will use. Whenever you make some procedure protected this function will be used to authorize your user to proceed. //You will then be able to call .Auth() on your handler's context and unmarshal whatever you returned first from this function into some variable Authorizer *Authorizer // The path where you would like the generated Typescript to be placed. // Keep in mind that YOU NEED TO PUT a .ts file at the end of the path // Default is ./output.ts OutputPath string // Boolean that determines if any typescript types will be generated. // Default is false. Set this to TRUE in production DisableGenerateTS bool //The function that will be used to validate your struct fields. ValidatorFn validatorFn //Disables the fiber logger middleware that is added. //False by default. Set this to TRUE in production DisableRequestLogging bool // by default Bluerpc transforms every error that is sent to the user into a json by the format ErrorResponse. Turn this to true if you would like fiber to handle what form will the errors have or write your own middleware to convert all of the errors to your liking DisableJSONOnlyErrors bool //This middleware catches all of the errors of every procedure and handles responding in a proper way //By default it is DefaultErrorMiddleware ErrorMiddleware Handler //the URL of the server. If left empty it will be interpreted as localhost ServerURL string //disable the printing of that start server message DisableInfoPrinting bool //determines the default cors origin for every request that comes in CORS_Origin string //The address that your SSL certificate is located at SSLCertPath string //The address that your SSL key is located at SSLKey string // Puts all of the needed Pprof routes in. Read more about pprof here // https://pkg.go.dev/net/http/pprof EnablePProf bool }
type Ctx ¶
type Ctx struct { // This session field can be used in your middlewares for you to store any data that you would need to pass on to your handlers Session any // contains filtered or unexported fields }
func (*Ctx) Attachment ¶
Attachment sets the Content-Disposition header to make the response an attachment. If a filename is provided, it includes it in the header.
func (*Ctx) Get ¶
/ This calls the Get method on the http Request to get a value from the header depending on a given key
func (*Ctx) GetCookies ¶ added in v0.7.7
returns an array of all of the cookies on the REQUEST object
func (*Ctx) GetReqHeaders ¶
GetReqHeaders returns a map of all request headers.
func (*Ctx) GetRespHeaders ¶
GetRespHeaders returns a COPY map of all response headers.
func (*Ctx) SendString ¶
type DefaultResError ¶
type DefaultResError struct {
Message string `json:"message"`
}
type ErrorResponse ¶
type ErrorResponse struct {
Message string `json:"message"`
}
type Header ¶
type Header struct { Status int Authorization string // Credentials for authenticating the client to the server CacheControl string // Directives for caching mechanisms in both requests and responses ContentEncoding string // The encoding of the body ContentType string // The MIME type of the body of the request (used with POST and PUT requests) Expires string // Gives the date/time after which the response is considered stale Cookies []*http.Cookie //Cookies }
type Mutation ¶
type Mutation[query any, input any, output any] func(ctx *Ctx, query query, input input) (*Res[output], error)
First Generic argument is QUERY PARAMETERS. Second is INPUT. Third is OUTPUT.
type Procedure ¶
type Procedure[query any, input any, output any] struct { // contains filtered or unexported fields }
func NewMutation ¶
func NewMutation[query any, input any, output any](app *App, mutation Mutation[query, input, output]) *Procedure[query, input, output]
Creates a new query procedure that can be attached to groups / app root. The generic arguments specify the structure for validating query parameters (the query Params, the body of the request and the resulting handler output). Use any to avoid validation
func NewQuery ¶
func NewQuery[query any, output any](app *App, queryFn Query[query, output]) *Procedure[query, any, output]
Creates a new query procedure that can be attached to groups / app root. The generic arguments specify the structure for validating query parameters (the query Params and the resulting handler output). Use any to avoid validation
func (*Procedure[query, input, output]) AcceptedContentType ¶
determines which content type should a request have in order for it to be valid.
func (*Procedure[query, input, output]) Authorizer ¶
func (p *Procedure[query, input, output]) Authorizer(a *Authorizer) *Procedure[query, input, output]
type ProcedureInfo ¶
type ProcedureInfo struct {
// contains filtered or unexported fields
}
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func (*Router) Authorizer ¶
func (router *Router) Authorizer(a *Authorizer) *Router
func (*Router) PrintInfo ¶
func (r *Router) PrintInfo()
prints all of the info for this route, including its procedures attached and all of its nested routes
func (*Router) Router ¶
Creates a new route or returns an existing one if that route was already created
type Static ¶
type Static struct { // When set to true, enables direct download. // Optional. Default value false. Download bool `json:"download"` // The name of the index file for serving a directory. // Optional. Default value "index.html". Index string `json:"index"` // Expiration duration for inactive file handlers. // Use a negative time.Duration to disable it. // // Optional. Default value 10 * time.Second. CacheDuration time.Duration `json:"cache_duration"` // The value for the Cache-Control HTTP-header // that is set on the file response. MaxAge is defined in seconds. // // Optional. Default value 0. MaxAge int `json:"max_age"` // Next defines a function to skip this middleware when returned true. // // Optional. Default: nil Next func(c *Ctx) bool }