Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateInnerLogger(logFileName, isJsonType, logMaxSize, logFileBackupCount, allowLogLevel string) log.Logger
- func IsDebugLevelMatched(level int) bool
- func IsTokenError(err error) bool
- func Retry(ctx context.Context, o backoff.Operation) error
- func RetryWithAttempt(ctx context.Context, maxAttempt int, o ConditionOperation) error
- func RetryWithBackOff(ctx context.Context, b backoff.BackOff, o backoff.Operation) error
- func RetryWithCondition(ctx context.Context, b backoff.BackOff, o ConditionOperation) error
- type AuthVersionType
- type AutoRetryClient
- func (c *AutoRetryClient) Close() error
- func (c *AutoRetryClient) RegisterCallbakUrl(url, method, operate string) (prj *ChatProject, err error)
- func (c *AutoRetryClient) ResetAccessKeyToken(xApiKey string)
- func (c *AutoRetryClient) SendChatMsg(toUserId, groupId, message, operate string) (prj *ChatProject, err error)
- func (c *AutoRetryClient) SendRobotGroupMsg(toUserId, groupId, title, content, message, objectName, operate, href string) (prj *ChatProject, err error)
- func (c *AutoRetryClient) SendRobotMsg(toUserId, message, objectName, operate string) (prj *ChatProject, err error)
- func (c *AutoRetryClient) SetAuthVersion(version AuthVersionType)
- func (c *AutoRetryClient) SetHTTPClient(client *http.Client)
- func (c *AutoRetryClient) SetUserAgent(userAgent string)
- type BadResponseError
- type ChatProject
- func (p *ChatProject) RawRequest(method, uri string, headers map[string]string, body []byte) (*http.Response, error)
- func (p *ChatProject) WithRequestTimeout(timeout time.Duration) *ChatProject
- func (p *ChatProject) WithRetryTimeout(timeout time.Duration) *ChatProject
- func (p *ChatProject) WithToken(token string) (*ChatProject, error)
- type Client
- func (c *Client) Close() error
- func (c *Client) RegisterCallbakUrl(url, method, operate string) (*ChatProject, error)
- func (c *Client) ResetAccessKeyToken(xApiKey string)
- func (c *Client) SendChatMsg(toUserId, groupId, message, opreate string) (*ChatProject, error)
- func (c *Client) SendRobotGroupMsg(toUserId, groupId, title, content, message, objectName, operate, href string) (*ChatProject, error)
- func (c *Client) SendRobotMsg(toUserId, message, objectName, opreate string) (*ChatProject, error)
- func (c *Client) SetAuthVersion(version AuthVersionType)
- func (c *Client) SetHTTPClient(client *http.Client)
- func (c *Client) SetUserAgent(userAgent string)
- type ClientInterface
- type ConditionOperation
- type Error
- type Signer
- type SignerV1
- type SignerV4
- type UpdateTokenFunction
Constants ¶
const ( // RequestIDHeader stands for the requestID in all response RequestIDHeader = "x-Chat-requestid" GetChatQueryInfo = "X-Chat-Query-Info" )
const ( HTTPHeaderAuthorization = "Authorization" HTTPHeaderContentMD5 = "Content-MD5" HTTPHeaderContentType = "Content-Type" HTTPHeaderContentLength = "Content-Length" HTTPHeaderDate = "Date" HTTPHeaderHost = "Host" HTTPHeaderUserAgent = "User-Agent" HTTPHeaderAPIVersion = "x-chat-apiversion" HTTPHeaderSignatureMethod = "x-chat-signaturemethod" HTTPHeaderBodyRawSize = "x-chat-bodyrawsize" ISO8601 = "20060102T150405Z" )
const BAD_REQUEST = "BadRequest"
const CONFIG_ALREADY_EXIST = "ConfigAlreadyExist"
const CONFIG_NOT_EXIST = "ConfigNotExist"
const DefaultLogUserAgent = "golang-sdk-v0.1.0"
const GROUP_ALREADY_EXIST = "GroupAlreadyExist"
const GROUP_NOT_EXIST = "GroupNotExist"
const INTERNAL_SERVER_ERROR = "InternalServerError"
const INVALID_API_VERSION = "InvalidAPIVersion"
const INVALID_BODY_RAW_SIZE = "InvalidBodyRawSize"
const INVALID_COMPRESS_TYPE = "InvalidCompressType"
const INVALID_CONTENT_TYPE = "InvalidContentType"
const INVALID_CURSOR = "InvalidCursor"
const INVALID_DATE_FORMAT = "InvalidDateFormat"
const INVALID_ENCODING = "InvalidEncoding"
const INVALID_KEY = "InvalidKey"
const INVALID_LINE = "InvalidLine"
const INVALID_OFFSET = "InvalidOffset"
const INVALID_PARAMETER = "InvalidParameter"
const INVALID_QUERY_STRING = "InvalidQueryString"
const INVALID_REVERSE = "InvalidReverse"
const INVALID_SIGNATURE_METHOD = "InvalidSignatureMethod"
const INVALID_TIMESTAMP = "InvalidTimestamp"
const INVALID_TIME_RANGE = "InvalidTimeRange"
const MISSING_API_VERSION = "MissingAPIVersion"
const MISSING_BODY_RAW_SIZE = "MissingBodyRawSize"
const MISSING_CONTENT_LENGTH = "MissingContentLength"
const MISSING_CONTENT_TYPE = "MissingContentType"
const MISSING_DATE = "MissingDate"
const MISSING_HOST = "MissingHost"
const MISSING_SIGNATURE_METHOD = "MissingSignatureMethod"
const MISS_ACCESS_KEY_ID = "MissAccessKeyId"
const PARAMETER_INVALID = "ParameterInvalid"
const POST_BODY_INVALID = "PostBodyInvalid"
const POST_BODY_TOO_LARGE = "PostBodyTooLarge"
const POST_BODY_UNCOMPRESS_ERROR = "PostBodyUncompressError"
const PROJECT_FORBIDDEN = "ProjectForbidden"
const PROJECT_NOT_EXIST = "ProjectNotExist"
const PROJECT_QUOTA_EXCEED = "ProjectQuotaExceed"
const READ_QUOTA_EXCEED = "ReadQuotaExceed"
const REQUEST_TIME_TOO_SKEWED = "RequestTimeTooSkewed"
const SERVER_BUSY = "ServerBusy"
const SHARD_NOT_EXIST = "ShardNotExist"
const SHARD_READ_QUOTA_EXCEED = "ShardReadQuotaExceed"
const SHARD_WRITE_QUOTA_EXCEED = "ShardWriteQuotaExceed"
const SHIPPER_NOT_EXIST = "ShipperNotExist"
const SIGNATURE_NOT_MATCH = "SignatureNotMatch"
const UN_AUTHORIZED = "Unauthorized"
const WRITE_QUOTA_EXCEED = "WriteQuotaExceed"
Variables ¶
var GlobalDebugLevel = 0
var GlobalForceUsingHTTP = false
GlobalForceUsingHTTP if GlobalForceUsingHTTP is true, then all request will use HTTP(ignore LogProject's UsingHTTP flag)
var InvalidCompressError = errors.New("Invalid Compress Type")
var Logger = initDefaultSLSLogger()
var MaxCompletedRetryCount = 20
var MaxCompletedRetryLatency = 5 * time.Minute
var RetryOnServerErrorEnabled = true
RetryOnServerErrorEnabled if RetryOnServerErrorEnabled is false, then all error requests will not be retried
Functions ¶
func GenerateInnerLogger ¶
func IsDebugLevelMatched ¶
func IsTokenError ¶
func Retry ¶
Retry execute the input operation immediately at first, and do an exponential backoff retry when failed. The default max elapsed time is 15 minutes. The default retry intervals are shown below, in seconds.
1 0.5 [0.25, 0.75] 2 0.75 [0.375, 1.125] 3 1.125 [0.562, 1.687] 4 1.687 [0.8435, 2.53] 5 2.53 [1.265, 3.795] 6 3.795 [1.897, 5.692] 7 5.692 [2.846, 8.538] 8 8.538 [4.269, 12.807] 9 12.807 [6.403, 19.210]
... The signature of backoff.Operation is "func() error".
func RetryWithAttempt ¶
func RetryWithAttempt(ctx context.Context, maxAttempt int, o ConditionOperation) error
RetryWithAttempt ...
func RetryWithBackOff ¶
RetryWithBackOff ...
func RetryWithCondition ¶
RetryWithCondition ...
Types ¶
type AuthVersionType ¶
type AuthVersionType string
AuthVersionType the version of auth
const ( // AuthV1 v1 AuthV1 AuthVersionType = "v1" )
type AutoRetryClient ¶
type AutoRetryClient struct {
// contains filtered or unexported fields
}
func (*AutoRetryClient) Close ¶
func (c *AutoRetryClient) Close() error
func (*AutoRetryClient) RegisterCallbakUrl ¶
func (c *AutoRetryClient) RegisterCallbakUrl(url, method, operate string) (prj *ChatProject, err error)
func (*AutoRetryClient) ResetAccessKeyToken ¶
func (c *AutoRetryClient) ResetAccessKeyToken(xApiKey string)
func (*AutoRetryClient) SendChatMsg ¶
func (c *AutoRetryClient) SendChatMsg(toUserId, groupId, message, operate string) (prj *ChatProject, err error)
func (*AutoRetryClient) SendRobotGroupMsg ¶
func (c *AutoRetryClient) SendRobotGroupMsg(toUserId, groupId, title, content, message, objectName, operate, href string) (prj *ChatProject, err error)
func (*AutoRetryClient) SendRobotMsg ¶
func (c *AutoRetryClient) SendRobotMsg(toUserId, message, objectName, operate string) (prj *ChatProject, err error)
func (*AutoRetryClient) SetAuthVersion ¶
func (c *AutoRetryClient) SetAuthVersion(version AuthVersionType)
SetAuthVersion set auth version that the client used
func (*AutoRetryClient) SetHTTPClient ¶
func (c *AutoRetryClient) SetHTTPClient(client *http.Client)
SetHTTPClient set a custom http client, all request will send to sls by this client
func (*AutoRetryClient) SetUserAgent ¶
func (c *AutoRetryClient) SetUserAgent(userAgent string)
type BadResponseError ¶
BadResponseError : special sls error, not valid json format
func NewBadResponseError ¶
func NewBadResponseError(body string, header map[string][]string, httpCode int) *BadResponseError
NewBadResponseError ...
func (BadResponseError) Error ¶
func (e BadResponseError) Error() string
func (BadResponseError) String ¶
func (e BadResponseError) String() string
type ChatProject ¶
type ChatProject struct { Name string `json:"projectName"` // Project name Description string `json:"description"` // Project description Status string `json:"status"` // Normal Owner string `json:"owner"` // empty Region string `json:"region"` // region CreateTime string `json:"createTime"` // unix time seconds, eg 1524539357 LastModifyTime string `json:"lastModifyTime"` // unix time seconds, eg 1524539357 Endpoint string // IP or hostname of endpoint XApiKey string SecurityToken string UsingHTTP bool // default https UserAgent string // default defaultLogUserAgent AuthVersion AuthVersionType // contains filtered or unexported fields }
ChatProject defines chat project
func NewChatProject ¶
func NewChatProject(name, endpoint, xApiKey string) (p *ChatProject, err error)
NewLogProject creates a new SLS project.
func (*ChatProject) RawRequest ¶
func (p *ChatProject) RawRequest(method, uri string, headers map[string]string, body []byte) (*http.Response, error)
RawRequest send raw http request to LogService and return the raw http response @note you should call http.Response.Body.Close() to close body stream
func (*ChatProject) WithRequestTimeout ¶
func (p *ChatProject) WithRequestTimeout(timeout time.Duration) *ChatProject
WithRequestTimeout with custom timeout for a request
func (*ChatProject) WithRetryTimeout ¶
func (p *ChatProject) WithRetryTimeout(timeout time.Duration) *ChatProject
WithRetryTimeout with custom timeout for a operation each operation may send one or more HTTP requests in case of retry required.
func (*ChatProject) WithToken ¶
func (p *ChatProject) WithToken(token string) (*ChatProject, error)
WithToken add token parameter
type Client ¶
type Client struct { Endpoint string // IP or hostname of SLS endpoint XApiKey string UserAgent string // default defaultLogUserAgent RequestTimeOut time.Duration RetryTimeOut time.Duration HTTPClient *http.Client //Region string AuthVersion AuthVersionType // contains filtered or unexported fields }
Client ...
func (*Client) RegisterCallbakUrl ¶
func (c *Client) RegisterCallbakUrl(url, method, operate string) (*ChatProject, error)
RegisterCallbakUrl create a new event.
func (*Client) ResetAccessKeyToken ¶
ResetAccessKeyToken reset client's access key token
func (*Client) SendChatMsg ¶
func (c *Client) SendChatMsg(toUserId, groupId, message, opreate string) (*ChatProject, error)
SendChatMsg send recall message.
func (*Client) SendRobotGroupMsg ¶
func (c *Client) SendRobotGroupMsg(toUserId, groupId, title, content, message, objectName, operate, href string) (*ChatProject, error)
SendRobotMsg send recall message.
func (*Client) SendRobotMsg ¶
func (c *Client) SendRobotMsg(toUserId, message, objectName, opreate string) (*ChatProject, error)
SendRobotMsg send recall message.
func (*Client) SetAuthVersion ¶
func (c *Client) SetAuthVersion(version AuthVersionType)
SetAuthVersion set signature version that the client used
func (*Client) SetHTTPClient ¶
SetHTTPClient set a custom http client, all request will send to sls by this client
func (*Client) SetUserAgent ¶
SetUserAgent set a custom userAgent
type ClientInterface ¶
type ClientInterface interface { SetUserAgent(userAgent string) SetHTTPClient(client *http.Client) // #################### Client Operations ##################### // ResetAccessKeyToken reset client's access key token ResetAccessKeyToken(xApiKey string) // SetAuthVersion Set signature version SetAuthVersion(version AuthVersionType) // Close the client Close() error // #################### Chat Operations ##################### SendChatMsg(toUserId, groupId, message, operate string) (*ChatProject, error) //old RegisterCallbakUrl(url, method, operate string) (*ChatProject, error) SendRobotMsg(toUserId, message, objectName, operate string) (*ChatProject, error) SendRobotGroupMsg(toUserId, groupId, title, content, message, objectName, operate, href string) (*ChatProject, error) }
ClientInterface for all chat's open api
func CreateNormalInterface ¶
func CreateNormalInterface(endpoint, xApiKey string) ClientInterface
CreateNormalInterface create a normal client
type ConditionOperation ¶
ConditionOperation : retry depends on the retured bool
type Error ¶
type Error struct { HTTPCode int32 `json:"httpCode"` Code string `json:"errorCode"` Message string `json:"errorMessage"` RequestID string `json:"requestID"` }
Error defines sls error
type SignerV1 ¶
type SignerV1 struct {
// contains filtered or unexported fields
}
SignerV1 version v1
func NewSignerV1 ¶
type SignerV4 ¶
type SignerV4 struct {
// contains filtered or unexported fields
}
SignerV4 sign version v4, a non-empty region is required