internal

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EncodingBase64 is base64 encoding for the data url
	EncodingBase64 = "base64"
	// EncodingASCII is ascii encoding for the data url
	EncodingASCII = "ascii"
)
View Source
const (
	RESTOptionsArgumentName          string = "restOptions"
	RESTSingleOptionsObjectName      string = "RestSingleOptions"
	RESTDistributedOptionsObjectName string = "RestDistributedOptions"
	RESTServerIDScalarName           string = "RestServerId"
	DistributedErrorObjectName       string = "DistributedError"
)

Variables

View Source
var DistributedObjectType rest.ObjectType = rest.ObjectType{
	Description: utils.ToPtr("Distributed execution options for REST requests to multiple servers"),
	Fields: map[string]rest.ObjectField{
		"servers": {
			ObjectField: schema.ObjectField{
				Description: utils.ToPtr("Specify remote servers to receive the request"),
				Type:        schema.NewNullableType(schema.NewArrayType(schema.NewNamedType(RESTServerIDScalarName))).Encode(),
			},
		},
		"parallel": {
			ObjectField: schema.ObjectField{
				Description: utils.ToPtr("Execute requests to remote servers in parallel"),
				Type:        schema.NewNullableNamedType(string(rest.ScalarBoolean)).Encode(),
			},
		},
	},
}

DistributedObjectType represents the object type of REST execution options for distributed servers

View Source
var SingleObjectType rest.ObjectType = rest.ObjectType{
	Description: utils.ToPtr("Execution options for REST requests to a single server"),
	Fields: map[string]rest.ObjectField{
		"servers": {
			ObjectField: schema.ObjectField{
				Description: utils.ToPtr("Specify remote servers to receive the request. If there are many server IDs the server is selected randomly"),
				Type:        schema.NewNullableType(schema.NewArrayType(schema.NewNamedType(RESTServerIDScalarName))).Encode(),
			},
		},
	},
}

SingleObjectType represents the object type of REST execution options for single server

Functions

func MaskString

func MaskString(input string) string

MaskString masks the string value for security

func UnwrapNullableType

func UnwrapNullableType(input schema.Type) (schema.TypeEncoder, bool, error)

UnwrapNullableType unwraps the underlying type of the nullable type

Types

type DataURI

type DataURI struct {
	MediaType  string
	Parameters map[string]string
	Data       string
}

DataURI represents the Data URI scheme

func DecodeDataURI

func DecodeDataURI(input string) (*DataURI, error)

DecodeDataURI decodes data URI scheme data:[<media type>][;<key>=<value>][;<extension>],<data>

type DistributedError

type DistributedError struct {
	schema.ConnectorError

	// Identity of the remote server
	Server string `json:"server" yaml:"server"`
}

DistributedError represents the error response of the remote request

func (DistributedError) Error

func (de DistributedError) Error() string

Error implements the Error interface

type DistributedResponse

type DistributedResponse[T any] struct {
	Results []DistributedResult[T] `json:"results" yaml:"results"`
	Errors  []DistributedError     `json:"errors"  yaml:"errors"`
}

DistributedResponse represents the response object of distributed operations

func NewDistributedResponse

func NewDistributedResponse[T any]() *DistributedResponse[T]

NewDistributedResponse creates an empty DistributedResponse instance

type DistributedResult

type DistributedResult[T any] struct {
	Server string `json:"server" yaml:"server"`
	Data   T      `json:"data"   yaml:"data"`
}

DistributedResult contains the success response of remote requests with a server identity

type Doer

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

Doer abstracts a HTTP client with Do method

type HTTPClient

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

HTTPClient represents a http client wrapper with advanced methods

func NewHTTPClient

func NewHTTPClient(client Doer) *HTTPClient

NewHTTPClient creates a http client wrapper

func (*HTTPClient) Send

func (client *HTTPClient) Send(ctx context.Context, request *RetryableRequest, selection schema.NestedField, resultType schema.Type, restOptions *RESTOptions) (any, error)

Send creates and executes the request and evaluate response selection

func (*HTTPClient) SetTracer

func (client *HTTPClient) SetTracer(tracer *connector.Tracer)

SetTracer sets the tracer instance

type Key

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

Key represents a key string or index

func NewIndexKey

func NewIndexKey(index int) Key

NewIndexKey creates an index key

func NewKey

func NewKey(key string) Key

NewKey creates a string key

func (Key) Index

func (k Key) Index() *int

Index gets the integer key

func (Key) IsEmpty

func (k Key) IsEmpty() bool

IsEmpty checks if the key is empty

func (Key) Key

func (k Key) Key() string

Key gets the string key

func (Key) String

func (k Key) String() string

String implements fmt.Stringer interface

type Keys

type Keys []Key

Keys represent a key slice

func (Keys) String

func (ks Keys) String() string

String implements fmt.Stringer interface

type MetadataCollection

type MetadataCollection []rest.NDCRestSchema

MetadataCollection stores list of REST metadata with helper methods

func (MetadataCollection) GetFunction

GetFunction gets the NDC function by name

func (MetadataCollection) GetProcedure

func (rms MetadataCollection) GetProcedure(name string) (*rest.OperationInfo, *rest.NDCRestSettings, error)

GetProcedure gets the NDC procedure by name

type MultipartWriter

type MultipartWriter struct {
	*multipart.Writer
}

MultipartWriter extends multipart.Writer with helpers

func NewMultipartWriter

func NewMultipartWriter(w io.Writer) *MultipartWriter

NewMultipartWriter creates a MultipartWriter instance

func (*MultipartWriter) WriteDataURI

func (w *MultipartWriter) WriteDataURI(name string, value any, headers http.Header) error

WriteDataURI write a file from data URI string

func (*MultipartWriter) WriteField

func (w *MultipartWriter) WriteField(fieldName, value string, headers http.Header) error

WriteField calls CreateFormField and then writes the given value.

func (*MultipartWriter) WriteJSON

func (w *MultipartWriter) WriteJSON(fieldName string, value any, headers http.Header) error

WriteField calls CreateFormField and then writes the given value with json encoding.

type ParameterItem

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

ParameterItem represents the key-value slice pair

func NewParameterItem

func NewParameterItem(keys Keys, values []string) ParameterItem

NewParameterItem creates a parameter value pair

func (*ParameterItem) Add

func (ssp *ParameterItem) Add(key Key, value string)

func (*ParameterItem) AddKey

func (ssp *ParameterItem) AddKey(key Key)

func (*ParameterItem) AddKeys

func (ssp *ParameterItem) AddKeys(keys []Key)

func (*ParameterItem) AddValue

func (ssp *ParameterItem) AddValue(value string)

func (*ParameterItem) AddValues

func (ssp *ParameterItem) AddValues(values []string)

func (ParameterItem) Keys

func (ssp ParameterItem) Keys() Keys

Keys returns keys of the parameter item

func (*ParameterItem) PrependKey

func (ssp *ParameterItem) PrependKey(key Key)

func (*ParameterItem) PrependKeys

func (ssp *ParameterItem) PrependKeys(keys []Key)

func (*ParameterItem) PrependValue

func (ssp *ParameterItem) PrependValue(value string)

func (*ParameterItem) PrependValues

func (ssp *ParameterItem) PrependValues(values []string)

func (ParameterItem) String

func (ssp ParameterItem) String() string

String implements fmt.Stringer interface

func (ParameterItem) Values

func (ssp ParameterItem) Values() []string

type ParameterItems

type ParameterItems []ParameterItem

func (*ParameterItems) Add

func (ssp *ParameterItems) Add(keys []Key, values []string)

func (ParameterItems) Find

func (ssp ParameterItems) Find(keys []Key) *ParameterItem

func (ParameterItems) FindDefault

func (ssp ParameterItems) FindDefault() *ParameterItem

func (ParameterItems) FindIndex

func (ssp ParameterItems) FindIndex(keys []Key) int

func (ParameterItems) String

func (ssp ParameterItems) String() string

String implements fmt.Stringer interface

type RESTOptions

type RESTOptions struct {
	Servers  []string `json:"servers"  yaml:"serverIds"`
	Parallel bool     `json:"parallel" yaml:"parallel"`

	Explain     bool                  `json:"-" yaml:"-"`
	Distributed bool                  `json:"-" yaml:"-"`
	Settings    *rest.NDCRestSettings `json:"-" yaml:"-"`
}

RESTOptions represent execution options for REST requests

func (*RESTOptions) FromValue

func (ro *RESTOptions) FromValue(value any) error

FromValue parses rest execution options from any value

type RequestBuilder

type RequestBuilder struct {
	Schema    *rest.NDCRestSchema
	Operation *rest.OperationInfo
	Arguments map[string]any
}

RequestBuilder builds requests to the remote service

func NewRequestBuilder

func NewRequestBuilder(restSchema *rest.NDCRestSchema, operation *rest.OperationInfo, arguments map[string]any) *RequestBuilder

NewRequestBuilder creates a new RequestBuilder instance

func (*RequestBuilder) Build

func (c *RequestBuilder) Build() (*RetryableRequest, error)

Build evaluates and builds a RetryableRequest

type RetryableRequest

type RetryableRequest struct {
	RawRequest  *rest.Request
	URL         string
	ServerID    string
	ContentType string
	Headers     http.Header
	Body        io.ReadSeeker
	Timeout     uint
	Retry       *rest.RetryPolicy
}

RetryableRequest wraps the raw request with retryable

func BuildDistributedRequestsWithOptions

func BuildDistributedRequestsWithOptions(request *RetryableRequest, restOptions *RESTOptions) ([]RetryableRequest, error)

BuildDistributedRequestsWithOptions builds distributed requests with options

func (*RetryableRequest) CreateRequest

func (r *RetryableRequest) CreateRequest(ctx context.Context) (*http.Request, context.CancelFunc, error)

CreateRequest creates an HTTP request with body copied

Jump to

Keyboard shortcuts

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