server

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const ExclusivelyMetadataKey = "_wzo/transport/http/metadata"

Variables

This section is empty.

Functions

func CarrierInterceptor

func CarrierInterceptor(carrier Carrier) gin.HandlerFunc

CarrierInterceptor carrier middleware.

func MetadataInterceptor

func MetadataInterceptor(md Metadata) gin.HandlerFunc

MetadataInterceptor is used to store a `ExclusivelyMetadataKey`/Metadata pair exclusively for this `*gin.Context`.

func TransportInterceptor

func TransportInterceptor() gin.HandlerFunc

TransportInterceptor transport middleware

func UrlValues

func UrlValues(params gin.Params) url.Values

func WithValueCarrier

func WithValueCarrier(ctx context.Context, c Carrier) context.Context

WithValueCarrier returns the value associated with ctxCarrierKey is Carrier.

Types

type Carrier

type Carrier interface {
	// Bind checks the Method and Content-Type to select codec.Marshaler automatically,
	// Depending on the "Content-Type" header different bind are used.
	Bind(*gin.Context, any) error
	// BindQuery binds the passed struct pointer using the query codec.Marshaler.
	BindQuery(*gin.Context, any) error
	// BindUri binds the passed struct pointer using the uri codec.Marshaler.
	// NOTE: before use this, you should set uri params in the request context with RequestWithUri.
	BindUri(*gin.Context, any) error
	// Error encode error response.
	Error(c *gin.Context, err error)
	// Render encode response.
	Render(*gin.Context, any)
	// Validate the request.
	Validate(context.Context, any) error
}

Carrier is an HTTP Carrier. protoc-gen-wzo-gin use disable_template=true options

func FromCarrier

func FromCarrier(ctx context.Context) Carrier

FromCarrier returns the Carrier value stored in ctx, if not exist cause panic.

type Codec

type Codec struct {
	*jsonpb.Codec
}

Codec is a Marshaler which marshals/unmarshals into/from JSON/ marshals use encoding/json unmarshals use google.golang.org/protobuf/encoding/protojson

func (*Codec) ContentType

func (*Codec) ContentType(_ interface{}) string

ContentType always Returns "application/json; charset=utf-8".

func (*Codec) Delimiter

func (c *Codec) Delimiter() []byte

func (*Codec) Marshal

func (*Codec) Marshal(v interface{}) ([]byte, error)

func (*Codec) NewDecoder

func (c *Codec) NewDecoder(r io.Reader) codec.Decoder

func (*Codec) NewEncoder

func (c *Codec) NewEncoder(w io.Writer) codec.Encoder

func (*Codec) Unmarshal

func (c *Codec) Unmarshal(data []byte, v interface{}) error

type Context

type Context struct {
	*gin.Context
}

func (*Context) GetError

func (c *Context) GetError() error

func (*Context) SetError

func (c *Context) SetError(err error)

func (*Context) ShouldBind

func (c *Context) ShouldBind(v any) error

func (*Context) ShouldBindQuery

func (c *Context) ShouldBindQuery(v any) error

func (*Context) ShouldBindUri

func (c *Context) ShouldBindUri(v any) error

func (*Context) String

func (c *Context) String(code int, format string, values ...any)

type HandlerFunc

type HandlerFunc func(*Context)

type InitHttpServerFunc

type InitHttpServerFunc func(r *Server) error

type Metadata

type Metadata struct {
	Service string
	Method  string
}

func GetMetadata

func GetMetadata(c *gin.Context) (md Metadata, ok bool)

GetMetadata returns the Metadata value stored in `*gin.Context`, if any.

func MustGetMetadata

func MustGetMetadata(c *gin.Context) Metadata

MustGetMetadata returns the Metadata value stored in `*gin.Context`.

type Option

type Option func(*Options)

func Addr

func Addr(s string) Option

func InitHttpServer

func InitHttpServer(f InitHttpServerFunc) Option

func Mode

func Mode(s string) Option

func Name

func Name(s string) Option

func Registry

func Registry(r registry.Registry) Option

func Tracing

func Tracing(b bool) Option

type Options

type Options struct {
	Name           string
	Addr           string
	InitHttpServer InitHttpServerFunc
	Mode           string
	Tracing        bool
	Registry       registry.Registry
}

type Server

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

func NewServer

func NewServer(opts ...Option) *Server

func (*Server) AnyEx

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

func (*Server) DeleteEx

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

func (*Server) GetEx

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

func (*Server) GroupEx

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

func (*Server) HandleEx

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

func (*Server) HeadEx

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

func (*Server) Init

func (s *Server) Init(opts ...Option)

func (*Server) MatchEx

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

func (*Server) OptionsEx

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

func (*Server) PatchEx

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

func (*Server) PostEx

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

func (*Server) PutEx

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

func (*Server) Start

func (s *Server) Start() error

func (*Server) Stop

func (s *Server) Stop() error

func (*Server) UseEx

func (s *Server) UseEx(middlewares ...HandlerFunc)

type Transport

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

Transport is an HTTP transport.

func (*Transport) ClientIp

func (tr *Transport) ClientIp() string

ClientIp Service full method or path

func (*Transport) FullPath

func (tr *Transport) FullPath() string

FullPath Service full method or path

func (*Transport) GinContext

func (tr *Transport) GinContext() *gin.Context

GinContext Service gin context

func (*Transport) Kind

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

Kind returns the transport kind.

func (*Transport) Method

func (tr *Transport) Method() string

Method Service http method

func (*Transport) RequestHeader

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

RequestHeader return transport request header http: http.Header grpc: metadata.MD

func (*Transport) ResponseHeader

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

ResponseHeader return transport response header http: http.Header grpc: metadata.MD

func (*Transport) Route

func (tr *Transport) Route() string

Route Service full route

type Transporter

type Transporter interface {
	transport.Transporter
	Method() string
	Route() string
	GinContext() *gin.Context
}

Transporter is http Transporter

Directories

Path Synopsis
middleware

Jump to

Keyboard shortcuts

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