pangea

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: MIT Imports: 24 Imported by: 1

Documentation

Index

Constants

This section is empty.

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 added in v2.3.0

func HashSHA1(i string) string

func HashSHA256

func HashSHA256(i string) string

func HashSHA512 added in v2.3.0

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 added in v2.2.0

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
}

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 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 added in v2.3.0

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) (*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 hapens, 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) GetPendingRequestID

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

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body ConfigIDer) (*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) NewRequestMultPart

func (c *Client) NewRequestMultPart(method, urlStr string, body interface{}, file io.Reader) (*http.Request, error)

func (*Client) SetHeaders

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

type ClientOption added in v2.3.0

type ClientOption func(*Client) error

func ClientWithConfigID added in v2.3.0

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 Filter added in v2.3.0

type Filter map[string]any

type FilterBase added in v2.3.0

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

func NewFilterBase added in v2.3.0

func NewFilterBase(f Filter) *FilterBase

func (FilterBase) Filter added in v2.3.0

func (fb FilterBase) Filter() Filter

type FilterCommon added in v2.3.0

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

type FilterEqual added in v2.3.0

type FilterEqual[T any] struct {
	FilterCommon
}

func NewFilterEqual added in v2.3.0

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

func (*FilterEqual[T]) Get added in v2.3.0

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

func (*FilterEqual[T]) Set added in v2.3.0

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

type FilterMatch added in v2.3.0

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

func NewFilterMatch added in v2.3.0

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

func (*FilterMatch[T]) Contains added in v2.3.0

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

func (*FilterMatch[T]) In added in v2.3.0

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

func (*FilterMatch[T]) SetContains added in v2.3.0

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

func (*FilterMatch[T]) SetIn added in v2.3.0

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

type FilterRange added in v2.3.0

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

func NewFilterRange added in v2.3.0

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

func (*FilterRange[T]) GreaterThan added in v2.3.0

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

func (*FilterRange[T]) GreaterThanEqual added in v2.3.0

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

func (*FilterRange[T]) LessThan added in v2.3.0

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

func (*FilterRange[T]) LessThanEqual added in v2.3.0

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

func (*FilterRange[T]) SetGreaterThan added in v2.3.0

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

func (*FilterRange[T]) SetGreaterThanEqual added in v2.3.0

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

func (*FilterRange[T]) SetLessThan added in v2.3.0

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

func (*FilterRange[T]) SetLessThanEqual added in v2.3.0

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

type Option added in v2.3.0

type Option func(*BaseService) error

func WithConfigID added in v2.3.0

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
}

type Response

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

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 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