Documentation ¶
Index ¶
- Constants
- Variables
- func AddGRPCMetadata(ctx context.Context, headerMD, trailerMD metadata.MD, ...)
- func AppendRichRoutes[R gin.IRoutes](iRoutes R, routes ...RichRoute) R
- func AppendRoutes[R gin.IRoutes](iRoutes R, routes ...Route) R
- func AsciiJSONRender(ctx context.Context, code int, resp any, _ string)
- func BytesBinding(ctx context.Context, req any, tag string) error
- func BytesRender(ctx context.Context, code int, resp any, contentType string)
- func CustomBinding(ctx context.Context, req any, _ string) error
- func CustomRender(ctx context.Context, code int, resp any, _ string)
- func ErrorRender(ctx context.Context, err error, ...)
- func FormBinding(ctx context.Context, req any, tag string) error
- func FormMultipartBinding(ctx context.Context, req any, tag string) error
- func FormPostBinding(ctx context.Context, req any, tag string) error
- func FromContext(ctx context.Context) *gin.Context
- func HTMLRender(ctx context.Context, code int, resp any, _ string)
- func Header(ctx context.Context) http.Header
- func HeaderBinding(ctx context.Context, req any, tag string) error
- func IndentedJSONRender(ctx context.Context, code int, resp any, _ string)
- func JSONBinding(ctx context.Context, req any, _ string) error
- func JSONPJSONRender(ctx context.Context, code int, resp any, _ string)
- func JSONRender(ctx context.Context, code int, resp any, _ string)
- func MsgPackBinding(ctx context.Context, req any, _ string) error
- func MsgPackRender(ctx context.Context, code int, resp any, _ string)
- func NewContext(c *gin.Context, rpcMethodName string) context.Context
- func NewGRPCContext(ctx context.Context, headerMatcher func(key string) (string, bool), ...) (context.Context, error)
- func ProtoBufBinding(ctx context.Context, req any, _ string) error
- func ProtoBufRender(ctx context.Context, code int, resp any, _ string)
- func ProtoJSONBinding(ctx context.Context, req any, _ string) error
- func ProtoJSONRender(ctx context.Context, code int, resp any, _ string)
- func PureJSONRender(ctx context.Context, code int, resp any, _ string)
- func QueryBinding(ctx context.Context, req any, tag string) error
- func RPCMethod(ctx context.Context) (string, bool)
- func ReaderBinding(ctx context.Context, req any, _ string) error
- func ReaderRender(ctx context.Context, code int, resp any, contentType string)
- func RedirectRender(ctx context.Context, code int, resp any, _ string)
- func RequestBind(ctx context.Context, req any, tag string, ...) error
- func ResponseRender(ctx context.Context, code int, resp any, contentType string, ...)
- func SecureJSONRender(ctx context.Context, code int, resp any, _ string)
- func SetHeader(ctx context.Context, header http.Header)
- func SetStatusCode(ctx context.Context, code int)
- func SetTrailer(ctx context.Context, trailer http.Header)
- func StatusCode(ctx context.Context) int
- func StringBinding(ctx context.Context, req any, tag string) error
- func StringRender(ctx context.Context, code int, resp any, contentType string)
- func TOMLBinding(ctx context.Context, req any, _ string) error
- func TOMLRender(ctx context.Context, code int, resp any, _ string)
- func TextRender(ctx context.Context, code int, resp any, _ string)
- func Trailer(ctx context.Context) http.Header
- func UriBinding(ctx context.Context, req any, tag string) error
- func Validate(req interface{}) error
- func XMLBinding(ctx context.Context, req any, _ string) error
- func XMLRender(ctx context.Context, code int, resp any, _ string)
- func YAMLBinding(ctx context.Context, req any, _ string) error
- func YAMLRender(ctx context.Context, code int, resp any, _ string)
- type Binding
- type Empty
- type Error
- type Option
- func ErrorHandler(h func(ctx context.Context, err error) error) Option
- func IncomingHeaderMatcher(m func(key string) (string, bool)) Option
- func MetadataAnnotator(a ...func(ctx context.Context) metadata.MD) Option
- func OutgoingHeaderMatcher(m func(key string) (string, bool)) Option
- func ResponseWrapper(w func(resp any) any) Option
- func Tag(tag string) Option
- type Options
- type Render
- type RichRoute
- type Route
- type ServerTransportStream
- func (s *ServerTransportStream) Header() metadata.MD
- func (s *ServerTransportStream) Method() string
- func (s *ServerTransportStream) SendHeader(md metadata.MD) error
- func (s *ServerTransportStream) SetHeader(md metadata.MD) error
- func (s *ServerTransportStream) SetTrailer(md metadata.MD) error
- func (s *ServerTransportStream) Trailer() metadata.MD
- type Status
- type Validator
Constants ¶
const GorsMetadataPrefix = "gors-"
GorsMetadataPrefix is prepended to permanent HTTP header keys when added to the gRPC context.
const MetadataHeaderPrefix = "Grpc-Metadata-"
MetadataHeaderPrefix is the http prefix that represents custom metadata parameters to or from a gRPC call.
const MetadataTrailerPrefix = "Grpc-Trailer-"
MetadataTrailerPrefix is prepended to gRPC metadata as it is converted to HTTP headers in a response handled by grpc-gateway
Variables ¶
var DefaultContextTimeout = 0 * time.Second
DefaultContextTimeout is used for gRPC call context.WithTimeout whenever a Grpc-Timeout inbound header isn't present. If the value is 0 the sent `context` will not have a timeout.
Functions ¶
func AddGRPCMetadata ¶ added in v1.3.0
func AppendRichRoutes ¶ added in v1.1.1
AppendRichRoutes 追加富路由
func AppendRoutes ¶ added in v1.1.1
AppendRoutes 追加基础路由
func AsciiJSONRender ¶ added in v1.3.0
func BytesBinding ¶ added in v1.3.2
func BytesRender ¶ added in v1.3.0
func CustomBinding ¶ added in v1.3.0
func CustomRender ¶ added in v1.3.0
func ErrorRender ¶ added in v1.3.0
func FormMultipartBinding ¶ added in v1.3.0
func FormPostBinding ¶ added in v1.3.0
func FromContext ¶
FromContext 从context获取gin.Contenxt
func HTMLRender ¶ added in v1.3.0
func HeaderBinding ¶ added in v1.3.0
func IndentedJSONRender ¶ added in v1.3.0
func JSONPJSONRender ¶ added in v1.3.0
func JSONRender ¶ added in v1.3.0
func MsgPackBinding ¶ added in v1.3.0
func MsgPackRender ¶ added in v1.3.0
func NewContext ¶
NewContext 向context注入gin.Context
func NewGRPCContext ¶ added in v1.3.0
func NewGRPCContext( ctx context.Context, headerMatcher func(key string) (string, bool), metadataAnnotators []func(ctx context.Context) metadata.MD, ) (context.Context, error)
NewGRPCContext adds context information such as metadata from the request. At a minimum, the RemoteAddr is included in the fashion of "X-Forwarded-For", except that the forwarded destination is not another HTTP service but rather a gRPC service.
func ProtoBufBinding ¶ added in v1.3.0
func ProtoBufRender ¶ added in v1.3.0
func ProtoJSONBinding ¶ added in v1.3.0
func ProtoJSONRender ¶ added in v1.3.0
func PureJSONRender ¶ added in v1.3.0
func QueryBinding ¶ added in v1.3.0
func RPCMethod ¶ added in v1.3.0
RPCMethod returns the method string for the server context. The returned string is in the format of "/package.Service/method".
func ReaderBinding ¶ added in v1.3.2
func ReaderRender ¶ added in v1.3.0
func RedirectRender ¶ added in v1.3.0
func RequestBind ¶ added in v1.3.0
func ResponseRender ¶ added in v1.3.0
func SecureJSONRender ¶ added in v1.3.0
func SetStatusCode ¶ added in v1.3.0
SetStatusCode 向context设置status code
func SetTrailer ¶ added in v1.3.0
SetTrailer 向context设置trailer
func StatusCode ¶ added in v1.3.0
StatusCode 从context获取status code
func StringBinding ¶ added in v1.3.2
func StringRender ¶ added in v1.3.0
func TOMLRender ¶ added in v1.3.0
func TextRender ¶ added in v1.3.0
Types ¶
type Error ¶ added in v1.3.0
type Error struct { // StatusCode http status code StatusCode int // Code business service code Code int // Message error message Message string }
Error 代表http状态码和业务状态
func ErrorFromMessage ¶ added in v1.3.0
type Option ¶ added in v1.3.0
type Option func(o *Options)
func ErrorHandler ¶ added in v1.3.0
func IncomingHeaderMatcher ¶ added in v1.3.0
func MetadataAnnotator ¶ added in v1.3.0
func OutgoingHeaderMatcher ¶ added in v1.3.0
func ResponseWrapper ¶ added in v1.3.0
type Options ¶ added in v1.3.0
type Options struct { Tag string ResponseWrapper func(resp any) any ErrorHandler func(ctx context.Context, err error) error IncomingHeaderMatcher func(key string) (string, bool) OutgoingHeaderMatcher func(key string) (string, bool) MetadataAnnotators []func(ctx context.Context) metadata.MD }
func NewOptions ¶ added in v1.4.3
type RichRoute ¶ added in v1.1.1
type RichRoute interface { Method() string Path() string Handlers() []gin.HandlerFunc }
RichRoute 富路由,在 Route 基础上,为路由增加了中间件功能。
func NewRichRoute ¶ added in v1.1.1
func NewRichRoute(route Route, middlewares ...gin.HandlerFunc) RichRoute
NewRichRoute 创建一个富路由
func NewRichRoutes ¶ added in v1.2.0
func NewRichRoutes(routes []Route, middlewares ...gin.HandlerFunc) []RichRoute
NewRichRoutes 创建一个多个富路由
type Route ¶
type Route interface { Method() string Path() string Handler() gin.HandlerFunc }
Route 基础路由,定义一个接口路由,包括method、path和处理器
type ServerTransportStream ¶ added in v1.3.0
type ServerTransportStream struct {
// contains filtered or unexported fields
}
ServerTransportStream implements grpc.ServerTransportStream. It should only be used by the generated files to support grpc.SendHeader outside of gRPC server use.
func NewServerTransportStream ¶ added in v1.3.0
func NewServerTransportStream(method string) *ServerTransportStream
func (*ServerTransportStream) Header ¶ added in v1.3.0
func (s *ServerTransportStream) Header() metadata.MD
Header returns the header metadata of the stream.
func (*ServerTransportStream) Method ¶ added in v1.3.0
func (s *ServerTransportStream) Method() string
func (*ServerTransportStream) SendHeader ¶ added in v1.3.0
func (s *ServerTransportStream) SendHeader(md metadata.MD) error
func (*ServerTransportStream) SetHeader ¶ added in v1.3.0
func (s *ServerTransportStream) SetHeader(md metadata.MD) error
SetHeader sets the header metadata.
func (*ServerTransportStream) SetTrailer ¶ added in v1.3.0
func (s *ServerTransportStream) SetTrailer(md metadata.MD) error
SetTrailer sets the trailer metadata.
func (*ServerTransportStream) Trailer ¶ added in v1.3.0
func (s *ServerTransportStream) Trailer() metadata.MD
Trailer returns the cached trailer metadata.