fiber

package module
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2023 License: MIT Imports: 29 Imported by: 0

README

Fiber

Doc Go Release Test Report Card Codecov License

Fiber http driver for Goravel.

Version

goravel/fiber goravel/framework
v1.1.x v1.13.x

Install

  1. Add package
go get -u github.com/goravel/fiber
  1. Register service provider, make sure it is registered first.
// config/app.go
import "github.com/goravel/fiber"

"providers": []foundation.ServiceProvider{
    &fiber.ServiceProvider{},
    ...
}
  1. Add fiber config to config/http.go file
// config/http.go
import (
    fiberfacades "github.com/goravel/fiber/facades"
)

"default": "fiber",

"drivers": map[string]any{
    ...
    "fiber": map[string]any{
        // prefork mode, see https://docs.gofiber.io/api/fiber/#config
        "prefork": false,
        "route": func() (route.Engine, error) {
            return fiberfacades.Route(), nil
        },
    },
}

Testing

Run command below to run test:

go test ./...

Documentation

Index

Constants

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

Variables

View Source
var (
	ConfigFacade     config.Config
	LogFacade        log.Log
	ValidationFacade validation.Validation
)

Functions

func Background

func Background() http.Context

func NewContext added in v1.0.4

func NewContext(ctx *fiber.Ctx) http.Context

func NewGroup added in v1.0.4

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

func NewRequest added in v1.0.4

func NewRequest(ctx *Context, log log.Log, validation validatecontract.Validation) httpcontract.Request

func NewStatus added in v1.1.4

func NewStatus(instance *fiber.Ctx, code int) httpcontract.ResponseSuccess

func NewSuccess added in v1.1.4

func NewSuccess(instance *fiber.Ctx) httpcontract.ResponseSuccess

func ResponseMiddleware added in v1.0.4

func ResponseMiddleware() httpcontract.Middleware

Types

type Context added in v1.0.4

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

func (*Context) Context added in v1.0.4

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

func (*Context) Deadline added in v1.0.4

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

func (*Context) Done added in v1.0.4

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

func (*Context) Err added in v1.0.4

func (c *Context) Err() error

func (*Context) Instance added in v1.0.4

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

func (*Context) Request added in v1.0.4

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

func (*Context) Response added in v1.0.4

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

func (*Context) Value added in v1.0.4

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

func (*Context) WithValue added in v1.0.4

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

type Group added in v1.0.4

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

func (*Group) Any added in v1.0.4

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

func (*Group) Delete added in v1.0.4

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

func (*Group) Get added in v1.0.4

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

func (*Group) Group added in v1.0.4

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

func (*Group) Middleware added in v1.0.4

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

func (*Group) Options added in v1.0.4

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

func (*Group) Patch added in v1.0.4

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

func (*Group) Post added in v1.0.4

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

func (*Group) Prefix added in v1.0.4

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

func (*Group) Put added in v1.0.4

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

func (*Group) Resource added in v1.0.4

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

func (*Group) Static added in v1.0.4

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

func (*Group) StaticFS added in v1.0.4

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

func (*Group) StaticFile added in v1.0.4

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

type Request added in v1.0.4

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

func (*Request) AbortWithStatus added in v1.0.4

func (r *Request) AbortWithStatus(code int)

func (*Request) AbortWithStatusJson added in v1.0.4

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

func (*Request) All added in v1.0.4

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

func (*Request) Bind added in v1.0.4

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

func (*Request) File added in v1.0.4

func (r *Request) File(name string) (filesystemcontract.File, error)

func (*Request) Form added in v1.0.4

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

func (*Request) FullUrl added in v1.0.4

func (r *Request) FullUrl() string

func (*Request) Header added in v1.0.4

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

func (*Request) Headers added in v1.0.4

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

func (*Request) Host added in v1.0.4

func (r *Request) Host() string

func (*Request) Input added in v1.0.4

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

func (*Request) InputBool added in v1.0.4

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

func (*Request) InputInt added in v1.0.4

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

func (*Request) InputInt64 added in v1.0.4

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

func (*Request) Ip added in v1.0.4

func (r *Request) Ip() string

func (*Request) Json added in v1.0.4

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

func (*Request) Method added in v1.0.4

func (r *Request) Method() string

func (*Request) Next added in v1.0.4

func (r *Request) Next()

func (*Request) Origin added in v1.0.4

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

func (*Request) Path added in v1.0.4

func (r *Request) Path() string

func (*Request) Queries added in v1.0.4

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

func (*Request) Query added in v1.0.4

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

func (*Request) QueryArray added in v1.0.4

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

func (*Request) QueryBool added in v1.0.4

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

func (*Request) QueryInt added in v1.0.4

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

func (*Request) QueryInt64 added in v1.0.4

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

func (*Request) QueryMap added in v1.0.4

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

func (*Request) Route added in v1.0.4

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

func (*Request) RouteInt added in v1.0.4

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

func (*Request) RouteInt64 added in v1.0.4

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

func (*Request) Url added in v1.0.4

func (r *Request) Url() string

func (*Request) Validate added in v1.0.4

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

func (*Request) ValidateRequest added in v1.0.4

func (r *Request) ValidateRequest(request httpcontract.FormRequest) (validatecontract.Errors, error)

type Response added in v1.0.4

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

func NewResponse added in v1.0.4

func NewResponse(instance *fiber.Ctx, origin httpcontract.ResponseOrigin) *Response

func (*Response) Data added in v1.0.4

func (r *Response) Data(code int, contentType string, data []byte)

func (*Response) Download added in v1.0.4

func (r *Response) Download(filepath, filename string)

func (*Response) File added in v1.0.4

func (r *Response) File(filepath string)

func (*Response) Flush added in v1.0.4

func (r *Response) Flush()

func (*Response) Header added in v1.0.4

func (r *Response) Header(key, value string) httpcontract.Response

func (*Response) Json added in v1.0.4

func (r *Response) Json(code int, obj any)

func (*Response) Origin added in v1.0.4

func (r *Response) Origin() httpcontract.ResponseOrigin

func (*Response) Redirect added in v1.0.4

func (r *Response) Redirect(code int, location string)

func (*Response) Status added in v1.0.4

func (r *Response) Status(code int) httpcontract.ResponseStatus

func (*Response) String added in v1.0.4

func (r *Response) String(code int, format string, values ...any)

func (*Response) Success added in v1.0.4

func (r *Response) Success() httpcontract.ResponseSuccess

func (*Response) Writer added in v1.0.4

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

type ResponseOrigin added in v1.0.4

type ResponseOrigin struct {
	*fiber.Ctx
}

func (*ResponseOrigin) Body added in v1.0.4

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

func (*ResponseOrigin) Header added in v1.0.4

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

func (*ResponseOrigin) Size added in v1.0.4

func (w *ResponseOrigin) Size() int

func (*ResponseOrigin) Status added in v1.0.4

func (w *ResponseOrigin) Status() int

type Route added in v1.0.4

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

Route fiber route Route 光纤路由

func NewRoute added in v1.0.4

func NewRoute(config config.Config) *Route

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

func (*Route) Fallback added in v1.0.4

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

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

func (*Route) GlobalMiddleware added in v1.0.4

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

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

func (*Route) Run added in v1.0.4

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

Run run server Run 运行服务器

func (*Route) RunTLS added in v1.0.4

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

RunTLS run TLS server RunTLS 运行 TLS 服务器

func (*Route) RunTLSWithCert added in v1.0.4

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

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

func (*Route) ServeHTTP added in v1.0.4

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

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

func (*Route) Test added in v1.0.4

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 added in v1.1.4

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

func (*Status) Data added in v1.1.4

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

func (*Status) Json added in v1.1.4

func (r *Status) Json(obj any)

func (*Status) String added in v1.1.4

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

type Success added in v1.1.4

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

func (*Success) Data added in v1.1.4

func (r *Success) Data(contentType string, data []byte)

func (*Success) Json added in v1.1.4

func (r *Success) Json(obj any)

func (*Success) String added in v1.1.4

func (r *Success) String(format string, values ...any)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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