core

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CtyunEndpointName = "ctyunEndpointName"
)

Variables

This section is empty.

Functions

func GetSign

func GetSign(query string, body []byte, date string, uuid string, credential Credential) string

GetSign 加签

Types

type Credential

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

func CredentialFromEnv

func CredentialFromEnv() *Credential

CredentialFromEnv 构造新的凭证

func NewCredential

func NewCredential(ak string, sk string) *Credential

NewCredential 构造新的凭证

type CtyunClient

type CtyunClient struct {
	Config *CtyunClientConfig
	// contains filtered or unexported fields
}

func ClientForProd

func ClientForProd() *CtyunClient

ClientForProd 生产环境客户端

func ClientForTest

func ClientForTest() *CtyunClient

ClientForTest 测试环境客户端

func DefaultClient

func DefaultClient() *CtyunClient

DefaultClient 默认客户端

func NewCtyunClient

func NewCtyunClient(cfg *CtyunClientConfig) *CtyunClient

NewCtyunClient 新建客户端

func (*CtyunClient) RegisterEndpoint

func (c *CtyunClient) RegisterEndpoint(endpoint Endpoint)

RegisterEndpoint 注册端点

func (CtyunClient) RequestToEndpoint

func (c CtyunClient) RequestToEndpoint(ctx context.Context, request *CtyunRequest) (*CtyunResponse, error)

RequestToEndpoint 向端点发送请求

type CtyunClientConfig

type CtyunClientConfig struct {
	Client    *http.Client
	HttpHooks []HttpHook
}

CtyunClientConfig 自定义配置

func ClientConfigForProd

func ClientConfigForProd() *CtyunClientConfig

ClientConfigForProd 构建生产环境默认的客户端

func ClientConfigForTest

func ClientConfigForTest() *CtyunClientConfig

ClientConfigForTest 构建测试环境默认的客户端

type CtyunRequest

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

func (*CtyunRequest) AddHeader

func (c *CtyunRequest) AddHeader(key, value string) *CtyunRequest

AddHeader 增加请求头

func (*CtyunRequest) AddHeaders

func (c *CtyunRequest) AddHeaders(key string, value []string) *CtyunRequest

func (*CtyunRequest) AddParam

func (c *CtyunRequest) AddParam(key, value string) *CtyunRequest

AddParam 增加参数

func (*CtyunRequest) AddParams

func (c *CtyunRequest) AddParams(key string, value []string) *CtyunRequest

AddParams 增加参数

func (*CtyunRequest) WriteJson

func (c *CtyunRequest) WriteJson(data interface{}, contentType string) (*CtyunRequest, error)

WriteJson 以application/json方式写入

func (*CtyunRequest) WriteString

func (c *CtyunRequest) WriteString(data, contentType string) (*CtyunRequest, error)

type CtyunRequestBuilder

type CtyunRequestBuilder struct {
	EndpointName EndpointName // 终端名称
	Method       string       // 请求方法
	UrlPath      string       // url路径
	Credential   Credential   // 用户信息
	ContentType  string       // 请求类型
}

func NewCtyunRequestBuilder

func NewCtyunRequestBuilder(template CtyunRequestTemplate) *CtyunRequestBuilder

func (CtyunRequestBuilder) Build

func (c CtyunRequestBuilder) Build() *CtyunRequest

Build 构造

func (*CtyunRequestBuilder) ReplaceUrl

func (c *CtyunRequestBuilder) ReplaceUrl(src string, target interface{}) *CtyunRequestBuilder

ReplaceUrl 替换路径中的目标值,例如把/orders/{masterOrderId}替换为/orders/1

func (*CtyunRequestBuilder) WithCredential

func (c *CtyunRequestBuilder) WithCredential(credential Credential) *CtyunRequestBuilder

WithCredential 增加请求credential

func (*CtyunRequestBuilder) WithEndpointName

func (c *CtyunRequestBuilder) WithEndpointName(endpointName EndpointName) *CtyunRequestBuilder

WithEndpointName 增加请求终端名称

type CtyunRequestTemplate

type CtyunRequestTemplate struct {
	EndpointName EndpointName // 终端名称
	Method       string       // 请求方法
	UrlPath      string       // url路径
	ContentType  string
}

type CtyunResponse

type CtyunResponse struct {
	Request  *http.Request
	Response *http.Response
}

func (CtyunResponse) Parse

func (c CtyunResponse) Parse(obj interface{}) error

Parse 解析为目标对象

type Endpoint

type Endpoint struct {
	Name EndpointName // 端点的名称
	Url  string       // 对应的地址
}

type EndpointName

type EndpointName string

type EndpointRegistry

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

func DefaultEndpointRegistry

func DefaultEndpointRegistry() *EndpointRegistry

DefaultEndpointRegistry 由默认的url创建

func (EndpointRegistry) GetEndpointUrl

func (e EndpointRegistry) GetEndpointUrl(endpointName EndpointName) string

GetEndpointUrl 获取端点信息

func (*EndpointRegistry) Register

func (e *EndpointRegistry) Register(endpoint Endpoint) error

Register 注册端点

func (*EndpointRegistry) SetDefaultUrl

func (e *EndpointRegistry) SetDefaultUrl(defaultUrl string)

SetDefaultUrl 设置默认的url

type HttpHook

type HttpHook interface {
	BeforeRequest(context.Context, *http.Request)
	AfterResponse(context.Context, *http.Response)
}

type PrintLogHttpHook

type PrintLogHttpHook struct{}

func (PrintLogHttpHook) AfterResponse

func (d PrintLogHttpHook) AfterResponse(_ context.Context, response *http.Response)

func (PrintLogHttpHook) BeforeRequest

func (d PrintLogHttpHook) BeforeRequest(_ context.Context, request *http.Request)

Jump to

Keyboard shortcuts

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