restv2

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: GPL-3.0 Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultMiddleware = &BaseMiddleware{}

DefaultMiddleware 默认中间件

Functions

This section is empty.

Types

type BaseMiddleware added in v0.6.0

type BaseMiddleware struct {
	Marshaler   Marshaler
	Unmarshaler Unmarshaler
}

BaseMiddleware 基础中间件

func (*BaseMiddleware) NewRequest added in v0.6.0

func (m *BaseMiddleware) NewRequest(rule giraffe.HttpRule, in interface{}) (*http.Request, error)

NewRequest 创建 http.Request 方法

func (*BaseMiddleware) ParseResponse added in v0.6.0

func (m *BaseMiddleware) ParseResponse(rule giraffe.HttpRule, resp *http.Response, out interface{}) error

ParseResponse 解析 http.Response 方法

type Client

type Client struct {
	*http.Client
	Middleware  Middleware
	NameService giraffe.NameService

	Scheme string
	// contains filtered or unexported fields
}

Client REST Client对象

func NewClient

func NewClient(opts ...ClientOption) *Client

NewClient Client实例化函数

func (*Client) Call

func (c *Client) Call(contract giraffe.Contract, req *http.Request, opts ...giraffe.CallOption) (*http.Response, error)

Call 请求函数

func (*Client) Invoke

func (c *Client) Invoke(ctx context.Context, md *giraffe.MethodDesc, in interface{}, out interface{}, opts ...giraffe.CallOption) error

Invoke 单次请求方法

func (*Client) NewStream

func (c *Client) NewStream(context.Context, *giraffe.StreamDesc, ...giraffe.CallOption) (giraffe.ClientStream, error)

NewStream 流式请求方法(未实现)

type ClientOption added in v0.5.2

type ClientOption func(c *Client)

ClientOption Client 配置函数

func WithClient added in v0.5.2

func WithClient(client *http.Client) ClientOption

WithClient 注入 http.Client

func WithNameService added in v0.5.2

func WithNameService(n giraffe.NameService) ClientOption

WithNameService 注入 NameService

func WithRetryConfig added in v1.0.1

func WithRetryConfig(conf RetryConfig) ClientOption

func WithScheme added in v1.0.5

func WithScheme(scheme string) ClientOption

type Marshaler added in v0.6.0

type Marshaler interface {
	Marshal(out io.Writer, pb proto.Message) error
}

Marshaler 序列化接口

type Middleware

type Middleware interface {
	NewRequest(rule giraffe.HttpRule, in interface{}) (*http.Request, error)
	ParseResponse(rule giraffe.HttpRule, resp *http.Response, out interface{}) error
}

Middleware 中间件定义

type RPCRetryConfig added in v1.0.1

type RPCRetryConfig map[string]RetryConfig

type RetryConfig added in v1.0.1

type RetryConfig struct {
	Enabled                  bool          `json:"enabled" yaml:"enabled"`
	Retries                  uint8         `json:"retries" yaml:"retries"`
	RetryIntervalMilliSecond int64         `json:"retry_interval_millisecond" yaml:"retry_interval_millisecond"`
	RetryInterval            time.Duration `json:"-" yaml:"-"`
}

type StaticAddress

type StaticAddress string

func (StaticAddress) GetAddress

func (s StaticAddress) GetAddress(ctx context.Context, contract giraffe.Contract) (string, error)

func (StaticAddress) GetAllAddresses

func (s StaticAddress) GetAllAddresses(ctx context.Context, contract giraffe.Contract) ([]string, error)

type Unmarshaler added in v0.6.0

type Unmarshaler interface {
	Unmarshal(r io.Reader, pb proto.Message) error
}

Unmarshaler 反序列化接口

Jump to

Keyboard shortcuts

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