gin

package
v0.0.0-...-01d4da0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: MulanPSL-2.0 Imports: 11 Imported by: 0

README

GIN

什么是GIN?

Gin 是使用 Go/golang 语言实现的 HTTP Web 框架。接口简洁,性能极高。

Gin 特性

  • 快速:路由不使用反射,基于Radix树,内存占用少。
  • 中间件:HTTP请求,可先经过一系列中间件处理,例如:Logger,Authorization,GZIP等。这个特性和 NodeJs 的 Koa 框架很像。中间件机制也极大地提高了框架的可扩展性。
  • 异常处理:服务始终可用,不会宕机。Gin 可以捕获 panic,并恢复。而且有极为便利的机制处理HTTP请求过程中发生的错误。
  • JSON:Gin可以解析并验证请求的JSON。这个特性对Restful API的开发尤其有用。
  • 路由分组:例如将需要授权和不需要授权的API分组,不同版本的API分组。而且分组可嵌套,且性能不受影响。
  • 渲染内置:原生支持JSON,XML和HTML的渲染。

参考资料

Documentation

Index

Constants

View Source
const (
	KindGin transport.Kind = "gin"
)

Variables

This section is empty.

Functions

func SetOperation

func SetOperation(ctx context.Context, op string)

SetOperation sets the transport operation.

Types

type Server

type Server struct {
	*gin.Engine
	// contains filtered or unexported fields
}

func NewServer

func NewServer(opts ...ServerOption) *Server

func (*Server) Endpoint

func (s *Server) Endpoint() (*url.URL, error)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(res http.ResponseWriter, req *http.Request)

func (*Server) Start

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

func (*Server) Stop

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

type ServerOption

type ServerOption func(*Server)

func WithAddress

func WithAddress(addr string) ServerOption

func WithErrorEncoder

func WithErrorEncoder(en kHttp.EncodeErrorFunc) ServerOption

func WithFilter

func WithFilter(filters ...kHttp.FilterFunc) ServerOption

func WithMiddleware

func WithMiddleware(m ...middleware.Middleware) ServerOption

func WithRequestDecoder

func WithRequestDecoder(dec kHttp.DecodeRequestFunc) ServerOption

func WithResponseEncoder

func WithResponseEncoder(en kHttp.EncodeResponseFunc) ServerOption

func WithStrictSlash

func WithStrictSlash(strictSlash bool) ServerOption

func WithTLSConfig

func WithTLSConfig(c *tls.Config) ServerOption

func WithTimeout

func WithTimeout(timeout time.Duration) ServerOption

type Transport

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

Transport is an HTTP transport.

func (*Transport) Endpoint

func (tr *Transport) Endpoint() string

Endpoint returns the transport endpoint.

func (*Transport) Kind

func (tr *Transport) Kind() transport.Kind

Kind returns the transport kind.

func (*Transport) Operation

func (tr *Transport) Operation() string

Operation returns the transport operation.

func (*Transport) PathTemplate

func (tr *Transport) PathTemplate() string

PathTemplate returns the http path template.

func (*Transport) ReplyHeader

func (tr *Transport) ReplyHeader() transport.Header

ReplyHeader returns the reply header.

func (*Transport) Request

func (tr *Transport) Request() *http.Request

Request returns the HTTP request.

func (*Transport) RequestHeader

func (tr *Transport) RequestHeader() transport.Header

RequestHeader returns the request header.

type Transporter

type Transporter interface {
	transport.Transporter
	Request() *http.Request
	PathTemplate() string
}

Transporter is http Transporter

Jump to

Keyboard shortcuts

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