web

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CustomBindRequest

func CustomBindRequest[T any](f func(c *gin.Context) T) func(c *gin.Context)

CustomBindRequest 自定义绑定参数 注意不包含验证 验证还是会统一进行

func DefaultRender

func DefaultRender(ctx *gin.Context, data any, err error)

DefaultRender 默认渲染函数

func GinContext

func GinContext(ctx context.Context) (*gin.Context, bool)

GinContext 返回原始的ginContext

Types

type Commenter

type Commenter interface {
	Comment(string)
}

type DefaultErrorResponse

type DefaultErrorResponse struct {
	Message string `json:"message"`
	TraceID string `json:"traceid"`
}

type Empty

type Empty struct{}

Empty 空参数定义 此类型不参与参数解析

type GroupCommenter

type GroupCommenter interface {
	Commenter
	Router
}

type Handler

type Handler func(any) gin.HandlerFunc

Handler ginhandler包裹器 负责将rpc模式转为gin handler

type Option

type Option func(*option)

func WithAddr

func WithAddr(addr string) Option

func WithDumpRequestBody

func WithDumpRequestBody(o bool) Option

WithDumpRequestBody 是否输出请求体

func WithOpenAPI

func WithOpenAPI(info *oas.DocInfo) Option

func WithResponseRender

func WithResponseRender(r Renderer) Option

WithResponseRender 自定义响应输出

type Renderer

type Renderer func(*gin.Context, any, error)

Renderer 渲染响应

type Router

type Router interface {
	// rpc模式路由方法
	// handler 支持rpc方法和gin.HandleFunc(为了支持gin中间件)
	Get(path string, handler ...any) Commenter
	Post(path string, handler ...any) Commenter
	Put(path string, handler ...any) Commenter
	Patch(path string, handler ...any) Commenter
	Delete(path string, handler ...any) Commenter
	Handle(method, path string, handler ...any) Commenter
	// 同gin
	Use(handler ...gin.HandlerFunc) Router
	Group(path string, handler ...gin.HandlerFunc) GroupCommenter
}

type Routes

type Routes []*routeInfo

func (*Routes) ToDoc

func (r *Routes) ToDoc(info oas.DocInfo) (*oas.Spec, error)

type Server

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

func New

func New(opts ...Option) *Server

func (*Server) GinEngine

func (s *Server) GinEngine() *gin.Engine

GinEngine 返回原始的ginEngine

func (*Server) Route

func (g *Server) Route(f func(*gin.Engine, Handler))

func (*Server) Router

func (s *Server) Router() Router

Router rpc风格的路由

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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