libgin

package module
v1.0.19 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2025 License: MIT Imports: 8 Imported by: 37

README

libgin

Starter for building web, including RESTful, applications using Gin

Documentation

Index

Constants

View Source
const (
	GroupREST   = "rest"
	GroupStatic = "static"
)

定义常用的分组名称

Variables

This section is empty.

Functions

func NewDemoModule added in v1.0.9

func NewDemoModule() *application.ModuleBuilder

NewDemoModule 创建模块 [github.com/starter-go/libgin#demo]

func NewDevtoolsModule added in v1.0.9

func NewDevtoolsModule() *application.ModuleBuilder

NewDevtoolsModule 导出模块 [github.com/starter-go/libgin#devtools]

func NewMainModule added in v1.0.9

func NewMainModule() *application.ModuleBuilder

NewMainModule 导出模块 github.com/starter-go/libgin

func NewTestModule added in v1.0.18

func NewTestModule() *application.ModuleBuilder

NewTestModule 创建模块 [github.com/starter-go/libgin#demo]

Types

type Connector

type Connector interface {
}

Connector ...

type ConnectorRegistration

type ConnectorRegistration struct {
	Name      string
	Connector Connector
}

ConnectorRegistration ...

type ConnectorRegistry added in v1.0.8

type ConnectorRegistry interface {
	ListRegistrations() []*ConnectorRegistration
}

ConnectorRegistry ...

type ContentTypeManager

type ContentTypeManager interface {
	FindTypeBySuffix(suffix string) (string, error)
}

ContentTypeManager 是文档类型管理器

type Context

type Context interface {
	GetConnectorByName(name string) (Connector, error)
	GetGroupByName(name string) (Group, error)
	GetRouterByName(name string) (Router, error)
	ListControllersForGroup(groupName string) ([]*ControllerRegistration, error)
}

Context 是 libgin 上下文,它集中管理各种 libgin 资源

type ContextHolder added in v1.0.4

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

ContextHolder 用来绑定 gin.Context & context.Context

func BindContext added in v1.0.4

func BindContext(c *gin.Context) *ContextHolder

BindContext 绑定 gin.Context & context.Context

func GetContextHolder added in v1.0.4

func GetContextHolder(cc context.Context) (*ContextHolder, error)

GetContextHolder 取 ContextHolder

func (*ContextHolder) Context added in v1.0.7

func (inst *ContextHolder) Context() context.Context

Context ...

func (*ContextHolder) GetValue added in v1.0.7

func (inst *ContextHolder) GetValue(key any) any

GetValue ...

func (*ContextHolder) GinContext added in v1.0.4

func (inst *ContextHolder) GinContext() *gin.Context

GinContext 获取绑定的 gin.Context

func (*ContextHolder) SetValue added in v1.0.7

func (inst *ContextHolder) SetValue(key, value any)

SetValue ...

type Controller

type Controller interface {
	Registration() *ControllerRegistration
}

Controller 表示一个 gin 控制器

type ControllerRegistration

type ControllerRegistration struct {
	Groups []string                   // 分组名称, 如果为空表示默认分组
	Route  func(rp RouterProxy) error // 控制器
}

ControllerRegistration 是控制器注册信息

type Executor added in v1.0.19

type Executor struct {
	Responder Responder
	Context   *gin.Context

	Body1  any
	Body2  any
	Error  error
	Status int

	// callbacks
	OnOpen  ExecutorOnOpenFunc
	OnSend  ExecutorOnSendFunc
	OnTask  ExecutorOnTaskFunc
	OnError ExecutorOnErrorFunc
	OnPanic ExecutorOnPanicFunc
	OnClose ExecutorOnCloseFunc
}

Executor 是默认的 REST 请求执行对象; 它为 REST API 提供一个便捷的可编程执行过程。

func (*Executor) DefaultOnClose added in v1.0.19

func (inst *Executor) DefaultOnClose()

func (*Executor) DefaultOnError added in v1.0.19

func (inst *Executor) DefaultOnError(err error)

func (*Executor) DefaultOnOpen added in v1.0.19

func (inst *Executor) DefaultOnOpen(c *gin.Context) error

func (*Executor) DefaultOnPanic added in v1.0.19

func (inst *Executor) DefaultOnPanic(x any)

func (*Executor) DefaultOnSend added in v1.0.19

func (inst *Executor) DefaultOnSend(err error)

func (*Executor) DefaultOnTask added in v1.0.19

func (inst *Executor) DefaultOnTask() error

func (*Executor) Execute added in v1.0.19

func (inst *Executor) Execute()

type ExecutorOnCloseFunc added in v1.0.19

type ExecutorOnCloseFunc func()

type ExecutorOnErrorFunc added in v1.0.19

type ExecutorOnErrorFunc func(err error)

type ExecutorOnOpenFunc added in v1.0.19

type ExecutorOnOpenFunc func(c *gin.Context) error

type ExecutorOnPanicFunc added in v1.0.19

type ExecutorOnPanicFunc func(x any)

type ExecutorOnSendFunc added in v1.0.19

type ExecutorOnSendFunc func(err error)

type ExecutorOnTaskFunc added in v1.0.19

type ExecutorOnTaskFunc func() error

type Group

type Group interface {
	// Registration( ... ) *GroupRegistration
	Route(r Router) error
}

Group ...

type GroupRegistration

type GroupRegistration struct {
	Enabled bool
	Name    string
	Path    string
	Group   Group
}

GroupRegistration ...

type GroupRegistry added in v1.0.8

type GroupRegistry interface {
	ListRegistrations() []*GroupRegistration
}

GroupRegistry ...

type Responder

type Responder interface {
	Accept(resp *Response) bool

	Send(resp *Response)
}

Responder 是 REST 响应发送器的接口

type ResponderRegistration added in v1.0.2

type ResponderRegistration struct {
	Priority  int // 优先级,数值越大,越先处理
	Name      string
	Enabled   bool
	Responder Responder
}

ResponderRegistration 是 Responder 的注册信息

type ResponderRegistry added in v1.0.2

type ResponderRegistry interface {
	ListRegistrations() []*ResponderRegistration
}

ResponderRegistry 是 Responder 的注册接口

type Response

type Response struct {
	Context   *gin.Context
	Status    int
	Error     error
	Responder string // 用于选择 Responder,它的值为 ResponderRegistration.Name
	Data      any
}

Response 表示一个 REST 响应结果

type Router

type Router interface {
	// Registration(  ) *RouterRegistration
	Engine() *gin.Engine
}

Router ...

type RouterProxy added in v1.0.5

type RouterProxy interface {
	For(path string) RouterProxy
	Route(r *Routing)
	Handle(method string, path string, h ...gin.HandlerFunc)
	NoMethod(h ...gin.HandlerFunc)
	NoRoute(h ...gin.HandlerFunc)

	GET(path string, h ...gin.HandlerFunc)
	POST(path string, h ...gin.HandlerFunc)
	PUT(path string, h ...gin.HandlerFunc)
	DELETE(path string, h ...gin.HandlerFunc)
}

RouterProxy ...

type RouterRegistration

type RouterRegistration struct {
	Name   string
	Router Router
}

RouterRegistration ...

type RouterRegistry added in v1.0.8

type RouterRegistry interface {
	ListRegistrations() []*RouterRegistration
}

RouterRegistry ...

type Routing added in v1.0.5

type Routing struct {
	Method      string
	Path        string
	Priority    int
	NoMethod    bool
	NoRoute     bool
	Middleware  bool
	AsIndexPage bool
	Handlers    []gin.HandlerFunc
}

Routing 表示一条路由记录

Directories

Path Synopsis
devtools
xos
gen
modules
src
configen command
demo/golang command
devtools command
main/golang command
test/golang command

Jump to

Keyboard shortcuts

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