httptool

package module
v0.0.0-...-40d7aee Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2022 License: LGPL-2.1 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Nil reqType = iota
	JSON
	XML
	Form
	Query
	FormPost
	FormMultipart
	ProtoBuf
	MsgPack
	YAML
	Uri
	Header
	TOML
)
View Source
const (
	Credentials = "credentials"
	BasicAuth   = "BasicAuth"
	BearerAuth  = "BearerAuth"
	ApiKeyAuth  = "ApiKeyAuth"
	OpenIDAuth  = "OpenIDAuth"
	OAuth2Auth  = "OAuth2Auth"
)
View Source
const (
	DEFAULT     = "default"
	BINDING     = "binding"
	DESCRIPTION = "description"
	QUERY       = "query"
	FORM        = "form"
	URI         = "uri"
	HEADER      = "header"
	COOKIE      = "cookie"
)

Variables

View Source
var (
	ErrNotFound = errors.New("no this record")
	ErrInsert   = errors.New("insert fail")
	ErrUpdate   = errors.New("update fail")
	ErrDelete   = errors.New("delete fail")
)

各类错误类型

View Source
var RQuery = queryBinding{}

Functions

func BindModel

func BindModel(req interface{}) gin.HandlerFunc

func CookiesParser

func CookiesParser(c *gin.Context, model interface{}) error

func NewHub

func NewHub() *hub

func RegisterGroup

func RegisterGroup(engine *gin.Engine, group *RouterGroup)

func RegisterGroupSimple

func RegisterGroupSimple(engine *gin.Engine, Relative string, Middlewares []gin.HandlerFunc, Handlers []RouterHandler)

func RegisterHandler

func RegisterHandler(engine *gin.Engine, handlers ...RouterHandler)

Types

type ApiKey

type ApiKey struct {
	Security
	Name string
}

func (*ApiKey) Authorize

func (k *ApiKey) Authorize(c *gin.Context)

func (*ApiKey) Provider

func (k *ApiKey) Provider() string

func (*ApiKey) Scheme

func (k *ApiKey) Scheme() *openapi3.SecurityScheme

type Basic

type Basic struct {
	Security
}

func (*Basic) Authorize

func (b *Basic) Authorize(c *gin.Context)

func (*Basic) Provider

func (b *Basic) Provider() string

func (*Basic) Scheme

func (b *Basic) Scheme() *openapi3.SecurityScheme

type Bearer

type Bearer struct {
	Security

	Required bool
}

func (*Bearer) Authorize

func (b *Bearer) Authorize(c *gin.Context)

func (*Bearer) Provider

func (b *Bearer) Provider() string

func (*Bearer) Scheme

func (b *Bearer) Scheme() *openapi3.SecurityScheme

type Client

type Client struct {
	Hub *hub
	// contains filtered or unexported fields
}

Client is a middleman between the websocket connection and the hub.

func NewWSClient

func NewWSClient(ctx *gin.Context) (*Client, error)

func (*Client) Read

func (c *Client) Read(ctx context.Context) (string, error)

func (*Client) Write

func (c *Client) Write(ctx context.Context, msg string) error

type ContentTypeType

type ContentTypeType string
var (
	ContentTypeRequest  ContentTypeType = "request"
	ContentTypeResponse ContentTypeType = "response"
)

type EnginX

type EnginX struct {
	*gin.Engine

	Routers map[string]map[string]*Router

	ErrorHandler ErrorHandlerFunc
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine(engine *gin.Engine, opts ...EnginxOpt) *EnginX

func (*EnginX) AfterInit

func (g *EnginX) AfterInit(f func())

func (*EnginX) BeforeInit

func (g *EnginX) BeforeInit(f func())

func (*EnginX) DELETE

func (g *EnginX) DELETE(path string, handler gin.HandlerFunc)

func (*EnginX) GET

func (g *EnginX) GET(path string, handler gin.HandlerFunc)

func (*EnginX) Group

func (g *EnginX) Group(path string, options ...Option) *Group

func (*EnginX) HEAD

func (g *EnginX) HEAD(path string, handler gin.HandlerFunc)

func (*EnginX) Handle

func (g *EnginX) Handle(path string, method string, r *Router)

func (*EnginX) Init

func (g *EnginX) Init()

func (*EnginX) Mount

func (g *EnginX) Mount(path string, app *EnginX)

func (*EnginX) OPTIONS

func (g *EnginX) OPTIONS(path string, handler gin.HandlerFunc)

func (*EnginX) PATCH

func (g *EnginX) PATCH(path string, handler gin.HandlerFunc)

func (*EnginX) POST

func (g *EnginX) POST(path string, handler gin.HandlerFunc)

func (*EnginX) PUT

func (g *EnginX) PUT(path string, handler gin.HandlerFunc)

func (*EnginX) Register

func (g *EnginX) Register(spec interface{}, middlewares ...gin.HandlerFunc)

func (*EnginX) RegisterAll

func (g *EnginX) RegisterAll(spec ...interface{})

func (*EnginX) Run

func (g *EnginX) Run(addr string) error

func (*EnginX) WithErrorHandler

func (g *EnginX) WithErrorHandler(handler ErrorHandlerFunc) *EnginX

type EnginxOpt

type EnginxOpt func(*EnginX)

func WithGlobalMiddleware

func WithGlobalMiddleware(middlewares ...gin.HandlerFunc) EnginxOpt

func WithGlobalMiddlewareByName

func WithGlobalMiddlewareByName(middlewares ...string) EnginxOpt

func WithLog

func WithLog(logger *logger.ZapX) EnginxOpt

func WithSwagger

func WithSwagger(swagger *Swagger) EnginxOpt

func WithWS

func WithWS() EnginxOpt

func WithWebStatic

func WithWebStatic(dist *embed.FS, prefix string) EnginxOpt

type ErrorHandlerFunc

type ErrorHandlerFunc func(ctx *gin.Context, err error, status int)

type Group

type Group struct {
	*EnginX
	Path       string
	Tags       []string
	Handlers   []gin.HandlerFunc
	Securities []ISecurity
}

func (*Group) DELETE

func (g *Group) DELETE(path string, router *Router)

func (*Group) GET

func (g *Group) GET(path string, router *Router)

func (*Group) Group

func (g *Group) Group(path string, options ...Option) *Group

func (*Group) HEAD

func (g *Group) HEAD(path string, router *Router)

func (*Group) Handle

func (g *Group) Handle(path string, method string, r *Router)

func (*Group) OPTIONS

func (g *Group) OPTIONS(path string, router *Router)

func (*Group) PATCH

func (g *Group) PATCH(path string, router *Router)

func (*Group) POST

func (g *Group) POST(path string, router *Router)

func (*Group) PUT

func (g *Group) PUT(path string, router *Router)

type Handler

type Handler struct {
	Method      string   `default:"GET"`
	Description string   `default:"no description"`
	Tags        []string `default:"default"`
	ContentType string   `default:"json"`
	Security    string   `default:"null"`
	Middlewares string

	Request struct{}

	Response200 struct {
		Code int    `json:"code"`
		Msg  string `json:"msg"`
	} `type:"application/json"`

	Response500 struct {
		Code   int    `json:"code"`
		Msg    string `json:"msg"`
		Detail string `json:"detail"`
	} `type:"application/json"`
}

put this in common

type CommonSuccResponse struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
}
type CommonFailResponse struct {
	Code   int    `json:"code"`
	Msg    string `json:"msg"`
	Detail string `json:"detail"`
}

this is a snippet @Summary (概要) @Description (描述) @Tags (tag) @Accept (请求类型: json|form) @Produce (响应类型: json) @Param token header string true "-" @Param req (参数类型: body | header | form | query) (数据类型) true "-" @Success 200 {object} CommonSuccRespons @Failure 500 {object} CommonFailResponse @Router (url) [ ( get | post | put) ]

func (Handler) Bind

func (Handler) Bind(ctx *gin.Context, val interface{}) error

func (*Handler) DoJson

func (b *Handler) DoJson(ctx *gin.Context, code types.ResponseCode, groups []string, data interface{})

func (*Handler) DoReq

func (b *Handler) DoReq(ctx *gin.Context, typ_ reqType, req interface{}) error

序列化请求以及进行校验

func (*Handler) DoRes

func (b *Handler) DoRes(ctx *gin.Context, code types.ResponseCode, ext interface{})

func (*Handler) Parse

func (b *Handler) Parse(ctx *gin.Context, req interface{}) error

func (*Handler) WS

func (b *Handler) WS(ctx *gin.Context) (*Client, error)

type ISecurity

type ISecurity interface {
	Authorize(g *gin.Context)
	Callback(c *gin.Context, credentials interface{}, err error)
	Provider() string
	Scheme() *openapi3.SecurityScheme
}

type Model

type Model any

type OAuth2

type OAuth2 struct {
	Security
	AuthorizationURL string
	TokenURL         string
	RefreshURL       string
	Scopes           map[string]string
}

func (*OAuth2) Authorize

func (i *OAuth2) Authorize(c *gin.Context)

func (*OAuth2) Provider

func (i *OAuth2) Provider() string

func (*OAuth2) Scheme

func (i *OAuth2) Scheme() *openapi3.SecurityScheme

type OpenID

type OpenID struct {
	Security
	ConnectUrl string
}

func (*OpenID) Authorize

func (i *OpenID) Authorize(c *gin.Context)

func (*OpenID) Provider

func (i *OpenID) Provider() string

func (*OpenID) Scheme

func (i *OpenID) Scheme() *openapi3.SecurityScheme

type Option

type Option func(*Group)

func GroupHandlers

func GroupHandlers(handlers ...gin.HandlerFunc) Option

func GroupSecurity

func GroupSecurity(securities ...ISecurity) Option

func GroupTags

func GroupTags(tags ...string) Option

type Response

type Response map[string]ResponseItem

type ResponseItem

type ResponseItem struct {
	Description string
	Model       interface{}
	ContentType string
	Headers     openapi3.Headers
}

type Router

type Router struct {
	Handlers           *list.List
	Path               string
	Method             string
	Summary            string
	Description        string
	Deprecated         bool
	RequestContentType string
	// ResponseContentType string
	Tags        []string
	API         gin.HandlerFunc
	Model       Model
	OperationID string
	Exclude     bool
	Securities  []ISecurity
	Response    Response
}

func NewRouter

func NewRouter(f gin.HandlerFunc, options ...RouterOption) *Router

func RouterNew

func RouterNew[T Model, F func(c *gin.Context, req T)](f F, options ...RouterOption) *Router

func RouterNewNew

func RouterNewNew(val interface{}, fn gin.HandlerFunc) *Router

func (*Router) GetHandlers

func (router *Router) GetHandlers() []gin.HandlerFunc

func (*Router) WithContentType

func (router *Router) WithContentType(contentType string, contentTypeType ContentTypeType) *Router

func (*Router) WithDeprecated

func (router *Router) WithDeprecated() *Router

func (*Router) WithDescription

func (router *Router) WithDescription(description string) *Router

func (*Router) WithExclude

func (router *Router) WithExclude() *Router

func (*Router) WithHandlers

func (router *Router) WithHandlers(handlers ...gin.HandlerFunc) *Router

func (*Router) WithOperationID

func (router *Router) WithOperationID(ID string) *Router

func (*Router) WithResponses

func (router *Router) WithResponses(response Response) *Router

func (*Router) WithSecurity

func (router *Router) WithSecurity(securities ...ISecurity) *Router

func (*Router) WithSummary

func (router *Router) WithSummary(summary string) *Router

func (*Router) WithTags

func (router *Router) WithTags(tags ...string) *Router

type RouterGroup

type RouterGroup struct {
	Relative    string
	Middlewares []gin.HandlerFunc
	Handler     []RouterHandler
}

type RouterHandler

type RouterHandler struct {
	Method     string
	Url        string
	Handler    gin.HandlerFunc
	Middleware []gin.HandlerFunc
}

func H

func H(method string, url string, handler gin.HandlerFunc, middleware []gin.HandlerFunc) RouterHandler

func HDefault

func HDefault(v interface{}) (handlers []RouterHandler)

type RouterOption

type RouterOption func(router *Router)

func ContentType

func ContentType(contentType string, contentTypeType ContentTypeType) RouterOption

ContentType Set request contentType

func Deprecated

func Deprecated() RouterOption

Deprecated mark api is deprecated

func Description

func Description(description string) RouterOption

func Exclude

func Exclude() RouterOption

Exclude exclude in docs

func Handlers

func Handlers(handlers ...gin.HandlerFunc) RouterOption

func OperationID

func OperationID(ID string) RouterOption

func Responses

func Responses(response Response) RouterOption

func RouterSecurity

func RouterSecurity(securities ...ISecurity) RouterOption

func Summary

func Summary(summary string) RouterOption

func Tags

func Tags(tags ...string) RouterOption

type Security

type Security struct {
	ISecurity
}

func (*Security) Callback

func (s *Security) Callback(c *gin.Context, credentials interface{}, err error)

type Swagger

type Swagger struct {
	Title             string
	Description       string
	Version           string
	DocsUrl           string
	RedocUrl          string
	OpenAPIUrl        string
	ExtraOpenAPIUrl   string
	OpenAPIMiddleware []gin.HandlerFunc
	Routers           map[string]map[string]*Router
	Servers           openapi3.Servers
	TermsOfService    string
	Contact           *openapi3.Contact
	License           *openapi3.License
	OpenAPI           *openapi3.T
	SwaggerOptions    map[string]interface{}
	RedocOptions      map[string]interface{}
}

func New

func New(title, description, version string, options ...SwaggerOption) *Swagger

func (*Swagger) BuildOpenAPI

func (swagger *Swagger) BuildOpenAPI()

func (*Swagger) MarshalJSON

func (swagger *Swagger) MarshalJSON() ([]byte, error)

func (*Swagger) MarshalYAML

func (swagger *Swagger) MarshalYAML() ([]byte, error)

func (*Swagger) WithContact

func (swagger *Swagger) WithContact(contact *openapi3.Contact) *Swagger

func (*Swagger) WithDescription

func (swagger *Swagger) WithDescription(description string) *Swagger

func (*Swagger) WithDocsUrl

func (swagger *Swagger) WithDocsUrl(url string) *Swagger

func (*Swagger) WithExtraOpenApi

func (swagger *Swagger) WithExtraOpenApi(extraurl string, middlewares ...gin.HandlerFunc) *Swagger

func (*Swagger) WithLicense

func (swagger *Swagger) WithLicense(license *openapi3.License) *Swagger

func (*Swagger) WithOpenAPIUrl

func (swagger *Swagger) WithOpenAPIUrl(url string) *Swagger

func (*Swagger) WithRedocOptions

func (swagger *Swagger) WithRedocOptions(options map[string]interface{}) *Swagger

func (*Swagger) WithRedocUrl

func (swagger *Swagger) WithRedocUrl(url string) *Swagger

func (*Swagger) WithServers

func (swagger *Swagger) WithServers(servers []*openapi3.Server) *Swagger

func (*Swagger) WithSwaggerOptions

func (swagger *Swagger) WithSwaggerOptions(options map[string]interface{}) *Swagger

func (*Swagger) WithTermsOfService

func (swagger *Swagger) WithTermsOfService(termsOfService string) *Swagger

func (*Swagger) WithTitle

func (swagger *Swagger) WithTitle(title string) *Swagger

func (*Swagger) WithVersion

func (swagger *Swagger) WithVersion(version string) *Swagger

type SwaggerOption

type SwaggerOption func(swagger *Swagger)

func Contact

func Contact(Contact *openapi3.Contact) SwaggerOption

func DocsUrl

func DocsUrl(url string) SwaggerOption

func License

func License(License *openapi3.License) SwaggerOption

func OpenAPIUrl

func OpenAPIUrl(url string) SwaggerOption

func RedocOptions

func RedocOptions(options map[string]interface{}) SwaggerOption

func RedocUrl

func RedocUrl(url string) SwaggerOption

func Routers

func Routers(routers map[string]map[string]*Router) SwaggerOption

func Servers

func Servers(servers openapi3.Servers) SwaggerOption

func SwagDescription

func SwagDescription(description string) SwaggerOption

func SwaggerOptions

func SwaggerOptions(options map[string]interface{}) SwaggerOption

func TermsOfService

func TermsOfService(TermsOfService string) SwaggerOption

func Title

func Title(title string) SwaggerOption

func Version

func Version(version string) SwaggerOption

type User

type User struct {
	Username string
	Password string
}

Directories

Path Synopsis
admin
jwt
store
mysql Module
postgresql Module
source Module
sqlite Module

Jump to

Keyboard shortcuts

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