common

package
v0.2.43 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: Apache-2.0 Imports: 21 Imported by: 12

Documentation

Index

Constants

View Source
const (
	JsonParseError         = "JSON_PARSE_FAILED"
	NetworkError           = "NETWORK_ERROR"
	CredentialMissingError = "CREDENTIAL_VALUE_MISSING"
	IoError                = "IO_ERROR"
)
View Source
const (
	POST = "POST"
	GET  = "GET"

	HTTP   = "http"
	HTTPS  = "https"
	DOMAIN = "console.zenlayer.com"
)
View Source
const SdkLang = "go"

Variables

This section is empty.

Functions

func Bool

func Bool(v bool) *bool

func ExponentialBackoff added in v0.2.43

func ExponentialBackoff(index int) time.Duration

ExponentialBackoff returns exponentially increasing durations: 1s, 2s, 4s, 8s, ...

func Float64

func Float64(v float64) *float64

func GetUrlQueriesEncoded

func GetUrlQueriesEncoded(params map[string]string) string

func InitStructWithDefaultTag

func InitStructWithDefaultTag(bean interface{})

func Int64

func Int64(v int64) *int64

func Integer

func Integer(v int) *int

func NewZenlayerCloudSdkError

func NewZenlayerCloudSdkError(code, message, requestId string) error

func ParseFromHttpResponse

func ParseFromHttpResponse(hr *http.Response, response Response) (err error)

func String

func String(v string) *string

func ToBool added in v0.2.4

func ToBool(v *bool) bool

func ToFloat64 added in v0.2.4

func ToFloat64(v *float64) float64

func ToInt64 added in v0.2.4

func ToInt64(v *int64) int64

func ToInteger added in v0.2.4

func ToInteger(v *int) int

func ToString added in v0.2.4

func ToString(v *string) string

func ToUint added in v0.2.4

func ToUint(v *uint) uint

func ToUint64 added in v0.2.4

func ToUint64(v *uint64) uint64

func Uint

func Uint(v uint) *uint

func Uint64

func Uint64(v uint64) *uint64

Types

type BaseRequest

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

func (*BaseRequest) GetAction

func (br *BaseRequest) GetAction() string

func (*BaseRequest) GetApiVersion

func (br *BaseRequest) GetApiVersion() string

func (*BaseRequest) GetAutoRetries

func (br *BaseRequest) GetAutoRetries() bool

func (*BaseRequest) GetBody

func (br *BaseRequest) GetBody() []byte

func (*BaseRequest) GetBodyReader

func (br *BaseRequest) GetBodyReader() io.Reader

func (*BaseRequest) GetBodyStr

func (br *BaseRequest) GetBodyStr() string

func (*BaseRequest) GetContentType

func (br *BaseRequest) GetContentType() string

func (*BaseRequest) GetContext added in v0.2.43

func (br *BaseRequest) GetContext() context.Context

GetContext returns the context associated with this request. It defaults to context.Background() when no context has been set, so callers can always rely on a non-nil context.

func (*BaseRequest) GetDomain

func (br *BaseRequest) GetDomain() string

func (*BaseRequest) GetFormParams

func (br *BaseRequest) GetFormParams() map[string]string

func (*BaseRequest) GetHeaders

func (br *BaseRequest) GetHeaders() map[string]string

func (*BaseRequest) GetHttpMethod

func (br *BaseRequest) GetHttpMethod() string

func (*BaseRequest) GetMaxAttempts

func (br *BaseRequest) GetMaxAttempts() int

func (*BaseRequest) GetParams

func (br *BaseRequest) GetParams() map[string]string

func (*BaseRequest) GetPath

func (br *BaseRequest) GetPath() string

func (*BaseRequest) GetScheme

func (br *BaseRequest) GetScheme() string

func (*BaseRequest) GetServiceName

func (br *BaseRequest) GetServiceName() string

func (*BaseRequest) GetUrl

func (br *BaseRequest) GetUrl() string

func (*BaseRequest) Init

func (br *BaseRequest) Init() *BaseRequest

func (*BaseRequest) InitWithApiInfo

func (br *BaseRequest) InitWithApiInfo(serviceName, apiVersion, action string)

func (*BaseRequest) SetAutoRetries

func (br *BaseRequest) SetAutoRetries(autoRetires bool)

func (*BaseRequest) SetBody

func (br *BaseRequest) SetBody(body []byte)

func (*BaseRequest) SetContentType

func (br *BaseRequest) SetContentType(contentType string)

func (*BaseRequest) SetContext added in v0.2.43

func (br *BaseRequest) SetContext(ctx context.Context)

SetContext binds a context to this request. The context is used to control the lifecycle (timeout / cancellation / value propagation) of the underlying HTTP call made by the client.

func (*BaseRequest) SetDomain

func (br *BaseRequest) SetDomain(domain string)

func (*BaseRequest) SetHeaders

func (br *BaseRequest) SetHeaders(headers map[string]string)

func (*BaseRequest) SetMaxAttempts

func (br *BaseRequest) SetMaxAttempts(maxAttempts int)

func (*BaseRequest) SetPath

func (br *BaseRequest) SetPath(path string)

func (*BaseRequest) SetScheme

func (br *BaseRequest) SetScheme(scheme string)

func (*BaseRequest) SetServiceName

func (br *BaseRequest) SetServiceName(serviceName string)

func (*BaseRequest) WithContext added in v0.2.43

func (br *BaseRequest) WithContext(ctx context.Context) *BaseRequest

WithContext is a chainable variant of SetContext.

type BaseResponse

type BaseResponse struct {
}

func (*BaseResponse) ParseErrorResponse

func (r *BaseResponse) ParseErrorResponse(body []byte) (err error)

type Client

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

func (*Client) ApiCall

func (c *Client) ApiCall(request Request, response Response) (err error)

func (*Client) InitWithCredential

func (c *Client) InitWithCredential(credential *Credential) (err error)

InitWithCredential initializes the client with HMAC-SHA256 signing credentials.

func (*Client) InitWithTokenCredential added in v0.2.37

func (c *Client) InitWithTokenCredential(credential *TokenCredential) (err error)

InitWithTokenCredential initializes the client with a Bearer token credential.

func (*Client) WithConfig

func (c *Client) WithConfig(config *Config) error

func (*Client) WithCredential added in v0.2.37

func (c *Client) WithCredential(credential CredentialIface) *Client

WithCredential sets the credential on the client and returns the client for chaining. Accepts any CredentialIface implementation (Credential or TokenCredential).

func (*Client) WithRequestClient added in v0.1.3

func (c *Client) WithRequestClient(rc string) *Client

type Config

type Config struct {
	AutoRetry     bool `default:"false"`
	MaxRetryTime  int  `default:"3"`
	RetryDuration time.Duration
	HttpTransport *http.Transport   `default:""`
	Transport     http.RoundTripper `default:""`
	Proxy         string            `default:""`
	Scheme        string            `default:"HTTPS"`
	Domain        string            `default:""`
	// timeout in seconds
	Timeout int `default:"300"`
	Debug   *bool

	// RateLimitExceededMaxRetries defines the maximum number of retries when rate limit is exceeded.
	RateLimitExceededMaxRetries int `default:"3"`
	// RateLimitExceededRetryDuration determines the wait duration between rate limit retries.
	// Defaults to ExponentialBackoff if nil.
	RateLimitExceededRetryDuration DurationFunc
}

func NewConfig

func NewConfig() (config *Config)

func (*Config) WithAutoRetry

func (c *Config) WithAutoRetry(isAutoRetry bool) *Config

func (*Config) WithHttpTransport

func (c *Config) WithHttpTransport(httpTransport *http.Transport) *Config

func (*Config) WithMaxRetryTime

func (c *Config) WithMaxRetryTime(maxRetryTime int) *Config

func (*Config) WithRateLimitRetry added in v0.2.43

func (c *Config) WithRateLimitRetry(maxRetries int, durationFunc DurationFunc) *Config

func (*Config) WithScheme

func (c *Config) WithScheme(scheme string) *Config

func (*Config) WithTimeout

func (c *Config) WithTimeout(timeout int) *Config

type Credential

type Credential struct {
	SecretKeyId       string
	SecretKeyPassword string
}

Credential authenticates via HMAC-SHA256 request signing.

func NewCredential

func NewCredential(secretKeyId, secretKeyPassword string) *Credential

func (*Credential) GetSecretKeyId

func (c *Credential) GetSecretKeyId() string

func (*Credential) GetSecretKeyPassword

func (c *Credential) GetSecretKeyPassword() string

func (*Credential) GetToken added in v0.2.37

func (c *Credential) GetToken() string

type CredentialIface

type CredentialIface interface {
	GetSecretKeyId() string
	GetSecretKeyPassword() string
	GetToken() string
}

CredentialIface is the common interface for all credential types. Implementations: Credential (HMAC signing), TokenCredential (Bearer token).

type DurationFunc added in v0.2.43

type DurationFunc func(index int) time.Duration

DurationFunc determines how long to wait between retries given the retry index.

type ErrorResponse

type ErrorResponse struct {
	RequestId string `json:"requestId"`
	Code      string `json:"code"`
	Message   string `json:"message"`
}

type Request

type Request interface {
	GetScheme() string
	GetHttpMethod() string
	GetDomain() string
	GetAction() string
	GetBodyReader() io.Reader
	GetParams() map[string]string
	GetFormParams() map[string]string
	GetBody() []byte
	GetPath() string
	GetUrl() string
	GetContentType() string
	GetHeaders() map[string]string
	GetApiVersion() string
	GetServiceName() string
	GetMaxAttempts() int
	GetAutoRetries() bool
	GetBodyStr() string
	GetContext() context.Context
	SetContext(context.Context)
	SetScheme(string)
	SetDomain(string)
	SetPath(string)
	SetContentType(string)
	SetHeaders(headers map[string]string)
	SetServiceName(string)
	SetBody([]byte)
	SetAutoRetries(bool)
	SetMaxAttempts(int)
}

type Response

type Response interface {
	ParseErrorResponse(body []byte) error
}

type TokenCredential added in v0.2.37

type TokenCredential struct {
	Token string
}

TokenCredential authenticates via a Bearer token (Authorization: Bearer <token>).

func NewTokenCredential added in v0.2.37

func NewTokenCredential(token string) *TokenCredential

func (*TokenCredential) GetSecretKeyId added in v0.2.37

func (c *TokenCredential) GetSecretKeyId() string

func (*TokenCredential) GetSecretKeyPassword added in v0.2.37

func (c *TokenCredential) GetSecretKeyPassword() string

func (*TokenCredential) GetToken added in v0.2.37

func (c *TokenCredential) GetToken() string

type ZenlayerCloudSdkError

type ZenlayerCloudSdkError struct {
	Code      string
	Message   string
	RequestId string
}

func (*ZenlayerCloudSdkError) Error

func (e *ZenlayerCloudSdkError) Error() string

func (*ZenlayerCloudSdkError) GetCode

func (e *ZenlayerCloudSdkError) GetCode() string

func (*ZenlayerCloudSdkError) GetMessage

func (e *ZenlayerCloudSdkError) GetMessage() string

func (*ZenlayerCloudSdkError) GetRequestId

func (e *ZenlayerCloudSdkError) GetRequestId() string

Jump to

Keyboard shortcuts

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