dara

package
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2025 License: Apache-2.0 Imports: 35 Imported by: 18

Documentation

Index

Constants

View Source
const (
	MAX_DELAY_TIME  = 120 * 1000              // 120 seconds
	MIN_DELAY_TIME  = 100                     // 100 milliseconds
	DEFAULT_MAX_CAP = 3 * 24 * 60 * 60 * 1000 // 3 days in milliseconds
	MAX_ATTEMPTS    = 3
)

Variables

This section is empty.

Functions

func AllowRetry

func AllowRetry(retry interface{}, retryTimes *int) *bool

func ArrAppend

func ArrAppend(arr interface{}, value interface{}, index int)

ArrAppend inserts a new pointer at a specified index in a pointer array.

func ArrContains

func ArrContains(arr interface{}, value interface{}) bool

ArrContains checks if an element is in the array

func ArrIndex

func ArrIndex(arr interface{}, value interface{}) int

ArrIndex returns the index of the element in the array

func ArrJoin

func ArrJoin(arr interface{}, sep string) string

func ArrPop

func ArrPop(arr interface{}) interface{}

ArrPop removes the last element from the array

func ArrPush

func ArrPush(arr interface{}, value interface{}) int

ArrPush adds an element to the end of the array

func ArrRemove

func ArrRemove(arr interface{}, value interface{})

ArrRemove removes an element from the array

func ArrShift

func ArrShift(arr interface{}) interface{}

ArrShift removes the first element from the array

func ArrUnshift

func ArrUnshift(arr interface{}, value interface{}) int

ArrUnshift adds an element to the beginning of the array

func Bool

func Bool(a bool) *bool

func BoolSlice

func BoolSlice(a []bool) []*bool

func BoolSliceValue

func BoolSliceValue(a []*bool) []bool

func BoolValue

func BoolValue(a *bool) bool

func BytesFromString

func BytesFromString(str string, typeStr string) []byte

func ConcatArr

func ConcatArr(arr1 interface{}, arr2 interface{}) interface{}

ConcatArr concatenates two arrays

func Convert

func Convert(in interface{}, out interface{}) error

Convert is use convert map[string]interface object to struct

func CreateReadStream

func CreateReadStream(path string) (*os.File, error)

CreateReadStream would typically return an os.File or similar

func CreateWriteStream

func CreateWriteStream(path string) (*os.File, error)

CreateWriteStream would typically return an os.File or similar

func Default

func Default(inputValue interface{}, defaultValue interface{}) (_result interface{})

func EncodeURL

func EncodeURL(urlStr string) string

EncodeURL encodes a URL string.

func Exists

func Exists(path string) (bool, error)

Exists checks if the file exists

func Float32

func Float32(a float32) *float32

func Float32Slice

func Float32Slice(a []float32) []*float32

func Float32Value

func Float32Value(a *float32) float32

func Float32ValueSlice

func Float32ValueSlice(a []*float32) []float32

func Float64

func Float64(a float64) *float64

func Float64Slice

func Float64Slice(a []float64) []*float64

func Float64Value

func Float64Value(a *float64) float64

func Float64ValueSlice

func Float64ValueSlice(a []*float64) []float64

func Floor

func Floor(n Number) int

Floor returns the largest integer less than or equal to the input number as int

func ForceBoolean

func ForceBoolean(a interface{}) bool

func ForceFloat32

func ForceFloat32(a interface{}) float32

ForceFloat32 attempts to assert that a is of type float32.

func ForceFloat64

func ForceFloat64(a interface{}) float64

ForceFloat64 attempts to assert that a is of type float64.

func ForceInt

func ForceInt(a interface{}) int

func ForceInt16

func ForceInt16(a interface{}) int16

ForceInt16 attempts to assert that a is of type int16.

func ForceInt32

func ForceInt32(a interface{}) int32

ForceInt32 attempts to assert that a is of type int32.

func ForceInt64

func ForceInt64(a interface{}) int64

func ForceInt8

func ForceInt8(a interface{}) int8

ForceInt8 attempts to assert that a is of type int8.

func ForceUInt16

func ForceUInt16(a interface{}) uint16

ForceUInt16 attempts to assert that a is of type uint16.

func ForceUInt32

func ForceUInt32(a interface{}) uint32

ForceUInt32 attempts to assert that a is of type uint32.

func ForceUInt8

func ForceUInt8(a interface{}) uint8

ForceUInt8 attempts to assert that a is of type uint8.

func ForceUint64

func ForceUint64(a interface{}) uint64

func GetBackoffDelay

func GetBackoffDelay(options *RetryOptions, ctx *RetryPolicyContext) int

getBackoffDelay calculates backoff delay

func GetBackoffTime

func GetBackoffTime(backoff interface{}, retrytimes *int) *int

func GetBoundary

func GetBoundary() string

func Int

func Int(a int) *int

func Int16

func Int16(a int16) *int16

func Int16Slice

func Int16Slice(a []int16) []*int16

func Int16Value

func Int16Value(a *int16) int16

func Int16ValueSlice

func Int16ValueSlice(a []*int16) []int16

func Int32

func Int32(a int32) *int32

func Int32Slice

func Int32Slice(a []int32) []*int32

func Int32Value

func Int32Value(a *int32) int32

func Int32ValueSlice

func Int32ValueSlice(a []*int32) []int32

func Int64

func Int64(a int64) *int64

func Int64Slice

func Int64Slice(a []int64) []*int64

func Int64Value

func Int64Value(a *int64) int64

func Int64ValueSlice

func Int64ValueSlice(a []*int64) []int64

func Int8

func Int8(a int8) *int8

func Int8Slice

func Int8Slice(a []int8) []*int8

func Int8Value

func Int8Value(a *int8) int8

func Int8ValueSlice

func Int8ValueSlice(a []*int8) []int8

func IntSlice

func IntSlice(a []int) []*int

func IntValue

func IntValue(a *int) int

func IntValueSlice

func IntValueSlice(a []*int) []int

func IsNil

func IsNil(val interface{}) bool

func KeySet

func KeySet(m interface{}) []string

func Merge

func Merge(args ...interface{}) map[string]*string

func NewCastError

func NewCastError(message *string) (err error)

NewCastError is used for cast type fails

func ParseJSON

func ParseJSON(a string) interface{}

func ParseXml

func ParseXml(val string, result interface{}) map[string]interface{}

func PathEncode

func PathEncode(path string) string

PathEncode encodes each segment of a path.

func PercentEncode

func PercentEncode(uri string) string

PercentEncode encodes a string for use in URLs, replacing certain characters.

func Prettify

func Prettify(i interface{}) string

func Random

func Random() float64

func ReadAsBytes

func ReadAsBytes(body io.Reader) ([]byte, error)

func ReadAsJSON

func ReadAsJSON(body io.Reader) (result interface{}, err error)

func ReadAsSSE

func ReadAsSSE(body io.ReadCloser, eventChannel chan *SSEEvent, errorChannel chan error)

func ReadAsString

func ReadAsString(body io.Reader) (string, error)

func Recover

func Recover(in interface{}) error

Recover is used to format error

func Retryable

func Retryable(err error) *bool

func Round

func Round(n Number) int

Round returns the nearest integer to the input number as int

func ShouldRetry

func ShouldRetry(options *RetryOptions, ctx *RetryPolicyContext) bool

shouldRetry determines if a retry should be attempted

func Sleep

func Sleep(backoffTime int)

func SortArr

func SortArr(arr interface{}, order string) interface{}

func String

func String(a string) *string

func StringSlice

func StringSlice(a []string) []*string

func StringSliceValue

func StringSliceValue(a []*string) []string

func StringValue

func StringValue(a *string) string

func Stringify

func Stringify(a interface{}) string

func TeaSDKError added in v1.3.2

func TeaSDKError(err error) error

func ToBytes

func ToBytes(s, encodingType string) []byte

func ToFileForm

func ToFileForm(body map[string]interface{}, boundary string) io.Reader

func ToFormString

func ToFormString(a map[string]interface{}) string

func ToInt

func ToInt(a *int32) *int

func ToInt32

func ToInt32(a *int) *int32

func ToMap

func ToMap(args ...interface{}) map[string]interface{}

func ToObject

func ToObject(obj interface{}) map[string]interface{}

func ToReader

func ToReader(obj interface{}) io.Reader

func ToString

func ToString(val interface{}) string

func ToWriter added in v1.3.3

func ToWriter(obj interface{}) io.Writer

func ToXML

func ToXML(obj map[string]interface{}) string

func TransInterfaceToBool

func TransInterfaceToBool(val interface{}) *bool

func TransInterfaceToInt

func TransInterfaceToInt(val interface{}) *int

func TransInterfaceToString

func TransInterfaceToString(val interface{}) *string

func Uint

func Uint(a uint) *uint

func Uint16

func Uint16(a uint16) *uint16

func Uint16Slice

func Uint16Slice(a []uint16) []*uint16

func Uint16Value

func Uint16Value(a *uint16) uint16

func Uint16ValueSlice

func Uint16ValueSlice(a []*uint16) []uint16

func Uint32

func Uint32(a uint32) *uint32

func Uint32Slice

func Uint32Slice(a []uint32) []*uint32

func Uint32Value

func Uint32Value(a *uint32) uint32

func Uint32ValueSlice

func Uint32ValueSlice(a []*uint32) []uint32

func Uint64

func Uint64(a uint64) *uint64

func Uint64Slice

func Uint64Slice(a []uint64) []*uint64

func Uint64Value

func Uint64Value(a *uint64) uint64

func Uint64ValueSlice

func Uint64ValueSlice(a []*uint64) []uint64

func Uint8

func Uint8(a uint8) *uint8

func Uint8Slice

func Uint8Slice(a []uint8) []*uint8

func Uint8Value

func Uint8Value(a *uint8) uint8

func Uint8ValueSlice

func Uint8ValueSlice(a []*uint8) []uint8

func UintSlice

func UintSlice(a []uint) []*uint

func UintValue

func UintValue(a *uint) uint

func UintValueSlice

func UintValueSlice(a []*uint) []uint

func Validate

func Validate(params interface{}) error

Types

type BackoffPolicy

type BackoffPolicy interface {
	GetDelayTime(ctx *RetryPolicyContext) int
}

BackoffPolicy interface with a method to get delay time

func BackoffPolicyFactory

func BackoffPolicyFactory(option map[string]interface{}) (BackoffPolicy, error)

BackoffPolicyFactory creates a BackoffPolicy based on the option

type BaseError

type BaseError interface {
	error
	GetName() *string
	GetCode() *string
}

type CastError

type CastError struct {
	Message *string
}

CastError is used for cast type fails

func (*CastError) Error

func (err *CastError) Error() string

Return message of CastError

type DaraFile

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

File struct to represent the file

func NewDaraFile

func NewDaraFile(path string) *DaraFile

NewFile creates a new instance of File

func (*DaraFile) Close

func (tf *DaraFile) Close() error

Close closes the file

func (*DaraFile) CreateTime

func (tf *DaraFile) CreateTime() (*Date, error)

CreateTime returns the creation time of the file

func (*DaraFile) Length

func (tf *DaraFile) Length() (int64, error)

Length returns the size of the file

func (*DaraFile) ModifyTime

func (tf *DaraFile) ModifyTime() (*Date, error)

ModifyTime returns the modification time of the file

func (*DaraFile) Path

func (tf *DaraFile) Path() string

Path returns the path of the file

func (*DaraFile) Read

func (tf *DaraFile) Read(size int) ([]byte, error)

Read reads a specified number of bytes from the file

func (*DaraFile) Write

func (tf *DaraFile) Write(data []byte) error

Write writes data to the file

type Date

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

func NewDate

func NewDate(dateInput string) (*Date, error)

func (*Date) Add

func (t *Date) Add(amount int, unit string) *Date

func (*Date) DayOfMonth

func (t *Date) DayOfMonth() int

func (*Date) DayOfWeek

func (t *Date) DayOfWeek() int

func (*Date) Diff

func (t *Date) Diff(amount string, diffDate *Date) int64

func (*Date) Format

func (t *Date) Format(layout string) string

func (*Date) Hour

func (t *Date) Hour() int

func (*Date) Minute

func (t *Date) Minute() int

func (*Date) Month

func (t *Date) Month() int

func (*Date) Second

func (t *Date) Second() int

func (*Date) Sub

func (t *Date) Sub(amount int, unit string) *Date

func (*Date) UTC

func (t *Date) UTC() string

func (*Date) Unix

func (t *Date) Unix() int64

func (*Date) WeekOfYear

func (t *Date) WeekOfYear() int

func (*Date) Year

func (t *Date) Year() int

type Entry

type Entry struct {
	Key   string
	Value interface{}
}

func Entries

func Entries(m interface{}) []*Entry

toFloat64 converts a numeric value to float64 for comparison

type EqualJitterBackoffPolicy

type EqualJitterBackoffPolicy struct {
	Period int
	Cap    int
}

EqualJitterBackoffPolicy implementation

func NewEqualJitterBackoffPolicy

func NewEqualJitterBackoffPolicy(option map[string]interface{}) *EqualJitterBackoffPolicy

func (*EqualJitterBackoffPolicy) GetDelayTime

func (e *EqualJitterBackoffPolicy) GetDelayTime(ctx *RetryPolicyContext) int

type ExponentialBackoffPolicy

type ExponentialBackoffPolicy struct {
	Period int
	Cap    int
}

ExponentialBackoffPolicy implementation

func NewExponentialBackoffPolicy

func NewExponentialBackoffPolicy(option map[string]interface{}) *ExponentialBackoffPolicy

func (*ExponentialBackoffPolicy) GetDelayTime

func (e *ExponentialBackoffPolicy) GetDelayTime(ctx *RetryPolicyContext) int

type ExtendsParameters

type ExtendsParameters = util.ExtendsParameters

type FileField

type FileField struct {
	Filename    *string   `json:"filename" xml:"filename" require:"true"`
	ContentType *string   `json:"content-type" xml:"content-type" require:"true"`
	Content     io.Reader `json:"content" xml:"content" require:"true"`
}

func (*FileField) SetContent

func (s *FileField) SetContent(v io.Reader) *FileField

func (*FileField) SetContentType

func (s *FileField) SetContentType(v string) *FileField

func (*FileField) SetFilename

func (s *FileField) SetFilename(v string) *FileField

type FileFormReader

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

func (*FileFormReader) Read

func (f *FileFormReader) Read(p []byte) (n int, err error)

type FixedBackoffPolicy

type FixedBackoffPolicy struct {
	Period int
}

FixedBackoffPolicy implementation

func NewFixedBackoffPolicy

func NewFixedBackoffPolicy(option map[string]interface{}) *FixedBackoffPolicy

func (*FixedBackoffPolicy) GetDelayTime

func (f *FixedBackoffPolicy) GetDelayTime(ctx *RetryPolicyContext) int

type FullJitterBackoffPolicy

type FullJitterBackoffPolicy struct {
	Period int
	Cap    int
}

FullJitterBackoffPolicy implementation

func NewFullJitterBackoffPolicy

func NewFullJitterBackoffPolicy(option map[string]interface{}) *FullJitterBackoffPolicy

func (*FullJitterBackoffPolicy) GetDelayTime

func (f *FullJitterBackoffPolicy) GetDelayTime(ctx *RetryPolicyContext) int

type HttpClient added in v1.3.6

type HttpClient interface {
	Call(request *http.Request, transport *http.Transport) (response *http.Response, err error)
}

type HttpRequest added in v1.3.6

type HttpRequest interface {
}

type HttpResponse added in v1.3.6

type HttpResponse interface {
}

type Model

type Model interface {
	Validate() error
	ToMap() map[string]interface{}
	// contains filtered or unexported methods
}

type Number

type Number interface{}

Number is an interface that can be implemented by any numeric type

type RandomBackoffPolicy

type RandomBackoffPolicy struct {
	Period int
	Cap    int
}

RandomBackoffPolicy implementation

func NewRandomBackoffPolicy

func NewRandomBackoffPolicy(option map[string]interface{}) *RandomBackoffPolicy

func (*RandomBackoffPolicy) GetDelayTime

func (r *RandomBackoffPolicy) GetDelayTime(ctx *RetryPolicyContext) int

type Request

type Request struct {
	Protocol *string
	Port     *int
	Method   *string
	Pathname *string
	Domain   *string
	Headers  map[string]*string
	Query    map[string]*string
	Body     io.Reader
}

Request is used wrap http request

func NewRequest

func NewRequest() (req *Request)

NewRequest is used shortly create Request

type Response

type Response struct {
	Body          io.ReadCloser
	StatusCode    *int
	StatusMessage *string
	Headers       map[string]*string
}

Response is use d wrap http response

func DoRequest

func DoRequest(request *Request, runtimeObject *RuntimeObject) (response *Response, err error)

DoRequest is used send request to server

func NewResponse

func NewResponse(httpResponse *http.Response) (res *Response)

NewResponse is create response with http response

func (*Response) ReadBody

func (response *Response) ReadBody() (body []byte, err error)

ReadBody is used read response body

type ResponseError

type ResponseError interface {
	BaseError
	GetRetryAfter() *int64
	GetStatusCode() *int
	GetAccessDeniedDetail() map[string]interface{}
	GetDescription() *string
	GetData() map[string]interface{}
}

type RetryCondition

type RetryCondition struct {
	MaxAttempts int
	Backoff     BackoffPolicy
	Exception   []string
	ErrorCode   []string
	MaxDelay    int
}

RetryCondition holds the retry conditions

func NewRetryCondition

func NewRetryCondition(condition map[string]interface{}) *RetryCondition

type RetryOptions

type RetryOptions struct {
	Retryable        bool
	RetryCondition   []*RetryCondition
	NoRetryCondition []*RetryCondition
}

RetryOptions holds the retry options

func NewRetryOptions

func NewRetryOptions(options map[string]interface{}) *RetryOptions

type RetryPolicyContext

type RetryPolicyContext struct {
	Key              string
	RetriesAttempted int
	HttpRequest      *Request  // placeholder for actual http.Request type
	HttpResponse     *Response // placeholder for actual http.Response type
	Exception        error
}

RetryPolicyContext holds context for the retry operation

type RuntimeObject

type RuntimeObject struct {
	IgnoreSSL         *bool                  `json:"ignoreSSL" xml:"ignoreSSL"`
	ReadTimeout       *int                   `json:"readTimeout" xml:"readTimeout"`
	ConnectTimeout    *int                   `json:"connectTimeout" xml:"connectTimeout"`
	LocalAddr         *string                `json:"localAddr" xml:"localAddr"`
	HttpProxy         *string                `json:"httpProxy" xml:"httpProxy"`
	HttpsProxy        *string                `json:"httpsProxy" xml:"httpsProxy"`
	NoProxy           *string                `json:"noProxy" xml:"noProxy"`
	MaxIdleConns      *int                   `json:"maxIdleConns" xml:"maxIdleConns"`
	Key               *string                `json:"key" xml:"key"`
	Cert              *string                `json:"cert" xml:"cert"`
	Ca                *string                `json:"ca" xml:"ca"`
	Socks5Proxy       *string                `json:"socks5Proxy" xml:"socks5Proxy"`
	Socks5NetWork     *string                `json:"socks5NetWork" xml:"socks5NetWork"`
	Listener          utils.ProgressListener `json:"listener" xml:"listener"`
	Tracker           *utils.ReaderTracker   `json:"tracker" xml:"tracker"`
	Logger            *utils.Logger          `json:"logger" xml:"logger"`
	RetryOptions      *RetryOptions          `json:"retryOptions" xml:"retryOptions"`
	ExtendsParameters *ExtendsParameters     `json:"extendsParameters,omitempty" xml:"extendsParameters,omitempty"`
	HttpClient
}

RuntimeObject is used for converting http configuration

func NewRuntimeObject

func NewRuntimeObject(runtime map[string]interface{}) *RuntimeObject

NewRuntimeObject is used for shortly create runtime object

type RuntimeOptions

type RuntimeOptions = util.RuntimeOptions

type SDKError

type SDKError struct {
	BaseError
	Code       *string
	Name       *string
	StatusCode *int
	Message    *string
	Data       *string
	Stack      *string

	Description        *string
	AccessDeniedDetail map[string]interface{}
	// contains filtered or unexported fields
}

SDKError struct is used save error code and message

func NewSDKError

func NewSDKError(obj map[string]interface{}) *SDKError

NewSDKError is used for shortly create SDKError object

func (*SDKError) Error

func (err *SDKError) Error() string

func (*SDKError) ErrorMessage

func (err *SDKError) ErrorMessage() *string

func (*SDKError) ErrorName

func (err *SDKError) ErrorName() *string

func (*SDKError) GetCode added in v1.3.2

func (err *SDKError) GetCode() *string

func (*SDKError) SetErrMsg

func (err *SDKError) SetErrMsg(msg string)

Set ErrMsg by msg

type SSEEvent

type SSEEvent struct {
	ID    *string
	Event *string
	Data  *string
	Retry *int
}

定义 Event 结构体

type URL

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

URL is a wrapper around the URL type.

func NewURL

func NewURL(str string) (*URL, error)

NewURL constructs a new URL from a string.

func ParseURL

func ParseURL(urlStr string) (*URL, error)

Parse constructs a new URL from a string.

func (*URL) Auth

func (t *URL) Auth() string

Auth returns the username and password of the URL.

func (*URL) Hash

func (t *URL) Hash() string

Hash returns the hash of the URL without the #.

func (*URL) Host

func (t *URL) Host() string

Host returns the host (host:port) of the URL.

func (*URL) Hostname

func (t *URL) Hostname() string

Hostname returns the hostname of the URL.

func (*URL) Href

func (t *URL) Href() string

Href returns the full URL.

func (*URL) Path

func (t *URL) Path() string

Path returns the path and query of the URL.

func (*URL) Pathname

func (t *URL) Pathname() string

Pathname returns the pathname of the URL.

func (*URL) Port

func (t *URL) Port() string

Port returns the port of the URL, or the default for the protocol if not specified.

func (*URL) Protocol

func (t *URL) Protocol() string

Protocol returns the protocol of the URL.

func (*URL) Search

func (t *URL) Search() string

Search returns the search part of the URL without the ?.

Jump to

Keyboard shortcuts

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