package shared
import "github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/shared"
Index ¶
- Constants
- Variables
- func Delay(ctx context.Context, delay time.Duration) error
- func EndpointToScope(endpoint string) string
- func GetJSON(resp *http.Response) (map[string]interface{}, error)
- func HasStatusCode(resp *http.Response, statusCodes ...int) bool
- func NewResponseError(resp *http.Response) error
- func NopCloser(rs io.ReadSeeker) io.ReadSeekCloser
- func Payload(resp *http.Response) ([]byte, error)
- func RetryAfter(resp *http.Response) time.Duration
- type AccessToken
- type AcquireResource
- type CtxWithHTTPHeaderKey
- type CtxWithRetryOptionsKey
- type ExpiringResource
- func NewExpiringResource(ar AcquireResource) *ExpiringResource
- func (er *ExpiringResource) GetResource(state interface{}) (interface{}, error)
- type NopClosingBytesReader
- func NewNopClosingBytesReader(data []byte) *NopClosingBytesReader
- func (r *NopClosingBytesReader) Bytes() []byte
- func (*NopClosingBytesReader) Close() error
- func (r *NopClosingBytesReader) Read(b []byte) (n int, err error)
- func (r *NopClosingBytesReader) Seek(offset int64, whence int) (int64, error)
- func (r *NopClosingBytesReader) Set(b []byte)
- type ResponseError
- type TokenCredential
- type TokenRequestOptions
Constants ¶
const ( ContentTypeAppJSON = "application/json" ContentTypeAppXML = "application/xml" )
const ( HeaderAuthorization = "Authorization" HeaderAuxiliaryAuthorization = "x-ms-authorization-auxiliary" HeaderAzureAsync = "Azure-AsyncOperation" HeaderContentLength = "Content-Length" HeaderContentType = "Content-Type" HeaderLocation = "Location" HeaderOperationLocation = "Operation-Location" HeaderRetryAfter = "Retry-After" HeaderUserAgent = "User-Agent" HeaderXmsDate = "x-ms-date" )
const ( // Module is the name of the calling module used in telemetry data. Module = "azcore" // Version is the semantic version (see http://semver.org) of this module. Version = "v0.21.1" )
const BearerTokenPrefix = "Bearer "
const (
DefaultMaxRetries = 3
)
Variables ¶
ErrNoBody is returned if the response didn't contain a body.
Functions ¶
func Delay ¶
Delay waits for the duration to elapse or the context to be cancelled.
func EndpointToScope ¶
EndpointToScope converts the provided URL endpoint to its default scope.
func GetJSON ¶
GetJSON reads the response body into a raw JSON object. It returns ErrNoBody if there was no content.
func HasStatusCode ¶
HasStatusCode returns true if the Response's status code is one of the specified values.
func NewResponseError ¶
NewResponseError creates a new *ResponseError from the provided HTTP response.
func NopCloser ¶
func NopCloser(rs io.ReadSeeker) io.ReadSeekCloser
NopCloser returns a ReadSeekCloser with a no-op close method wrapping the provided io.ReadSeeker.
func Payload ¶
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 RetryAfter ¶
RetryAfter returns non-zero if the response contains a Retry-After header value.
Types ¶
type AccessToken ¶
AccessToken represents an Azure service bearer access token with expiry information.
type AcquireResource ¶
type AcquireResource func(state interface{}) (newResource interface{}, newExpiration time.Time, err error)
AcquireResource abstracts a method for refreshing an expiring resource.
type CtxWithHTTPHeaderKey ¶
type CtxWithHTTPHeaderKey struct{}
CtxWithHTTPHeaderKey is used as a context key for adding/retrieving http.Header.
type CtxWithRetryOptionsKey ¶
type CtxWithRetryOptionsKey struct{}
CtxWithRetryOptionsKey is used as a context key for adding/retrieving RetryOptions.
type ExpiringResource ¶
type ExpiringResource struct {
// contains filtered or unexported fields
}
ExpiringResource is a temporal resource (usually a credential) that requires periodic refreshing.
func NewExpiringResource ¶
func NewExpiringResource(ar AcquireResource) *ExpiringResource
NewExpiringResource creates a new ExpiringResource that uses the specified AcquireResource for refreshing.
func (*ExpiringResource) GetResource ¶
func (er *ExpiringResource) GetResource(state interface{}) (interface{}, error)
GetResource returns the underlying resource. If the resource is fresh, no refresh is performed.
type NopClosingBytesReader ¶
type NopClosingBytesReader struct {
// contains filtered or unexported fields
}
NopClosingBytesReader is an io.ReadSeekCloser around a byte slice. It also provides direct access to the byte slice to avoid rereading.
func NewNopClosingBytesReader ¶
func NewNopClosingBytesReader(data []byte) *NopClosingBytesReader
NewNopClosingBytesReader creates a new NopClosingBytesReader around the specified byte slice.
func (*NopClosingBytesReader) Bytes ¶
func (r *NopClosingBytesReader) Bytes() []byte
Bytes returns the underlying byte slice.
func (*NopClosingBytesReader) Close ¶
func (*NopClosingBytesReader) Close() error
Close implements the io.Closer interface.
func (*NopClosingBytesReader) Read ¶
func (r *NopClosingBytesReader) Read(b []byte) (n int, err error)
Read implements the io.Reader interface.
func (*NopClosingBytesReader) Seek ¶
func (r *NopClosingBytesReader) Seek(offset int64, whence int) (int64, error)
Seek implements the io.Seeker interface.
func (*NopClosingBytesReader) Set ¶
func (r *NopClosingBytesReader) Set(b []byte)
Set replaces the existing byte slice with the specified byte slice and resets the reader.
type ResponseError ¶
type ResponseError struct { // ErrorCode is the error code returned by the resource provider if available. ErrorCode string // StatusCode is the HTTP status code as defined in https://pkg.go.dev/net/http#pkg-constants. StatusCode int // RawResponse is the underlying HTTP response. RawResponse *http.Response }
ResponseError is returned when a request is made to a service and the service returns a non-success HTTP status code. Use errors.As() to access this type in the error chain.
func (*ResponseError) Error ¶
func (e *ResponseError) Error() string
Error implements the error interface for type ResponseError. Note that the message contents are not contractual and can change over time.
type TokenCredential ¶
type TokenCredential interface { // GetToken requests an access token for the specified set of scopes. GetToken(ctx context.Context, options TokenRequestOptions) (*AccessToken, error) }
TokenCredential represents a credential capable of providing an OAuth token.
type TokenRequestOptions ¶
type TokenRequestOptions struct { // Scopes contains the list of permission scopes required for the token. Scopes []string // TenantID contains the tenant ID to use in a multi-tenant authentication scenario, if TenantID is set // it will override the tenant ID that was added at credential creation time. TenantID string }
TokenRequestOptions contain specific parameter that may be used by credentials types when attempting to get a token.
Source Files ¶
constants.go expiring_resource.go response_error.go shared.go
- Version
- v0.21.1
- Published
- Feb 4, 2022
- Platform
- windows/amd64
- Imports
- 14 packages
- Last checked
- 1 hour ago –
Tools for package owners.