protocol

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package protocol 提供了 HTTP、HTTPS、NSHead、ProtoBuffer 协议支持

Index

Constants

View Source
const HttpClientAlive time.Duration = 5 * time.Minute
View Source
const UA = "GCAL/" + gversion.VERSION + " (laya gcal http client)"

Variables

View Source
var DefaultHTTPClientFactory = func(serv service.Service) (cli *http.Client, err error) {
	var proxyURL *url.URL

	perHost := -1
	if serv.GetReuse() {
		perHost = 2
	}

	return &http.Client{
		Transport: &http.Transport{
			Proxy: http.ProxyURL(proxyURL),
			DialContext: (&net.Dialer{
				Timeout:   serv.GetConnTimeout(),
				KeepAlive: 30 * time.Second,
			}).DialContext,
			MaxIdleConnsPerHost:   perHost,
			TLSHandshakeTimeout:   10 * time.Second,
			ExpectContinueTimeout: 1 * time.Second,
		},

		Timeout: serv.GetTotalTimeout(),
	}, nil
}

DefaultHTTPClientFactory 默认的 http client factory

Functions

This section is empty.

Types

type HTTPHead

type HTTPHead struct {
	Status        string
	StatusCode    int
	Proto         string
	Header        map[string][]string
	ContentLength int64
}

HTTPHead HTTPResponse,兼容历史

type HTTPProtocol

type HTTPProtocol struct {
	RawReq *http.Request
	// contains filtered or unexported fields
}

HTTPProtocol http 协议

func NewHTTPProtocol

func NewHTTPProtocol(ctx *context.Context, serv service.Service, req *HTTPRequest, isHTTPS bool) (hp *HTTPProtocol, err error)

NewHTTPProtocol 创建一个 Http Protocol

func (*HTTPProtocol) Do

func (hp *HTTPProtocol) Do(ctx *context.Context, addr string) (rsp *Response, err error)

Do 发送请求

func (*HTTPProtocol) Protocol

func (hp *HTTPProtocol) Protocol() string

Protocol 返回类型

type HTTPRequest

type HTTPRequest struct {
	CustomAddr string

	Header      map[string][]string
	Method      string
	Body        interface{}
	Path        string
	QueryParams url.Values
	TraceId     string

	Converter converter.ConverterType
	Ctx       context.RequestContext
}

HTTPRequest http requst 对象,gcal.Cal 函数必须传递这个类型的变量

type PbRPCHead

type PbRPCHead struct {
	Header     grpcx.Header
	Meta       pbrpc.RpcMeta
	Attachment []byte
}

PbRPCHead PbRPC头

type PbRPCProtocol

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

PbRPCProtocol pbrpc 协议

func NewPbRPCProtocol

func NewPbRPCProtocol(ctx *context.Context, serv service.Service, req *PbRPCRequest) (hp *PbRPCProtocol, err error)

NewPbRPCProtocol 创建 PbRPC协议

func (*PbRPCProtocol) Do

func (hp *PbRPCProtocol) Do(ctx *context.Context, addr string) (rsp *Response, err error)

Do 执行

func (*PbRPCProtocol) Protocol

func (hp *PbRPCProtocol) Protocol() string

Protocol 返回类型

type PbRPCRequest

type PbRPCRequest struct {
	CustomAddr string
	Data       *grpcx.Package
	TraceId    string

	Ctx context.RequestContext
}

PbRPCRequest PbRpc 请求

type Protocoler

type Protocoler interface {
	Do(ctx *context.Context, addr string) (*Response, error)
	Protocol() string
}

Protocoler 协议的接口 协议本身只完成数据请求

func NewProtocol

func NewProtocol(ctx *context.Context, serv service.Service, req interface{}) (p Protocoler, err error)

NewProtocol 创建协议

type Response

type Response struct {
	// Raw []byte
	Body      interface{}
	Head      interface{}
	Request   interface{}
	OriginRsp interface{}
}

Response 通用的返回

Jump to

Keyboard shortcuts

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