utils

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SerializationMethodToContentType = map[string]string{
		"json":      "application/json",
		"form":      "application/x-www-form-urlencoded",
		"multipart": "multipart/form-data",
		"raw":       "application/octet-stream",
		"string":    "text/plain",
	}
)

Functions

func Contains

func Contains(slice []string, item string) bool

func GenerateURL

func GenerateURL(ctx context.Context, serverURL, path string, pathParams interface{}, globals map[string]map[string]map[string]interface{}) (string, error)

func MatchContentType

func MatchContentType(contentType string, pattern string) bool

func PopulateHeaders

func PopulateHeaders(ctx context.Context, req *http.Request, headers interface{})

func PopulateQueryParams

func PopulateQueryParams(ctx context.Context, req *http.Request, queryParams interface{}, globals map[string]map[string]map[string]interface{}) error

func ReplaceParameters

func ReplaceParameters(stringWithParams string, params map[string]string) string

func Retry

func Retry(ctx context.Context, r Retries, action func() (*http.Response, error)) (*http.Response, error)

func SerializeRequestBody

func SerializeRequestBody(ctx context.Context, request interface{}, requestFieldName string, serializationMethod string) (*bytes.Buffer, string, error)

func UnmarshalJsonFromResponseBody

func UnmarshalJsonFromResponseBody(body io.Reader, out interface{}) error

Types

type BackoffStrategy

type BackoffStrategy struct {
	InitialInterval int
	MaxInterval     int
	Exponent        float64
	MaxElapsedTime  int
}

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type Retries

type Retries struct {
	Config      *RetryConfig
	StatusCodes []string
}

type RetryConfig

type RetryConfig struct {
	Strategy              string
	Backoff               *BackoffStrategy
	RetryConnectionErrors bool
}

type SecurityClient

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

func ConfigureSecurityClient

func ConfigureSecurityClient(c HTTPClient, security interface{}) *SecurityClient

func (*SecurityClient) Do

func (c *SecurityClient) Do(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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