utils

package
v0.74.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: MIT Imports: 35 Imported by: 0

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.74.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 added in v0.16.0

func AmazonTraceIDGen() string

func ConvertByteToFile added in v0.30.0

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

func CustomTransportRuntime added in v0.30.0

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

func EscapeQuotes added in v0.21.0

func EscapeQuotes(s string) string

func GenerateID

func GenerateID() string

GenerateID returns UUID without dash

func GenerateMessageID

func GenerateMessageID() string

func GetClient added in v0.72.0

func GetClient() http.Client

func GetEnv added in v0.64.0

func GetEnv(key, fallback string) string

func GetNamespaceContextExpirationTime added in v0.64.0

func GetNamespaceContextExpirationTime() time.Duration

func GetRequestBuffer added in v0.21.0

func GetRequestBuffer(r *ABRequest) []byte

func GetRolesExpirationTime added in v0.64.0

func GetRolesExpirationTime() time.Duration

func IsFormType added in v0.21.0

func IsFormType(r *ABRequest) bool

func IsMultipart added in v0.21.0

func IsMultipart(r *ABRequest, mediaType string) bool

func IsStatusCodeError added in v0.21.0

func IsStatusCodeError(statusCode int) bool

func LogRequest added in v0.22.0

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

func LogResponse added in v0.22.0

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

func MangleContentType added in v0.21.0

func MangleContentType(mediaType, boundary string) string

func NewHttpRequestFromABRequest added in v0.21.0

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

func ReadByChunks added in v0.28.0

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

func RewindBody added in v0.21.0

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

func SelectScheme added in v0.21.0

func SelectScheme(schemes []string) string

func SetLogger added in v0.22.0

func SetLogger(inner http.RoundTripper) http.RoundTripper

func SetTimeNowForTest added in v0.36.0

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

func SetupRewindBody added in v0.21.0

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

func SimpleHTTPCall added in v0.14.0

func SimpleHTTPCall(client http.Client, endpoint, httpMethod, authorizationValue, contentType string, requestBody io.Reader) (*http.Response, error)

func TimeNow added in v0.36.0

func TimeNow() time.Time

func UserAgentGen added in v0.13.0

func UserAgentGen() string

Types

type ABClientTransport added in v0.21.0

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 added in v0.21.0

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

func NewABClientTransportWithHttpClient added in v0.21.0

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

func (*ABClientTransport) GetPreSendABRequestFunc added in v0.21.0

func (ct *ABClientTransport) GetPreSendABRequestFunc() PreSendABRequestFunc

func (*ABClientTransport) GetPreSendHttpRequestFunc added in v0.21.0

func (ct *ABClientTransport) GetPreSendHttpRequestFunc() PreSendHttpRequestFunc

func (*ABClientTransport) GetRoundTripper added in v0.21.0

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

func (*ABClientTransport) NewHttpClient added in v0.21.0

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

func (*ABClientTransport) PickScheme added in v0.21.0

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

func (*ABClientTransport) SetPreSendABequestFunc added in v0.21.0

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

func (*ABClientTransport) SetPreSendHttpRequestFunc added in v0.21.0

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

func (*ABClientTransport) Submit added in v0.21.0

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

type ABRequest added in v0.21.0

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 added in v0.21.0

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

func (*ABRequest) GetBody added in v0.21.0

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

func (*ABRequest) GetBodyParam added in v0.21.0

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

func (*ABRequest) GetFileParam added in v0.21.0

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

func (*ABRequest) GetHeaderParams added in v0.21.0

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

func (*ABRequest) GetMethod added in v0.21.0

func (r *ABRequest) GetMethod() string

func (*ABRequest) GetPath added in v0.21.0

func (r *ABRequest) GetPath() string

func (*ABRequest) GetQueryParams added in v0.21.0

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

func (*ABRequest) SetBodyParam added in v0.21.0

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

func (*ABRequest) SetFileParam added in v0.21.0

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

func (*ABRequest) SetFormParam added in v0.21.0

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

func (*ABRequest) SetHeaderParam added in v0.21.0

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

func (*ABRequest) SetPathParam added in v0.21.0

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

func (*ABRequest) SetQueryParam added in v0.21.0

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

func (*ABRequest) SetTimeout added in v0.21.0

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

type ABResponse added in v0.21.0

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

ABResponse Implements runtime.ClientResponse

func NewABResponseFromHttpResponse added in v0.21.0

func NewABResponseFromHttpResponse(httpResponse *http.Response) ABResponse

func (ABResponse) Body added in v0.21.0

func (r ABResponse) Body() io.ReadCloser

func (ABResponse) Code added in v0.21.0

func (r ABResponse) Code() int

func (ABResponse) GetHeader added in v0.21.0

func (r ABResponse) GetHeader(name string) string

func (ABResponse) GetHeaders added in v0.27.1

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

func (ABResponse) Message added in v0.21.0

func (r ABResponse) Message() string

type Backoff added in v0.19.0

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

Backoff interface

func NewConstantBackoff added in v0.19.0

func NewConstantBackoff(duration time.Duration) Backoff

func NewExponentialBackoff added in v0.19.0

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

type ClientTransport added in v0.21.0

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 added in v0.18.0

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

func (*CustomTransport) RoundTrip added in v0.18.0

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

type DefaultPersistentRoundTripper added in v0.21.0

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

func NewDefaultPersistentRoundTripper added in v0.21.0

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

func (DefaultPersistentRoundTripper) RoundTrip added in v0.21.0

func (DefaultPersistentRoundTripper) ShouldRetry added in v0.21.0

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

type FlightIdContainer added in v0.63.0

type FlightIdContainer struct {
	Value string
}

func GetDefaultFlightID added in v0.63.0

func GetDefaultFlightID() *FlightIdContainer

func (*FlightIdContainer) SetFlightID added in v0.63.0

func (f *FlightIdContainer) SetFlightID(flightId string)

type Once added in v0.23.0

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

func (*Once) Do added in v0.23.0

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

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

func (*Once) Reset added in v0.23.0

func (o *Once) Reset()

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

type PersistentRoundTripper added in v0.21.0

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

type PreSendABRequestFunc added in v0.21.0

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

type PreSendHttpRequestFunc added in v0.21.0

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

type Retry added in v0.19.0

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 added in v0.19.0

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

type TrackedReadCloser added in v0.21.0

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

func (*TrackedReadCloser) Close added in v0.21.0

func (r *TrackedReadCloser) Close() error

func (*TrackedReadCloser) Read added in v0.21.0

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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