http

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CarrierInterceptor added in v0.5.0

func CarrierInterceptor(carrier Carrier) gin.HandlerFunc

CarrierInterceptor carrier middleware.

func TransportInterceptor

func TransportInterceptor() gin.HandlerFunc

TransportInterceptor transport middleware

func UrlValues added in v0.9.0

func UrlValues(params gin.Params) url.Values

func WithValueCallOption added in v0.4.4

func WithValueCallOption(ctx context.Context, cs CallSettings) context.Context

WithValueCallOption returns a new Context that carries value.

func WithValueCarrier added in v0.5.0

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

WithValueCarrier returns the value associated with ctxCarrierKey is Carrier.

func WithValueUri deprecated added in v0.4.1

func WithValueUri(req *http.Request, params gin.Params) *http.Request

Deprecated: Because BindUri is deprecated.

Types

type CallOption added in v0.4.4

type CallOption func(cs *CallSettings)

CallOption is an option used by Invoke to control behaviors of RPC calls. CallOption works by modifying relevant fields of CallSettings.

func WithCoAccept added in v0.8.0

func WithCoAccept(accept string) CallOption

WithCoAccept use encoding.MIMExxx

func WithCoContentType added in v0.4.4

func WithCoContentType(contentType string) CallOption

WithCoContentType use encoding.MIMExxx

func WithCoHeader added in v0.4.4

func WithCoHeader(k, v string) CallOption

WithCoHeader

func WithCoNoAuth added in v0.4.4

func WithCoNoAuth() CallOption

WithCoNoAuth

func WithCoPath added in v0.4.4

func WithCoPath(path string) CallOption

WithCoPath

type CallSettings added in v0.4.4

type CallSettings struct {

	// Path overwrite api call
	Path string
	// contains filtered or unexported fields
}

CallSettings allow fine-grained control over how calls are made.

func DefaultCallOption deprecated added in v0.4.4

func DefaultCallOption(path string, opts ...CallOption) CallSettings

Deprecated: use Client.CallSetting(path string, opts ...CallOption) instead.

func FromValueCallOption added in v0.4.4

func FromValueCallOption(ctx context.Context) (cs CallSettings, ok bool)

FromValueCallOption returns the CallSettings value stored in ctx, if any.

func MustFromValueCallOption added in v0.4.4

func MustFromValueCallOption(ctx context.Context) CallSettings

MustFromValueCallOption returns the CallSettings value stored in ctx.

type Carrier added in v0.5.0

type Carrier interface {
	// WithValueUri sets the URL params for the given request.
	//
	// Deprecated: Use BindURI not need this.
	WithValueUri(*http.Request, gin.Params) *http.Request
	// 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.
	BindUri(*gin.Context, any) error
	// Error encode error response.
	Error(*gin.Context, error)
	// Render encode response.
	Render(*gin.Context, any)
	// Validate the request.
	Validate(context.Context, any) error
}

Carrier is an HTTP Carrier.

func FromCarrier added in v0.5.0

func FromCarrier(ctx context.Context) Carrier

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

type Client added in v0.4.4

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

func NewClient added in v0.4.4

func NewClient(opts ...ClientOption) *Client

func (*Client) CallSetting added in v0.8.0

func (c *Client) CallSetting(path string, cos ...CallOption) *CallSettings

func (*Client) Delete added in v0.4.5

func (c *Client) Delete(ctx context.Context, path string, req, resp any, opts ...CallOption) error

Delete method does DELETE HTTP request. It's defined in section 4.3.5 of RFC7231.

func (*Client) Deref added in v0.4.5

func (c *Client) Deref() *resty.Client

func (*Client) EncodeQuery added in v0.4.4

func (c *Client) EncodeQuery(v any) (string, error)

EncodeQuery encode v into “URL encoded” form ("bar=baz&foo=quux") sorted by key.

func (*Client) EncodeURL added in v0.4.4

func (c *Client) EncodeURL(pathTemplate string, msg any, needQuery bool) string

EncodeURL encode msg to url path. pathTemplate is a template of url path like http://helloworld.dev/{name}/sub/{sub.name}.

func (*Client) Execute added in v0.4.5

func (c *Client) Execute(ctx context.Context, method, path string, req, resp any, opts ...CallOption) error

func (*Client) Get added in v0.4.5

func (c *Client) Get(ctx context.Context, path string, req, resp any, opts ...CallOption) error

Get method does GET HTTP request. It's defined in section 4.3.1 of RFC7231.

func (*Client) Head added in v0.4.5

func (c *Client) Head(ctx context.Context, path string, req, resp any, opts ...CallOption) error

Head method does HEAD HTTP request. It's defined in section 4.3.2 of RFC7231.

func (*Client) Invoke added in v0.4.4

func (c *Client) Invoke(ctx context.Context, method, path string, in, out any, settings *CallSettings) error

Invoke the request NOTE: Do not use this function. use Execute instead.

func (*Client) Options added in v0.4.5

func (c *Client) Options(ctx context.Context, path string, req, resp any, opts ...CallOption) error

Options method does OPTIONS HTTP request. It's defined in section 4.3.7 of RFC7231.

func (*Client) Patch added in v0.4.5

func (c *Client) Patch(ctx context.Context, path string, req, resp any, opts ...CallOption) error

Patch method does PATCH HTTP request. It's defined in section 2 of RFC5789.

func (*Client) Post added in v0.4.5

func (c *Client) Post(ctx context.Context, path string, req, resp any, opts ...CallOption) error

Post method does POST HTTP request. It's defined in section 4.3.3 of RFC7231.

func (*Client) Put added in v0.4.5

func (c *Client) Put(ctx context.Context, path string, req, resp any, opts ...CallOption) error

Put method does PUT HTTP request. It's defined in section 4.3.4 of RFC7231.

type ClientOption added in v0.4.4

type ClientOption func(*Client)

func WithCallOption added in v0.8.0

func WithCallOption(cs ...CallOption) ClientOption

func WithEncoding added in v0.4.4

func WithEncoding(codec *encoding.Encoding) ClientOption

func WithNoAuth deprecated added in v0.4.4

func WithNoAuth() ClientOption

Deprecated: use WithCallOption(WithCoNoAuth) instead.

func WithTokenSource added in v0.4.4

func WithTokenSource(t oauth2.TokenSource) ClientOption

func WithValidate added in v0.4.4

func WithValidate(f func(any) error) ClientOption

type ErrorReply added in v0.4.4

type ErrorReply struct {
	Code   int
	Body   []byte
	Header http.Header
}

func (*ErrorReply) Error added in v0.4.4

func (e *ErrorReply) Error() string

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

Jump to

Keyboard shortcuts

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