utils

package
v0.1.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 34 Imported by: 286

Documentation

Index

Constants

View Source
const (
	DefaultLength = 32
	MinLength     = 32
	MaxLength     = 96
)
View Source
const (
	StartBackoff = 1 * time.Second
	MaxBackoff   = 5 * time.Second
	MaxTries     = 1
)
View Source
const (
	HeaderContentDisposition = "Content-Disposition"
)
View Source
const UserAgentSDK = "AccelByteGoSDK/v0.40.0"

UserAgentSDK attention: this var will be incremented automatically on `Makefile version` using regex therefore the patterns need to comply

Variables

View Source
var (
	DefaultTimeout = 30 * time.Second
)
View Source
var RetryCodes = map[int]bool{
	422: true,
	425: true,
	500: true,
	502: true,
	408: true,
}

Functions

func AmazonTraceIDGen

func AmazonTraceIDGen() string

func ConvertByteToFile

func ConvertByteToFile(fileByte io.Writer, writer *bytes.Buffer, fileName string) (runtime.NamedReadCloser, error)

func CustomTransportRuntime

func CustomTransportRuntime(transport *httptransport.Runtime) *httptransport.Runtime

func EscapeQuotes

func EscapeQuotes(s string) string

func GenerateID

func GenerateID() string

GenerateID returns UUID without dash

func GenerateMessageID

func GenerateMessageID() string

func GetRequestBuffer

func GetRequestBuffer(r *ABRequest) []byte

func IsFormType

func IsFormType(r *ABRequest) bool

func IsMultipart

func IsMultipart(r *ABRequest, mediaType string) bool

func IsStatusCodeError

func IsStatusCodeError(statusCode int) bool

func LogRequest

func LogRequest(r *http.Request) interface{}

func LogResponse

func LogResponse(r *http.Response) interface{}

func MangleContentType

func MangleContentType(mediaType, boundary string) string

func NewHttpRequestFromABRequest

func NewHttpRequestFromABRequest(
	req *ABRequest,
	mediaType string,
	basePath string,
	producers map[string]oar.Producer,
	registry oaStrFmt.Registry,
	auth oar.ClientAuthInfoWriter,
) (*http.Request, error)

func ReadByChunks

func ReadByChunks(filePath string) (*os.File, error)

func RewindBody

func RewindBody(r *http.Request) (*http.Request, error)

func SelectScheme

func SelectScheme(schemes []string) string

func SetLogger

func SetLogger(inner http.RoundTripper) http.RoundTripper

func SetTimeNowForTest

func SetTimeNowForTest(t *testing.T, now time.Time)

func SetupRewindBody

func SetupRewindBody(r *http.Request) (*http.Request, error)

func TimeNow

func TimeNow() time.Time

func UserAgentGen

func UserAgentGen() string

Types

type ABClientTransport

type ABClientTransport struct {
	DefaultMediaType      string
	DefaultAuthentication oar.ClientAuthInfoWriter
	Consumers             map[string]oar.Consumer
	Producers             map[string]oar.Producer

	Transport http.RoundTripper
	Jar       http.CookieJar

	Host     string
	BasePath string
	Schemes  []string
	Formats  oaStrFmt.Registry
	Context  context.Context

	Debug  bool
	Logger oarLogger.Logger
	// contains filtered or unexported fields
}

ABClientTransport Implements utils.ClientTransport

func NewABClientTransport

func NewABClientTransport(host, basePath string, schemes []string) *ABClientTransport

func NewABClientTransportWithHttpClient

func NewABClientTransportWithHttpClient(host, basePath string, schemes []string, httpClient *http.Client) *ABClientTransport

func (*ABClientTransport) GetPreSendABRequestFunc

func (ct *ABClientTransport) GetPreSendABRequestFunc() PreSendABRequestFunc

func (*ABClientTransport) GetPreSendHttpRequestFunc

func (ct *ABClientTransport) GetPreSendHttpRequestFunc() PreSendHttpRequestFunc

func (*ABClientTransport) GetRoundTripper

func (ct *ABClientTransport) GetRoundTripper() http.RoundTripper

func (*ABClientTransport) NewHttpClient

func (ct *ABClientTransport) NewHttpClient() *http.Client

func (*ABClientTransport) PickScheme

func (ct *ABClientTransport) PickScheme(schemes []string) string

func (*ABClientTransport) SetPreSendABequestFunc

func (ct *ABClientTransport) SetPreSendABequestFunc(requestFunc PreSendABRequestFunc) error

func (*ABClientTransport) SetPreSendHttpRequestFunc

func (ct *ABClientTransport) SetPreSendHttpRequestFunc(requestFunc PreSendHttpRequestFunc) error

func (*ABClientTransport) Submit

func (ct *ABClientTransport) Submit(clientOperation *oar.ClientOperation) (interface{}, error)

type ABRequest

type ABRequest struct {
	PathPattern string
	Method      string
	Writer      oar.ClientRequestWriter

	PathParams map[string]string
	Header     http.Header
	Query      url.Values
	FormFields url.Values
	FileFields map[string][]oar.NamedReadCloser
	Payload    interface{}
	Timeout    time.Duration
	Buf        *bytes.Buffer

	GetBodyFunc func(r *ABRequest) []byte
}

ABRequest Implements runtime.ClientRequest

func NewABRequestFromClientOperation

func NewABRequestFromClientOperation(clientOperation *oar.ClientOperation) (*ABRequest, error)

func (*ABRequest) GetBody

func (r *ABRequest) GetBody() []byte

func (*ABRequest) GetBodyParam

func (r *ABRequest) GetBodyParam() interface{}

func (*ABRequest) GetFileParam

func (r *ABRequest) GetFileParam() map[string][]oar.NamedReadCloser

func (*ABRequest) GetHeaderParams

func (r *ABRequest) GetHeaderParams() http.Header

func (*ABRequest) GetMethod

func (r *ABRequest) GetMethod() string

func (*ABRequest) GetPath

func (r *ABRequest) GetPath() string

func (*ABRequest) GetQueryParams

func (r *ABRequest) GetQueryParams() url.Values

func (*ABRequest) SetBodyParam

func (r *ABRequest) SetBodyParam(payload interface{}) error

func (*ABRequest) SetFileParam

func (r *ABRequest) SetFileParam(name string, files ...oar.NamedReadCloser) error

func (*ABRequest) SetFormParam

func (r *ABRequest) SetFormParam(name string, values ...string) error

func (*ABRequest) SetHeaderParam

func (r *ABRequest) SetHeaderParam(name string, values ...string) error

func (*ABRequest) SetPathParam

func (r *ABRequest) SetPathParam(name string, value string) error

func (*ABRequest) SetQueryParam

func (r *ABRequest) SetQueryParam(name string, values ...string) error

func (*ABRequest) SetTimeout

func (r *ABRequest) SetTimeout(timeout time.Duration) error

type ABResponse

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

ABResponse Implements runtime.ClientResponse

func NewABResponseFromHttpResponse

func NewABResponseFromHttpResponse(httpResponse *http.Response) ABResponse

func (ABResponse) Body

func (r ABResponse) Body() io.ReadCloser

func (ABResponse) Code

func (r ABResponse) Code() int

func (ABResponse) GetHeader

func (r ABResponse) GetHeader(name string) string

func (ABResponse) GetHeaders

func (r ABResponse) GetHeaders(name string) []string

func (ABResponse) Message

func (r ABResponse) Message() string

type Backoff

type Backoff interface {
	// Get delay's duration
	Get(attempt uint) time.Duration
}

Backoff interface

func NewConstantBackoff

func NewConstantBackoff(duration time.Duration) Backoff

func NewExponentialBackoff

func NewExponentialBackoff(start time.Duration, max time.Duration) Backoff

type ClientTransport

type ClientTransport interface {
	GetRoundTripper() http.RoundTripper
	GetPreSendABRequestFunc() PreSendABRequestFunc
	SetPreSendABRequestFunc(PreSendABRequestFunc) error
	GetPreSendHttpRequestFunc() PreSendHttpRequestFunc
	SetPreSendHttpRequestFunc(PreSendHttpRequestFunc) error

	oar.ClientTransport // for Submit(*ClientOperation) (interface{}, error)
}

ClientTransport Implements runtime.ClientTransport

type CodeVerifier

type CodeVerifier struct {
	Value string
}

func CreateCodeVerifier

func CreateCodeVerifier() (*CodeVerifier, error)

func CreateCodeVerifierFromBytes

func CreateCodeVerifierFromBytes(b []byte) (*CodeVerifier, error)

func CreateCodeVerifierWithLength

func CreateCodeVerifierWithLength(length int) (*CodeVerifier, error)

func (*CodeVerifier) CodeChallengePlain

func (v *CodeVerifier) CodeChallengePlain() string

func (*CodeVerifier) CodeChallengeS256

func (v *CodeVerifier) CodeChallengeS256() string

func (*CodeVerifier) String

func (v *CodeVerifier) String() string

type CustomTransport

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

func (*CustomTransport) RoundTrip

func (c *CustomTransport) RoundTrip(r *http.Request) (*http.Response, error)

type DefaultPersistentRoundTripper

type DefaultPersistentRoundTripper struct {
	MaxAttempts *int
	MaxElapsed  *time.Duration
	// contains filtered or unexported fields
}

func NewDefaultPersistentRoundTripper

func NewDefaultPersistentRoundTripper(maxAttempts *int, maxElapsed *time.Duration, internalRoundTripper http.RoundTripper) DefaultPersistentRoundTripper

func (DefaultPersistentRoundTripper) RoundTrip

func (DefaultPersistentRoundTripper) ShouldRetry

func (rt DefaultPersistentRoundTripper) ShouldRetry(req *http.Request, res *http.Response, attempts int, elapsed time.Duration) bool

type Once

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

func (*Once) Do

func (o *Once) Do(f func())

This Do is similar to http://github.com/matryer/resync

func (*Once) Reset

func (o *Once) Reset()

This Reset is similar to http://github.com/matryer/resync

type PersistentRoundTripper

type PersistentRoundTripper interface {
	ShouldRetry(req *http.Request, res *http.Response, attempts int, elapsed time.Duration) bool
	http.RoundTripper
}

type PreSendABRequestFunc

type PreSendABRequestFunc func(r *ABRequest) (*ABRequest, error)

type PreSendHttpRequestFunc

type PreSendHttpRequestFunc func(r *http.Request) (*http.Request, error)

type Retry

type Retry struct {
	RetryCodes map[int]bool
	MaxTries   uint
	Backoff    Backoff
	Transport  http.RoundTripper
	Sleeper    func(duration time.Duration)
}

Retry struct with http.RoundTripper.

func (Retry) RoundTrip

func (m Retry) RoundTrip(req *http.Request) (*http.Response, error)

type TrackedReadCloser

type TrackedReadCloser struct {
	io.ReadCloser
	// contains filtered or unexported fields
}

func (*TrackedReadCloser) Close

func (r *TrackedReadCloser) Close() error

func (*TrackedReadCloser) Read

func (r *TrackedReadCloser) Read(data []byte) (int, error)

Directories

Path Synopsis
validator Module

Jump to

Keyboard shortcuts

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