fiber

package module
v0.0.0-...-3dda34e Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2025 License: MIT Imports: 45 Imported by: 0

README

Fiber

Doc Go Release Test Report Card Codecov License

Fiber http driver for Goravel.

Version

goravel/fiber goravel/framework
v1.3.x v1.15.x
v1.2.x v1.14.x
v1.1.x v1.13.x

Install

  1. Add package
go get -u github.com/neatethnicity/fiber
  1. Register service provider
// config/app.go
import "github.com/neatethnicity/fiber"

"providers": []foundation.ServiceProvider{
    ...
    &fiber.ServiceProvider{},
}
  1. Add fiber config to config/http.go file
// config/http.go
import (
    fiberfacades "github.com/neatethnicity/fiber/facades"
    "github.com/goravel/framework/support/path"
    "github.com/gofiber/template/html/v2"
    "github.com/gofiber/fiber/v2"
)

"default": "fiber",

"drivers": map[string]any{
    "fiber": map[string]any{
        // immutable mode, see https://docs.gofiber.io/#zero-allocation
        // WARNING: This option is dangerous. Only change it if you fully understand the potential consequences.
        "immutable": true,
        // prefork mode, see https://docs.gofiber.io/api/fiber/#config
        "prefork": false,
        // Optional, default is 4096 KB
        "body_limit": 4096,
        "header_limit": 4096,
        "route": func() (route.Route, error) {
            return fiberfacades.Route("fiber"), nil
        },
        // Optional, default is "html/template"
        "template": func() (fiber.Views, error) {
            return html.New(path.Resource("views"), ".tmpl"), nil
        },
    },
},

Testing

Run command below to run test:

go test ./...

Documentation

Index

Constants

View Source
const RouteBinding = "goravel.fiber.route"

Variables

View Source
var (
	App              foundation.Application
	ConfigFacade     config.Config
	LogFacade        log.Log
	ValidationFacade validation.Validation
	ViewFacade       http.View
)

Functions

func Background

func Background() http.Context

func Cors

func Cors() http.Middleware

func NewContextRequest

func NewContextRequest(ctx *Context, log log.Log, validation contractsvalidate.Validation) contractshttp.ContextRequest

func NewContextResponse

func NewContextResponse(instance *fiber.Ctx, origin contractshttp.ResponseOrigin) contractshttp.ContextResponse

func NewGroup

func NewGroup(config config.Config, instance *fiber.App, prefix string, originMiddlewares []httpcontract.Middleware, lastMiddlewares []httpcontract.Middleware) route.Router

func NewStatus

func NewStatus(instance *fiber.Ctx, code int) contractshttp.ResponseStatus

func ResponseMiddleware

func ResponseMiddleware() contractshttp.Middleware

func Timeout

func Timeout(timeout time.Duration) contractshttp.Middleware

Timeout creates middleware to set a timeout for a request. NOTICE: It does not cancel long running executions. Underlying executions must handle timeout by using context.Context parameter. For details, see https://github.com/valyala/fasthttp/issues/965

Types

type Context

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

func NewContext

func NewContext(c *fiber.Ctx) *Context

func (*Context) Context

func (c *Context) Context() context.Context

func (*Context) Deadline

func (c *Context) Deadline() (deadline time.Time, ok bool)

func (*Context) Done

func (c *Context) Done() <-chan struct{}

func (*Context) Err

func (c *Context) Err() error

func (*Context) Instance

func (c *Context) Instance() *fiber.Ctx

func (*Context) Request

func (c *Context) Request() http.ContextRequest

func (*Context) Response

func (c *Context) Response() http.ContextResponse

func (*Context) Value

func (c *Context) Value(key any) any

func (*Context) WithContext

func (c *Context) WithContext(ctx context.Context)

func (*Context) WithValue

func (c *Context) WithValue(key any, value any)

type ContextRequest

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

func (*ContextRequest) Abort

func (r *ContextRequest) Abort(code ...int)

func (*ContextRequest) AbortWithStatus

func (r *ContextRequest) AbortWithStatus(code int)

DEPRECATED: Use Abort instead

func (*ContextRequest) AbortWithStatusJson

func (r *ContextRequest) AbortWithStatusJson(code int, jsonObj any)

DEPRECATED: Use Response().Json().Abort() instead

func (*ContextRequest) All

func (r *ContextRequest) All() map[string]any

func (*ContextRequest) Bind

func (r *ContextRequest) Bind(obj any) error

func (*ContextRequest) BindQuery

func (r *ContextRequest) BindQuery(obj any) error

func (*ContextRequest) Cookie

func (r *ContextRequest) Cookie(key string, defaultValue ...string) string

func (*ContextRequest) File

func (*ContextRequest) Files

func (r *ContextRequest) Files(name string) ([]contractsfilesystem.File, error)

func (*ContextRequest) Form

func (r *ContextRequest) Form(key string, defaultValue ...string) string

func (*ContextRequest) FullUrl

func (r *ContextRequest) FullUrl() string

func (*ContextRequest) HasSession

func (r *ContextRequest) HasSession() bool

func (*ContextRequest) Header

func (r *ContextRequest) Header(key string, defaultValue ...string) string

func (*ContextRequest) Headers

func (r *ContextRequest) Headers() http.Header

func (*ContextRequest) Host

func (r *ContextRequest) Host() string

func (*ContextRequest) Input

func (r *ContextRequest) Input(key string, defaultValue ...string) string

func (*ContextRequest) InputArray

func (r *ContextRequest) InputArray(key string, defaultValue ...[]string) []string

func (*ContextRequest) InputBool

func (r *ContextRequest) InputBool(key string, defaultValue ...bool) bool

func (*ContextRequest) InputInt

func (r *ContextRequest) InputInt(key string, defaultValue ...int) int

func (*ContextRequest) InputInt64

func (r *ContextRequest) InputInt64(key string, defaultValue ...int64) int64

func (*ContextRequest) InputMap

func (r *ContextRequest) InputMap(key string, defaultValue ...map[string]any) map[string]any

func (*ContextRequest) InputMapArray

func (r *ContextRequest) InputMapArray(key string, defaultValue ...[]map[string]any) []map[string]any

func (*ContextRequest) Ip

func (r *ContextRequest) Ip() string

func (*ContextRequest) Json

func (r *ContextRequest) Json(key string, defaultValue ...string) string

func (*ContextRequest) Method

func (r *ContextRequest) Method() string

func (*ContextRequest) Next

func (r *ContextRequest) Next()

func (*ContextRequest) Origin

func (r *ContextRequest) Origin() *http.Request

func (*ContextRequest) Path

func (r *ContextRequest) Path() string

func (*ContextRequest) Queries

func (r *ContextRequest) Queries() map[string]string

func (*ContextRequest) Query

func (r *ContextRequest) Query(key string, defaultValue ...string) string

func (*ContextRequest) QueryArray

func (r *ContextRequest) QueryArray(key string) []string

func (*ContextRequest) QueryBool

func (r *ContextRequest) QueryBool(key string, defaultValue ...bool) bool

func (*ContextRequest) QueryInt

func (r *ContextRequest) QueryInt(key string, defaultValue ...int) int

func (*ContextRequest) QueryInt64

func (r *ContextRequest) QueryInt64(key string, defaultValue ...int64) int64

func (*ContextRequest) QueryMap

func (r *ContextRequest) QueryMap(key string) map[string]string

func (*ContextRequest) Route

func (r *ContextRequest) Route(key string) string

func (*ContextRequest) RouteInt

func (r *ContextRequest) RouteInt(key string) int

func (*ContextRequest) RouteInt64

func (r *ContextRequest) RouteInt64(key string) int64

func (*ContextRequest) Session

func (r *ContextRequest) Session() contractsession.Session

func (*ContextRequest) SetSession

func (*ContextRequest) Url

func (r *ContextRequest) Url() string

func (*ContextRequest) Validate

func (r *ContextRequest) Validate(rules map[string]string, options ...contractsvalidate.Option) (contractsvalidate.Validator, error)

func (*ContextRequest) ValidateRequest

func (r *ContextRequest) ValidateRequest(request contractshttp.FormRequest) (contractsvalidate.Errors, error)

type ContextResponse

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

func (*ContextResponse) Cookie

func (*ContextResponse) Data

func (r *ContextResponse) Data(code int, contentType string, data []byte) contractshttp.AbortableResponse

func (*ContextResponse) Download

func (r *ContextResponse) Download(filepath, filename string) contractshttp.Response

func (*ContextResponse) File

func (r *ContextResponse) File(filepath string) contractshttp.Response

func (*ContextResponse) Flush

func (r *ContextResponse) Flush()

func (*ContextResponse) Header

func (r *ContextResponse) Header(key, value string) contractshttp.ContextResponse

func (*ContextResponse) Json

func (*ContextResponse) NoContent

func (r *ContextResponse) NoContent(code ...int) contractshttp.AbortableResponse

func (*ContextResponse) Origin

func (*ContextResponse) Redirect

func (r *ContextResponse) Redirect(code int, location string) contractshttp.AbortableResponse

func (*ContextResponse) Status

func (*ContextResponse) Stream

func (*ContextResponse) String

func (r *ContextResponse) String(code int, format string, values ...any) contractshttp.AbortableResponse

func (*ContextResponse) Success

func (*ContextResponse) View

func (*ContextResponse) WithoutCookie

func (r *ContextResponse) WithoutCookie(name string) contractshttp.ContextResponse

func (*ContextResponse) Writer

func (r *ContextResponse) Writer() http.ResponseWriter

type DataResponse

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

func (*DataResponse) Abort

func (r *DataResponse) Abort() error

func (*DataResponse) Render

func (r *DataResponse) Render() error

type DownloadResponse

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

func (*DownloadResponse) Render

func (r *DownloadResponse) Render() error

type FileResponse

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

func (*FileResponse) Render

func (r *FileResponse) Render() error

type Group

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

func (*Group) Any

func (r *Group) Any(relativePath string, handler httpcontract.HandlerFunc)

func (*Group) Delete

func (r *Group) Delete(relativePath string, handler httpcontract.HandlerFunc)

func (*Group) Get

func (r *Group) Get(relativePath string, handler httpcontract.HandlerFunc)

func (*Group) Group

func (r *Group) Group(handler route.GroupFunc)

func (*Group) Middleware

func (r *Group) Middleware(middlewares ...httpcontract.Middleware) route.Router

func (*Group) Options

func (r *Group) Options(relativePath string, handler httpcontract.HandlerFunc)

func (*Group) Patch

func (r *Group) Patch(relativePath string, handler httpcontract.HandlerFunc)

func (*Group) Post

func (r *Group) Post(relativePath string, handler httpcontract.HandlerFunc)

func (*Group) Prefix

func (r *Group) Prefix(addr string) route.Router

func (*Group) Put

func (r *Group) Put(relativePath string, handler httpcontract.HandlerFunc)

func (*Group) Resource

func (r *Group) Resource(relativePath string, controller httpcontract.ResourceController)

func (*Group) Static

func (r *Group) Static(relativePath, root string)

func (*Group) StaticFS

func (r *Group) StaticFS(relativePath string, fs http.FileSystem)

func (*Group) StaticFile

func (r *Group) StaticFile(relativePath, filePath string)

type HtmlResponse

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

func (*HtmlResponse) Render

func (r *HtmlResponse) Render() error

type JsonResponse

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

func (*JsonResponse) Abort

func (r *JsonResponse) Abort() error

func (*JsonResponse) Render

func (r *JsonResponse) Render() error

type NoContentResponse

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

func (*NoContentResponse) Abort

func (r *NoContentResponse) Abort() error

func (*NoContentResponse) Render

func (r *NoContentResponse) Render() error

type RedirectResponse

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

func (*RedirectResponse) Abort

func (r *RedirectResponse) Abort() error

func (*RedirectResponse) Render

func (r *RedirectResponse) Render() error

type ResponseOrigin

type ResponseOrigin struct {
	*fiber.Ctx
}

func (*ResponseOrigin) Body

func (w *ResponseOrigin) Body() *bytes.Buffer

func (*ResponseOrigin) Header

func (w *ResponseOrigin) Header() http.Header

func (*ResponseOrigin) Size

func (w *ResponseOrigin) Size() int

func (*ResponseOrigin) Status

func (w *ResponseOrigin) Status() int

type Route

type Route struct {
	route.Router
	// contains filtered or unexported fields
}

Route fiber route Route fiber 路由

func NewRoute

func NewRoute(config config.Config, parameters map[string]any) (*Route, error)

NewRoute create new fiber route instance NewRoute 创建新的 fiber 路由实例

func (*Route) Fallback

func (r *Route) Fallback(handler contractshttp.HandlerFunc)

Fallback set fallback handler Fallback 设置回退处理程序

func (*Route) GlobalMiddleware

func (r *Route) GlobalMiddleware(middlewares ...contractshttp.Middleware)

GlobalMiddleware set global middleware GlobalMiddleware 设置全局中间件

func (*Route) Listen

func (r *Route) Listen(l net.Listener) error

Listen listen server Listen 监听服务器

func (*Route) ListenTLS

func (r *Route) ListenTLS(l net.Listener) error

ListenTLS listen TLS server ListenTLS 监听 TLS 服务器

func (*Route) ListenTLSWithCert

func (r *Route) ListenTLSWithCert(l net.Listener, certFile, keyFile string) error

ListenTLSWithCert listen TLS server with cert file and key file ListenTLSWithCert 使用证书文件和密钥文件监听 TLS 服务器

func (*Route) Recover

func (r *Route) Recover(callback func(ctx contractshttp.Context, err any))

func (*Route) Run

func (r *Route) Run(host ...string) error

Run run server Run 运行服务器

func (*Route) RunTLS

func (r *Route) RunTLS(host ...string) error

RunTLS run TLS server RunTLS 运行 TLS 服务器

func (*Route) RunTLSWithCert

func (r *Route) RunTLSWithCert(host, certFile, keyFile string) error

RunTLSWithCert run TLS server with cert file and key file RunTLSWithCert 使用证书文件和密钥文件运行 TLS 服务器

func (*Route) ServeHTTP

func (r *Route) ServeHTTP(writer http.ResponseWriter, request *http.Request)

ServeHTTP serve http request (Not support) ServeHTTP 服务 HTTP 请求 (不支持)

func (*Route) Shutdown

func (r *Route) Shutdown(ctx ...context.Context) error

Shutdown gracefully shuts down the server Shutdown 优雅退出HTTP Server

func (*Route) Test

func (r *Route) Test(request *http.Request) (*http.Response, error)

Test for unit test Test 用于单元测试

type ServiceProvider

type ServiceProvider struct{}

func (*ServiceProvider) Boot

func (receiver *ServiceProvider) Boot(app foundation.Application)

func (*ServiceProvider) Register

func (receiver *ServiceProvider) Register(app foundation.Application)

type Status

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

func (*Status) Data

func (r *Status) Data(contentType string, data []byte) contractshttp.AbortableResponse

func (*Status) Json

func (*Status) Stream

func (r *Status) Stream(step func(w contractshttp.StreamWriter) error) contractshttp.Response

func (*Status) String

func (r *Status) String(format string, values ...any) contractshttp.AbortableResponse

type StreamResponse

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

func (*StreamResponse) Render

func (r *StreamResponse) Render() (err error)

type StringResponse

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

func (*StringResponse) Abort

func (r *StringResponse) Abort() error

func (*StringResponse) Render

func (r *StringResponse) Render() error

type View

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

func NewView

func NewView(instance *fiber.Ctx) *View

func (*View) First

func (receive *View) First(views []string, data ...any) contractshttp.Response

func (*View) Make

func (receive *View) Make(view string, data ...any) contractshttp.Response

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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