gins

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: MIT Imports: 27 Imported by: 1

README

GINS

What is GINS?

Gin is an HTTP Web framework implemented in the Go/golang language. Simple interface, high performance.

Gin characteristic

  • ** Fast ** : Routing does not use reflection, is based on Radix tree, and has low memory footprint.
  • ** Middleware ** : HTTP requests can be processed by a series of middleware, such as Logger, Authorization, and GZIP. This feature is similar to the Koa framework for NodeJs. The middleware mechanism also greatly improves the extensibility of the framework.
  • ** Exception Handling ** : The service is always available without downtime. Gin can capture panic and recover. And there are very convenient mechanisms for handling errors that occur during HTTP requests.
  • JSON : Gin can parse and validate the requested JSON. This feature is especially useful for Restful API development.
  • ** Routing Group ** : For example, group apis that require authorization and those that do not require authorization. Group apis of different versions. And the groups can be nested, and performance is not affected.
  • ** Rendering built-in ** : Native support for JSON, XML and HTML rendering.

Reference materials

Documentation

Index

Constants

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

SupportPackageIsVersion1 These constants should not be referenced from any other code.

Variables

This section is empty.

Functions

func Bind

func Bind(ctx *Context, obj any) error

Bind is bind json body to target.

func BindBody

func BindBody(ctx *Context, obj any) error

BindBody bind json body to target.

func BindQuery

func BindQuery(ctx *Context, target interface{}) error

BindQuery bind query parameters to target.

func BindURI

func BindURI(ctx *Context, target interface{}) error

BindURI bind form parameters to target.

func CodecForRequest

func CodecForRequest(c *Context, name string) (encoding.Codec, bool)

CodecForRequest get encoding.Codec via http.Request

func CodecName

func CodecName(name string) string

CodecName returns the content-type with base prefix.

func ContentType

func ContentType(subtype string) string

ContentType returns the content-type with base prefix.

func DefaultErrorEncoder

func DefaultErrorEncoder(c *Context, err error)

DefaultErrorEncoder encodes the error to the HTTP response.

func DefaultRequestDecoder

func DefaultRequestDecoder(c *Context, v interface{}) error

DefaultRequestDecoder decodes the request body to object.

func DefaultRequestQuery

func DefaultRequestQuery(c *Context, v interface{}) error

DefaultRequestQuery decodes the request vars to object.

func DefaultRequestVars

func DefaultRequestVars(c *Context, v interface{}) error

DefaultRequestVars decodes the request vars to object.

func DefaultResponseEncoder

func DefaultResponseEncoder(c *Context, v interface{}) error

DefaultResponseEncoder encodes the object to the HTTP response.

func EncodeURL

func EncodeURL(pathTemplate string, msg interface{}, needQuery bool) string

EncodeURL encode proto message to url path.

func FromContext

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

FromContext takes a context as an argument and returns a pointer to a gin.Context and a boolean value.

func NewContext

func NewContext(ctx *gin.Context) context.Context

NewContext creates a new context from a gin context

func NewEndpoint

func NewEndpoint(scheme, host string) *url.URL

NewEndpoint new an Endpoint URL.

func ParseEndpoint

func ParseEndpoint(endpoints []string, scheme string) (string, error)

ParseEndpoint parses an Endpoint URL.

func Scheme

func Scheme(scheme string, isSecure bool) string

Scheme is the scheme of endpoint url. examples: scheme="http",isSecure=true get "https"

func SetOperation

func SetOperation(ctx context.Context, op string)

SetOperation sets the transport operation.

Types

type CallOption

type CallOption = transhttp.CallOption

CallOption configures a Call before it starts or extracts information from a Call after it completes.

func Operation

func Operation(operation string) CallOption

Operation is serviceMethod call option

func PathTemplate

func PathTemplate(pattern string) CallOption

PathTemplate is http path template

type Client

type Client = transhttp.Client

Client is an HTTP client.

type Context

type Context = gin.Context

type DecodeRequestFunc

type DecodeRequestFunc func(*Context, interface{}) error

DecodeRequestFunc is decode request func.

type EncodeErrorFunc

type EncodeErrorFunc func(*Context, error)

EncodeErrorFunc is encode error func.

type EncodeResponseFunc

type EncodeResponseFunc func(*Context, interface{}) error

EncodeResponseFunc is encode response func.

type Engine

type Engine = gin.Engine

func New

func New(fns ...gin.OptionFunc) *Engine

type Flusher

type Flusher = http.Flusher

Flusher type net/http

type HandlerFunc

type HandlerFunc = gin.HandlerFunc

func Logger

func Logger(logger log.Logger) HandlerFunc

Logger receives the gin framework default log

func Middlewares

func Middlewares(m ...middleware.Middleware) HandlerFunc

Middlewares return middlewares wrapper

func Recovery

func Recovery(logger log.Logger, stack bool) HandlerFunc

Recovery recover any panic that may occur in the project

type IRouter

type IRouter = gin.IRouter

type IRoutes

type IRoutes = gin.IRoutes

type Redirector

type Redirector interface {
	Redirect() (string, int)
}

Redirector replies to the request with a redirect to url which may be a path relative to the request path.

type Request

type Request = http.Request

Request type net/http.

type ResponseController

type ResponseController = http.ResponseController

ResponseController is type net/http.ResponseController which was added in Go 1.20.

type ResponseWriter

type ResponseWriter = http.ResponseWriter

ResponseWriter type net/http.

type RouteInfo

type RouteInfo = gin.RouteInfo

type RouterGroup

type RouterGroup = gin.RouterGroup

type RoutesInfo

type RoutesInfo = gin.RoutesInfo

type Server

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

func NewServer

func NewServer(opts ...ServerOption) *Server

func (*Server) Any

func (s *Server) Any(path string, handlers ...HandlerFunc) IRoutes

func (*Server) DELETE

func (s *Server) DELETE(path string, handlers ...HandlerFunc) IRoutes

func (*Server) Endpoint

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

func (*Server) GET

func (s *Server) GET(path string, handlers ...HandlerFunc) IRoutes

func (*Server) Group

func (s *Server) Group(path string, handlers ...HandlerFunc) *RouterGroup

func (*Server) HEAD

func (s *Server) HEAD(path string, handlers ...HandlerFunc) IRoutes

func (*Server) Handle

func (s *Server) Handle(method, path string, handlers ...HandlerFunc) IRoutes

func (*Server) Match

func (s *Server) Match(methods []string, path string, handlers ...HandlerFunc) IRoutes

func (*Server) OPTIONS

func (s *Server) OPTIONS(path string, handlers ...HandlerFunc) IRoutes

func (*Server) PATCH

func (s *Server) PATCH(path string, handlers ...HandlerFunc) IRoutes

func (*Server) POST

func (s *Server) POST(path string, handlers ...HandlerFunc) IRoutes

func (*Server) PUT

func (s *Server) PUT(path string, handlers ...HandlerFunc) IRoutes

func (*Server) Route

func (s *Server) Route(prefix string, filters ...HandlerFunc) IRoutes

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) Static

func (s *Server) Static(path string, root string) IRoutes

func (*Server) StaticFS

func (s *Server) StaticFS(path string, system http.FileSystem) IRoutes

func (*Server) StaticFile

func (s *Server) StaticFile(path string, filepath string) IRoutes

func (*Server) StaticFileFS

func (s *Server) StaticFileFS(path string, filepath string, system http.FileSystem) IRoutes

func (*Server) Stop

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

func (*Server) Use

func (s *Server) Use(handlers ...HandlerFunc) IRoutes

func (*Server) WalkHandle

func (s *Server) WalkHandle(handle func(method, path string, handler http.HandlerFunc)) error

WalkHandle walks the router and all its sub-routers, calling walkFn for each route in the tree.

func (*Server) WalkRoute

func (s *Server) WalkRoute(fn WalkRouteFunc) error

WalkRoute walks the router and all its sub-routers, calling walkFn for each route in the tree.

type ServerOption

type ServerOption func(*Server)

func Address

func Address(addr string) ServerOption

func Endpoint

func Endpoint(endpoint *url.URL) ServerOption

Endpoint with server address.

func ErrorEncoder

func ErrorEncoder(en EncodeErrorFunc) ServerOption

func Filter

func Filter(filters ...HandlerFunc) ServerOption

Filter with HTTP middleware option.

func Listener

func Listener(lis net.Listener) ServerOption

Listener with server lis

func MethodNotAllowedHandler

func MethodNotAllowedHandler(handlers ...HandlerFunc) ServerOption

func Middleware

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

Middleware with service middleware option.

func Network

func Network(network string) ServerOption

Network with server network.

func NotFoundHandler

func NotFoundHandler(handlers ...HandlerFunc) ServerOption

func RequestDecoder

func RequestDecoder(dec DecodeRequestFunc) ServerOption

RequestDecoder with request decoder.

func ResponseEncoder

func ResponseEncoder(en EncodeResponseFunc) ServerOption

ResponseEncoder with response encoder.

func StrictSlash

func StrictSlash(strictSlash bool) ServerOption

func TLSConfig

func TLSConfig(c *tls.Config) ServerOption

TLSConfig with TLS config.

func Timeout

func Timeout(timeout time.Duration) ServerOption

Timeout with server timeout.

func WithLogger

func WithLogger(l log.Logger) ServerOption

WithLogger inject info logger

func WithTLSConfig

func WithTLSConfig(c *tls.Config) 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 = transhttp.Transporter

Transporter is http Transporter

type WalkRouteFunc

type WalkRouteFunc func(RouteInfo) error

WalkRouteFunc is the type of the function called for each route visited by Walk.

Jump to

Keyboard shortcuts

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