fiber

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

README

gofast-fiber

GoFast 框架的 Fiber HTTP 引擎驱动插件。

框架核心 go-fast-framework 不再内置 HTTP 引擎,需显式安装并注册本插件(或 gofast-gin)。

安装

go get github.com/zhoudm1743/gofast-fiber@v0.9.0

接入

import (
    gohttp "github.com/zhoudm1743/go-fast-framework/http"
    "github.com/zhoudm1743/go-fast-framework/foundation"
    gofastfiber "github.com/zhoudm1743/gofast-fiber"
)

app.SetProviders([]foundation.ServiceProvider{
    // ...
    &gohttp.ServiceProvider{},
    &gofastfiber.ServiceProvider{},
})
server:
  driver: fiber   # 框架配置默认值

依赖

  • github.com/zhoudm1743/go-fast-framework >= v0.9.0
  • github.com/gofiber/fiber/v2

License

Apache-2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRoute

func NewRoute(cfg contracts.Config, validator contracts.Validation, storage contracts.Storage, log contracts.Log) (contracts.Route, error)

NewRoute 创建基于 Fiber 的 HTTP 路由服务实例。

Types

type Context

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

Context 实现 contracts.Context,内部包装 *fiber.Ctx。 应用代码只见 contracts.Context,不感知 Fiber。

func NewContext

NewContext 创建 Fiber 上下文包装器。

func (*Context) Abort

func (ctx *Context) Abort() error

func (*Context) AbortWithCode

func (ctx *Context) AbortWithCode(code int) error

func (*Context) AbortWithJson

func (ctx *Context) AbortWithJson(code int, obj any) error

func (*Context) Bind

func (ctx *Context) Bind(obj any) error

Bind 将请求数据填充到 obj(URI → Query → Body),最后统一验证。

func (*Context) BodyRaw

func (ctx *Context) BodyRaw() []byte

func (*Context) ClearCookie

func (ctx *Context) ClearCookie(name string)

func (*Context) ContentType

func (ctx *Context) ContentType() string

func (*Context) Cookie

func (ctx *Context) Cookie(name string) string

func (*Context) File

func (ctx *Context) File(key string) (contracts.File, error)

func (*Context) Files

func (ctx *Context) Files(key string) ([]contracts.File, error)

Files 返回 multipart 表单中指定 key 的所有上传文件,兼容单文件和多文件。

func (*Context) FormValue

func (ctx *Context) FormValue(key string) string

func (*Context) FullPath

func (ctx *Context) FullPath() string

func (*Context) HTML

func (ctx *Context) HTML(code int, name string, data any) error

HTML 渲染 HTML 模板并发送响应。 name 为相对于模板目录的路径,例如 "home/index.html"。

func (*Context) Header

func (ctx *Context) Header(key string) string

func (*Context) IP

func (ctx *Context) IP() string

func (*Context) JSON

func (ctx *Context) JSON(code int, obj any) error

func (*Context) Method

func (ctx *Context) Method() string

func (*Context) Next

func (ctx *Context) Next() error

func (*Context) Param

func (ctx *Context) Param(key string) string

func (*Context) Path

func (ctx *Context) Path() string

func (*Context) Query

func (ctx *Context) Query(key string, defaultValue ...string) string

func (*Context) QueryBool

func (ctx *Context) QueryBool(key string, defaultValue ...bool) bool

func (*Context) QueryFloat64

func (ctx *Context) QueryFloat64(key string, defaultValue ...float64) float64

func (*Context) QueryInt

func (ctx *Context) QueryInt(key string, defaultValue ...int) int

func (*Context) QueryInt64

func (ctx *Context) QueryInt64(key string, defaultValue ...int64) int64

func (*Context) Redirect

func (ctx *Context) Redirect(code int, location string) error

Redirect 发送 HTTP 重定向响应。

func (*Context) Response

func (ctx *Context) Response() contracts.Response

func (*Context) SendFile

func (ctx *Context) SendFile(path string) error

func (*Context) SetCookie

func (ctx *Context) SetCookie(name, value string, opts contracts.CookieOptions)

func (*Context) SetHeader

func (ctx *Context) SetHeader(key, value string) contracts.Context

func (*Context) Status

func (ctx *Context) Status(code int) contracts.Context

func (*Context) Storage

func (ctx *Context) Storage() contracts.Storage

func (*Context) String

func (ctx *Context) String(code int, s string) error

func (*Context) Underlying

func (ctx *Context) Underlying() any

Underlying 返回底层 *fiber.Ctx,用于 SSE 等高级场景。

func (*Context) UserAgent

func (ctx *Context) UserAgent() string

func (*Context) Value

func (ctx *Context) Value(key string) any

func (*Context) WithValue

func (ctx *Context) WithValue(key string, value any) contracts.Context

func (*Context) Write

func (ctx *Context) Write(data []byte) error

Write 写入原始字节到响应体。

type ServiceProvider

type ServiceProvider struct{}

ServiceProvider Fiber HTTP 驱动接入点(可选驱动,需显式加入应用 providers)。

import gofastfiber "github.com/zhoudm1743/gofast-fiber"
app.SetProviders(append(providers, &gofastfiber.ServiceProvider{}))

配置 server.driver: fiber(框架默认值)

func (*ServiceProvider) Boot

func (*ServiceProvider) Register

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

Jump to

Keyboard shortcuts

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