runtime

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2022 License: MIT Imports: 32 Imported by: 912

Documentation

Overview

Package runtime contains various facilities for creating requests and handling responses. The content is intended for SDK authors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeByteArray

func DecodeByteArray(s string, v *[]byte, format Base64Encoding) error

DecodeByteArray will base-64 decode the provided string into v.

func Drain

func Drain(resp *http.Response)

Drain reads the response body to completion then closes it. The bytes read are discarded.

func EncodeByteArray

func EncodeByteArray(v []byte, format Base64Encoding) string

EncodeByteArray will base-64 encode the byte slice v.

func HasStatusCode

func HasStatusCode(resp *http.Response, statusCodes ...int) bool

HasStatusCode returns true if the Response's status code is one of the specified values.

func JoinPaths

func JoinPaths(root string, paths ...string) string

JoinPaths concatenates multiple URL path segments into one path, inserting path separation characters as required. JoinPaths will preserve query parameters in the root path

func MarshalAsByteArray

func MarshalAsByteArray(req *policy.Request, v []byte, format Base64Encoding) error

MarshalAsByteArray will base-64 encode the byte slice v, then calls SetBody. The encoded value is treated as a JSON string.

func MarshalAsJSON

func MarshalAsJSON(req *policy.Request, v interface{}) error

MarshalAsJSON calls json.Marshal() to get the JSON encoding of v then calls SetBody.

func MarshalAsXML

func MarshalAsXML(req *policy.Request, v interface{}) error

MarshalAsXML calls xml.Marshal() to get the XML encoding of v then calls SetBody.

func NewLogPolicy

func NewLogPolicy(o *policy.LogOptions) policy.Policy

NewLogPolicy creates a request/response logging policy object configured using the specified options. Pass nil to accept the default values; this is the same as passing a zero-value options.

func NewPoller

func NewPoller(pollerID string, resp *http.Response, pl pipeline.Pipeline) (*pollers.Poller, error)

NewPoller creates a Poller based on the provided initial response. pollerID - a unique identifier for an LRO, it's usually the client.Method string.

func NewPollerFromResumeToken

func NewPollerFromResumeToken(pollerID string, token string, pl pipeline.Pipeline) (*pollers.Poller, error)

NewPollerFromResumeToken creates a Poller from a resume token string. pollerID - a unique identifier for an LRO, it's usually the client.Method string.

func NewRequest

func NewRequest(ctx context.Context, httpMethod string, endpoint string) (*pipeline.Request, error)

NewRequest creates a new policy.Request with the specified input.

func NewRequestIdPolicy added in v0.20.0

func NewRequestIdPolicy() policy.Policy

func NewResponseError

func NewResponseError(resp *http.Response) error

NewResponseError creates an *azcore.ResponseError from the provided HTTP response. Call this when a service request returns a non-successful status code.

func NewRetryPolicy

func NewRetryPolicy(o *policy.RetryOptions) policy.Policy

NewRetryPolicy creates a policy object configured using the specified options. Pass nil to accept the default values; this is the same as passing a zero-value options.

func NewTelemetryPolicy

func NewTelemetryPolicy(mod, ver string, o *policy.TelemetryOptions) policy.Policy

NewTelemetryPolicy creates a telemetry policy object that adds telemetry information to outgoing HTTP requests. The format is [<application_id> ]azsdk-go-<mod>/<ver> <platform_info>. Pass nil to accept the default values; this is the same as passing a zero-value options.

func Payload

func Payload(resp *http.Response) ([]byte, error)

Payload reads and returns the response body or an error. On a successful read, the response body is cached. Subsequent reads will access the cached value.

func SetMultipartFormData

func SetMultipartFormData(req *policy.Request, formData map[string]interface{}) error

SetMultipartFormData writes the specified keys/values as multi-part form fields with the specified value. File content must be specified as a ReadSeekCloser. All other values are treated as string values.

func SkipBodyDownload added in v0.21.0

func SkipBodyDownload(req *policy.Request)

SkipBodyDownload will disable automatic downloading of the response body.

func UnmarshalAsByteArray

func UnmarshalAsByteArray(resp *http.Response, v *[]byte, format Base64Encoding) error

UnmarshalAsByteArray will base-64 decode the received payload and place the result into the value pointed to by v.

func UnmarshalAsJSON

func UnmarshalAsJSON(resp *http.Response, v interface{}) error

UnmarshalAsJSON calls json.Unmarshal() to unmarshal the received payload into the value pointed to by v.

func UnmarshalAsXML

func UnmarshalAsXML(resp *http.Response, v interface{}) error

UnmarshalAsXML calls xml.Unmarshal() to unmarshal the received payload into the value pointed to by v.

Types

type Base64Encoding

type Base64Encoding int

Base64Encoding is usesd to specify which base-64 encoder/decoder to use when encoding/decoding a slice of bytes to/from a string.

const (
	// Base64StdFormat uses base64.StdEncoding for encoding and decoding payloads.
	Base64StdFormat Base64Encoding = 0

	// Base64URLFormat uses base64.RawURLEncoding for encoding and decoding payloads.
	Base64URLFormat Base64Encoding = 1
)

type BearerTokenPolicy added in v0.20.0

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

BearerTokenPolicy authorizes requests with bearer tokens acquired from a TokenCredential.

func NewBearerTokenPolicy added in v0.20.0

func NewBearerTokenPolicy(cred azcore.TokenCredential, scopes []string, opts *policy.BearerTokenOptions) *BearerTokenPolicy

NewBearerTokenPolicy creates a policy object that authorizes requests with bearer tokens. cred: an azcore.TokenCredential implementation such as a credential object from azidentity scopes: the list of permission scopes required for the token. opts: optional settings. Pass nil to accept default values; this is the same as passing a zero-value options.

func (*BearerTokenPolicy) Do added in v0.20.0

Do authorizes a request with a bearer token

type Pipeline

type Pipeline = pipeline.Pipeline

Pipeline represents a primitive for sending HTTP requests and receiving responses. Its behavior can be extended by specifying policies during construction.

func NewPipeline

func NewPipeline(module, version string, plOpts PipelineOptions, options *policy.ClientOptions) Pipeline

NewPipeline creates a pipeline from connection options, with any additional policies as specified. module, version: used by the telemetry policy, when enabled perCall: additional policies to invoke once per request perRetry: additional policies to invoke once per request and once per retry of that request

type PipelineOptions added in v0.21.0

type PipelineOptions struct {
	AllowedHeaders, AllowedQueryParameters []string
	PerCall, PerRetry                      []policy.Policy
}

PipelineOptions contains Pipeline options for SDK developers

Jump to

Keyboard shortcuts

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