core

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChinaMainlandMajorDomain = "sd-rtn.com"
	OverseaMajorDomain       = "agora.io"
)
View Source
const (
	US = iota
	EU
	AP
	CN
)
View Source
const (
	USWestRegionDomainPrefix = "api-us-west-1"
	USEastRegionDomainPrefix = "api-us-east-1"
)
View Source
const (
	APSoutheastRegionDomainPrefix = "api-ap-southeast-1"
	APNortheastRegionDomainPrefix = "api-ap-northeast-1"
)
View Source
const (
	EUWestRegionDomainPrefix    = "api-eu-west-1"
	EUCentralRegionDomainPrefix = "api-eu-central-1"
)
View Source
const (
	CNEastRegionDomainPrefix  = "api-cn-east-1"
	CNNorthRegionDomainPrefix = "api-cn-north-1"
)
View Source
const GlobalDomainPrefix = "api"

Variables

View Source
var (
	DiscardLogger = &discardLogger{}
)
View Source
var RegionDomain = map[RegionArea]Domain{
	US: {
		RegionDomainPrefixes: []string{
			USWestRegionDomainPrefix,
			USEastRegionDomainPrefix,
		},
		MajorDomainSuffixes: []string{
			OverseaMajorDomain,
			ChinaMainlandMajorDomain,
		},
	},
	EU: {
		RegionDomainPrefixes: []string{
			EUWestRegionDomainPrefix,
			EUCentralRegionDomainPrefix,
		},
		MajorDomainSuffixes: []string{
			OverseaMajorDomain,
			ChinaMainlandMajorDomain,
		},
	},
	AP: {
		RegionDomainPrefixes: []string{
			APSoutheastRegionDomainPrefix,
			APNortheastRegionDomainPrefix,
		},
		MajorDomainSuffixes: []string{
			OverseaMajorDomain,
			ChinaMainlandMajorDomain,
		},
	},
	CN: {
		RegionDomainPrefixes: []string{
			CNEastRegionDomainPrefix,
			CNNorthRegionDomainPrefix,
		},
		MajorDomainSuffixes: []string{
			ChinaMainlandMajorDomain,
			OverseaMajorDomain,
		},
	},
}

Functions

func Contains

func Contains(S []string, E string) bool

func NewDefaultLogger

func NewDefaultLogger(level LogLevel) *sampleLogger

func RetryDo

func RetryDo(retryFunc RetryFunc, stopFunc RetryShouldStopFunc, delayFunc DelayFunc, attemptFunc OnFailedAttemptFunc) error

Types

type BaseResponse

type BaseResponse struct {
	RawBody        []byte
	HttpStatusCode int
}

func (*BaseResponse) UnmarshallToTarget

func (r *BaseResponse) UnmarshallToTarget(target interface{}) error

UnmarshallToTarget unmarshall body into target var successful if err is nil

type BasicAuthCredential

type BasicAuthCredential struct {
	Username string
	Password string
}

func NewBasicAuthCredential

func NewBasicAuthCredential(username string, password string) *BasicAuthCredential

func (*BasicAuthCredential) Type

func (*BasicAuthCredential) Visit

func (b *BasicAuthCredential) Visit(r *http.Request)

type Client

type Client interface {
	GetAppID() string
	GetLogger() Logger
	DoREST(ctx context.Context, path string, method string, requestBody interface{}) (*BaseResponse, error)
}

type ClientImpl

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

func NewClient

func NewClient(config *Config) *ClientImpl

func (*ClientImpl) DoREST

func (c *ClientImpl) DoREST(ctx context.Context, path string,
	method string, requestBody interface{},
) (*BaseResponse, error)

func (*ClientImpl) GetAppID

func (c *ClientImpl) GetAppID() string

func (*ClientImpl) GetLogger added in v0.3.0

func (c *ClientImpl) GetLogger() Logger

type Config

type Config struct {
	AppID       string
	HttpTimeout time.Duration
	Credential  Credential

	RegionCode RegionArea
	Logger     Logger
}

type Credential

type Credential interface {
	Type() CredentialType
	Visit(r *http.Request)
}

type CredentialType

type CredentialType int
const (
	BasicAuth CredentialType = iota
)

type DelayFunc

type DelayFunc func(int) time.Duration

type Domain

type Domain struct {
	RegionDomainPrefixes []string
	MajorDomainSuffixes  []string
}

type DomainPool

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

func NewDomainPool

func NewDomainPool(domainArea RegionArea, logger Logger) *DomainPool

func (*DomainPool) AllDomainsSuffixes

func (d *DomainPool) AllDomainsSuffixes() []string

func (*DomainPool) GetCurrentRegion

func (d *DomainPool) GetCurrentRegion() string

func (*DomainPool) GetCurrentUrl

func (d *DomainPool) GetCurrentUrl() string

func (*DomainPool) NextRegion

func (d *DomainPool) NextRegion()

func (*DomainPool) SelectBestDomain

func (d *DomainPool) SelectBestDomain(ctx context.Context) error

type DomainResolver

type DomainResolver interface {
	Resolve(ctx context.Context, domains []string, regionPrefix string) (string, error)
}

type DomainResolverFunc

type DomainResolverFunc func(ctx context.Context, domains []string, regionPrefix string) (string, error)

func (DomainResolverFunc) Resolve

func (d DomainResolverFunc) Resolve(ctx context.Context, domains []string, regionPrefix string) (string, error)

type GatewayErr

type GatewayErr struct {
	Code int
	Msg  string
}

func NewGatewayErr

func NewGatewayErr(code int, msg string) *GatewayErr

func (*GatewayErr) Error

func (g *GatewayErr) Error() string

type InternalErr

type InternalErr struct {
	Err string
}

func NewInternalErr

func NewInternalErr(msg string) *InternalErr

func (*InternalErr) Error

func (i *InternalErr) Error() string

type LogLevel

type LogLevel int
const (
	LogDebug LogLevel = iota
	LogInfo
	LogWarning
	LogErr
	LogUnknown
)

type Logger

type Logger interface {
	Debug(ctx context.Context, module string, v ...interface{})
	Debugf(ctx context.Context, module string, format string, v ...interface{})
	Error(ctx context.Context, module string, v ...interface{})
	Errorf(ctx context.Context, module string, format string, v ...interface{})
	Info(ctx context.Context, module string, v ...interface{})
	Infof(ctx context.Context, module string, format string, v ...interface{})
	Warn(ctx context.Context, module string, v ...interface{})
	Warnf(ctx context.Context, module string, format string, v ...interface{})

	Level() LogLevel
	SetLevel(level LogLevel)
}

type OnFailedAttemptFunc

type OnFailedAttemptFunc func(error)

type RegionArea

type RegionArea int

type ResponseInterface

type ResponseInterface interface {
	IsSuccess() bool
}

type RetryErr

type RetryErr struct {
	Err error
	// contains filtered or unexported fields
}

func NewRetryErr

func NewRetryErr(needRetry bool, err error) *RetryErr

func (*RetryErr) Error

func (r *RetryErr) Error() string

func (*RetryErr) NeedRetry

func (r *RetryErr) NeedRetry() bool

func (*RetryErr) Unwrap

func (r *RetryErr) Unwrap() error

type RetryFunc

type RetryFunc func(retryCount int) error

type RetryShouldStopFunc

type RetryShouldStopFunc func() bool

Jump to

Keyboard shortcuts

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