pangea

package
v3.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 23 Imported by: 1

Documentation

Index

Constants

View Source
const (
	TMmultipart TransferMethod = "multipart"
	TMpostURL                  = "post-url"
	TMputURL                   = "put-url"
	TMsourceURL                = "source-url"
)

Variables

This section is empty.

Functions

func B64ToStr

func B64ToStr(enc string) ([]byte, error)

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func BoolValue

func BoolValue(v *bool) bool

BoolValue is a helper routine that returns the value of a bool pointer or a default value if nil

func GetDefaultPangeaLogger

func GetDefaultPangeaLogger() *zerolog.Logger

func GetHashPrefix

func GetHashPrefix(h string, len uint) string

func HashSHA1

func HashSHA1(i string) string

func HashSHA256

func HashSHA256(i string) string

func HashSHA512

func HashSHA512(i string) string

func Int

func Int(v int) *int

Int is a helper routine that allocates a new int value to store v and returns a pointer to it.

func IntValue

func IntValue(v *int) int

IntValue is a helper routine that returns the value of a int pointer or a default value if nil

func PangeaTime

func PangeaTime(v pu.PangeaTimestamp) *pu.PangeaTimestamp

Time is a helper routine that allocates a new PangeaTimestamp value to store v and returns a pointer to it.

func StrToB64

func StrToB64(dec string) string

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

func StringValue

func StringValue(v *string) string

StringValue is a helper routine that returns the value of a string pointer or a default value if nil

func Stringify

func Stringify(obj interface{}) string

Stringify returns the string representation of a json object.

func StringifyIndented

func StringifyIndented(obj interface{}) string

Stringify returns the string representation of a json object.

func Time

func Time(v time.Time) *time.Time

Time is a helper routine that allocates a new time.Time value to store v and returns a pointer to it.

Types

type APIError

type APIError struct {
	BaseError

	// the reponse header of the request if any
	ResponseHeader *ResponseHeader

	// the result of the request
	RawResult json.RawMessage

	// error details
	PangeaErrors PangeaErrors
}

func NewAPIError

func NewAPIError(err error, r *Response) *APIError

func (*APIError) Error

func (e *APIError) Error() string

type AcceptedError

type AcceptedError struct {
	ResponseHeader
	ResultField    any
	AcceptedResult AcceptedResult
	Response
}

TODO: Duplicated fields. Remove ResponseHeader in next breaking update.

func (*AcceptedError) Error

func (e *AcceptedError) Error() string

func (*AcceptedError) Is

func (e *AcceptedError) Is(target error) bool

Is returns whether the provided error equals this error.

func (*AcceptedError) ReqID

func (e *AcceptedError) ReqID() string

ReqID is a helper function to get the request ID

type AcceptedResult added in v3.1.0

type AcceptedResult struct {
	TTLMins      int               `json:"ttl_mins"`
	RetryCounter int               `json:"retry_counter"`
	Location     string            `json:"location"`
	PostURL      string            `json:"post_url"`
	PutURL       string            `json:"put_url"`
	PostFormData map[string]string `json:"post_form_data"`
}

func (AcceptedResult) HasUploadURL added in v3.4.0

func (ar AcceptedResult) HasUploadURL() bool

type BaseError

type BaseError struct {
	// The underlying error that triggered this one, if any.
	Err error

	// the HTTP response
	HTTPResponse *http.Response
}

func (*BaseError) Error

func (e *BaseError) Error() string

type BaseRequest

type BaseRequest struct {
	ConfigID string `json:"config_id,omitempty"`
}

func (*BaseRequest) GetConfigID

func (br *BaseRequest) GetConfigID() string

func (*BaseRequest) SetConfigID

func (br *BaseRequest) SetConfigID(c string)

type BaseService

type BaseService struct {
	Client *Client
}

func NewBaseService

func NewBaseService(name string, baseCfg *Config) BaseService

func (*BaseService) GetPendingRequestID

func (bs *BaseService) GetPendingRequestID() []string

func (*BaseService) PollResultByError

func (bs *BaseService) PollResultByError(ctx context.Context, e AcceptedError) (*PangeaResponse[any], error)

func (*BaseService) PollResultByID

func (bs *BaseService) PollResultByID(ctx context.Context, rid string, v any) (*PangeaResponse[any], error)

func (*BaseService) PollResultRaw

func (bs *BaseService) PollResultRaw(ctx context.Context, rid string) (*PangeaResponse[map[string]any], error)

type BaseServicer

type BaseServicer interface {
	GetPendingRequestID() []string
	PollResultByError(ctx context.Context, e AcceptedError) (*PangeaResponse[any], error)
	PollResultByID(ctx context.Context, rid string, v any) (*PangeaResponse[any], error)
	PollResultRaw(ctx context.Context, requestID string) (*PangeaResponse[map[string]any], error)
}

type Client

type Client struct {

	// Client logger
	Logger zerolog.Logger
	// contains filtered or unexported fields
}

A Client manages communication with the Pangea API.

func NewClient

func NewClient(service string, baseCfg *Config, additionalConfigs ...*Config) *Client

func (*Client) BareDo

func (c *Client) BareDo(ctx context.Context, req *http.Request) (*http.Response, error)

BareDo sends an API request and lets you handle the api response.

If an error or API Error occurs, the error will contain more information. Otherwise you
are supposed to read and close the response's Body.

func (*Client) CheckResponse

func (c *Client) CheckResponse(r *Response, v any) error

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v any, handleQueue bool) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v is nil, and no error happens, the response is returned as is. The provided ctx must be non-nil, if it is nil an error is returned. If it is canceled or times out, ctx.Err() will be returned.

The provided ctx must be non-nil, if it is nil an error is returned. If it is canceled or times out, ctx.Err() will be returned.

func (*Client) FetchAcceptedResponse

func (c *Client) FetchAcceptedResponse(ctx context.Context, reqID string, v interface{}) (*Response, error)

FetchAcceptedResponse retries the

func (*Client) FullPostPresignedURL added in v3.3.0

func (c *Client) FullPostPresignedURL(ctx context.Context, url string, input ConfigIDer, out any, fd FileData) (*Response, error)

func (*Client) GetPendingRequestID

func (c *Client) GetPendingRequestID() []string

func (*Client) GetPresignedURL added in v3.3.0

func (c *Client) GetPresignedURL(ctx context.Context, url string, input any) (*Response, *AcceptedResult, error)

func (*Client) GetRequestIDURL added in v3.1.0

func (c *Client) GetRequestIDURL(rid string) (string, error)

func (*Client) GetURL added in v3.1.0

func (c *Client) GetURL(path string) (string, error)

func (*Client) NewRequest

func (c *Client) NewRequest(method, url string, body any) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the Domain of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*Client) NewRequestForm added in v3.1.0

func (c *Client) NewRequestForm(method, url string, fd FileData, setHeaders bool) (*http.Request, error)

func (*Client) NewRequestMultipart added in v3.1.0

func (c *Client) NewRequestMultipart(method, url string, body any, fd FileData) (*http.Request, error)

func (*Client) PostMultipart added in v3.1.0

func (c *Client) PostMultipart(ctx context.Context, url string, input any, out any, fd FileData) (*Response, error)

func (*Client) ServiceName added in v3.1.0

func (c *Client) ServiceName() string

func (*Client) SetHeaders

func (c *Client) SetHeaders(req *http.Request)

func (*Client) UploadFile added in v3.3.0

func (c *Client) UploadFile(ctx context.Context, url string, tm TransferMethod, fd FileData) error

type ClientOption

type ClientOption func(*Client) error

func ClientWithConfigID

func ClientWithConfigID(cid string) ClientOption

type Config

type Config struct {
	// The Bearer token used to authenticate requests.
	Token string

	// Config ID for multi-config projects
	// @deprecated: Set config_id with options in service initialization if supported
	ConfigID string

	// The HTTP client to be used by the client.
	//  It defaults to defaults.HTTPClient
	HTTPClient *http.Client

	// Base domain for API requests.
	Domain string

	// Set to true to use plain http
	Insecure bool

	// Set to "local" for testing locally
	Enviroment string

	// AdditionalHeaders is a map of additional headers to be sent with the request.
	AdditionalHeaders map[string]string

	// Custom user agent is a string to be added to pangea sdk user agent header and identify app
	CustomUserAgent string

	// if it should retry request
	// if HTTPClient is set in the config this value won't take effect
	Retry bool

	// Enable queued request retry support
	QueuedRetryEnabled bool

	// Timeout used to poll results after 202 (in secs)
	PollResultTimeout time.Duration

	// Retry config defaults to a base retry option
	RetryConfig *RetryConfig

	// Logger
	Logger *zerolog.Logger
}

func (*Config) Copy

func (c *Config) Copy(cfgs ...*Config) *Config

Copy will return a shallow copy of the Config object. If any additional configurations are provided they will be merged into the new config returned.

func (*Config) MergeIn

func (c *Config) MergeIn(cfgs ...*Config)

MergeIn merges the passed in configs into the existing config object.

type ConfigIDer

type ConfigIDer interface {
	SetConfigID(configID string)
	GetConfigID() string
}

type ErrorField

type ErrorField struct {
	Code   string `json:"code"`
	Detail string `json:"detail"`
	Source string `json:"source"`
	Path   string `json:"path,omitempty"`
}

type FileData added in v3.3.0

type FileData struct {
	File    io.Reader
	Name    string
	Details map[string]string
}

type Filter

type Filter map[string]any

type FilterBase

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

func NewFilterBase

func NewFilterBase(f Filter) *FilterBase

func (FilterBase) Filter

func (fb FilterBase) Filter() Filter

type FilterCommon

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

type FilterEqual

type FilterEqual[T any] struct {
	FilterCommon
}

func NewFilterEqual

func NewFilterEqual[T any](name string, filter *Filter) *FilterEqual[T]

func (*FilterEqual[T]) Get

func (f *FilterEqual[T]) Get() *T

func (*FilterEqual[T]) Set

func (f *FilterEqual[T]) Set(value *T)

type FilterMatch

type FilterMatch[T any] struct {
	FilterEqual[T]
}

func NewFilterMatch

func NewFilterMatch[T any](name string, filter *Filter) *FilterMatch[T]

func (*FilterMatch[T]) Contains

func (f *FilterMatch[T]) Contains() []T

func (*FilterMatch[T]) In

func (f *FilterMatch[T]) In() []T

func (*FilterMatch[T]) SetContains

func (f *FilterMatch[T]) SetContains(value []T)

func (*FilterMatch[T]) SetIn

func (f *FilterMatch[T]) SetIn(value []T)

type FilterRange

type FilterRange[T any] struct {
	FilterEqual[T]
}

func NewFilterRange

func NewFilterRange[T any](name string, filter *Filter) *FilterRange[T]

func (*FilterRange[T]) GreaterThan

func (f *FilterRange[T]) GreaterThan() *T

func (*FilterRange[T]) GreaterThanEqual

func (f *FilterRange[T]) GreaterThanEqual() *T

func (*FilterRange[T]) LessThan

func (f *FilterRange[T]) LessThan() *T

func (*FilterRange[T]) LessThanEqual

func (f *FilterRange[T]) LessThanEqual() *T

func (*FilterRange[T]) SetGreaterThan

func (f *FilterRange[T]) SetGreaterThan(value *T)

func (*FilterRange[T]) SetGreaterThanEqual

func (f *FilterRange[T]) SetGreaterThanEqual(value *T)

func (*FilterRange[T]) SetLessThan

func (f *FilterRange[T]) SetLessThan(value *T)

func (*FilterRange[T]) SetLessThanEqual

func (f *FilterRange[T]) SetLessThanEqual(value *T)

type Option

type Option func(*BaseService) error

func WithConfigID

func WithConfigID(cid string) Option

type PangeaErrors

type PangeaErrors struct {
	Errors []ErrorField `json:"errors,omitempty"`
}

type PangeaResponse

type PangeaResponse[T any] struct {
	Response
	Result         *T
	AcceptedResult *AcceptedResult
}

type Response

type Response struct {
	ResponseHeader
	HTTPResponse *http.Response
	// Query raw result
	RawResult json.RawMessage `json:"result"`
	// contains filtered or unexported fields
}

func (Response) MarshalJSON added in v3.6.0

func (r Response) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for CustomType.

func (*Response) UnmarshalResult

func (r *Response) UnmarshalResult(target interface{}) error

type ResponseHeader

type ResponseHeader struct {
	// The request ID
	RequestID *string `json:"request_id"`

	// The time the request was issued, ISO8601
	RequestTime *string `json:"request_time"`

	// The time the response was issued, ISO8601
	ResponseTime *string `json:"response_time"`

	// The HTTP status code msg
	Status *string `json:"status"`

	// The summary of the response
	Summary *string `json:"summary"`
}

func (*ResponseHeader) String

func (r *ResponseHeader) String() string

type RetryConfig

type RetryConfig struct {
	RetryWaitMin time.Duration // Minimum time to wait
	RetryWaitMax time.Duration // Maximum time to wait
	RetryMax     int           // Maximum number of retries
	BackOff      float32       //Exponential back of factor
}

type TransferMethod added in v3.1.0

type TransferMethod string

type TransferRequest added in v3.1.0

type TransferRequest struct {
	TransferMethod TransferMethod `json:"transfer_method,omitempty"`
}

func (TransferRequest) GetTransferMethod added in v3.1.0

func (tr TransferRequest) GetTransferMethod() TransferMethod

type TransferRequester added in v3.1.0

type TransferRequester interface {
	GetTransferMethod() TransferMethod
}

type UnmarshalError

type UnmarshalError struct {
	BaseError

	Bytes []byte
}

func NewUnmarshalError

func NewUnmarshalError(err error, bytes []byte, r *http.Response) *UnmarshalError

func (*UnmarshalError) Error

func (e *UnmarshalError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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