gins

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: MIT Imports: 32 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

Overview

Package gins is a gin extension package.

Package gins is a gin extension package.

Package gins is a gin extension package.

Package gins is a gin extension package.

Package gins is a gin extension package.

Package gins is a gin extension package.

Package gins is a gin extension package.

Package gins is a gin extension package.

Package gins is a gin extension package.

Package gins implements the functions, types, and interfaces for the module.

Package gins is a gin extension package.

Package gins is a gin extension package.

Package gins is a gin extension package.

Index

Constants

View Source
const (
	ContextRequestBodyBytesKey = "_gins_context_request_body_bytes"
	ContextResponseBodBytesKey = "_gins_context_response_body_bytes"
)
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 ResultError added in v0.0.13

func ResultError(c *Context, err error, status ...int)

ResultError result error data with status code

func ResultJSON added in v0.0.13

func ResultJSON(c *gin.Context, status int, resp pagination.Responder)

ResultJSON result json data with status code

func ResultOK added in v0.0.13

func ResultOK(c *gin.Context)

ResultOK result success data with status code

func ResultPage added in v0.0.13

func ResultPage(c *gin.Context, resp pagination.Responder, args ...map[string]any)

ResultPage result page data with status code

func ResultSuccess added in v0.0.13

func ResultSuccess(c *gin.Context, resp pagination.Responder)

ResultSuccess result success data with status code

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 Result added in v0.0.10

type Result struct {
	pagination.UnimplementedResponder `json:"-"`
	Success                           bool           `json:"success"`
	Total                             int64          `json:"total,omitempty"`
	Data                              any            `json:"data,omitempty"`
	Extra                             any            `json:"extra,omitempty"`
	Error                             *httperr.Error `json:"error,omitempty"`
}

func (Result) GetData added in v0.0.13

func (r Result) GetData() any

func (Result) GetSuccess added in v0.0.13

func (r Result) GetSuccess() bool

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