context

package
v0.0.8-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Copyright (c) Microsoft Corporation. Licensed under the MIT License.

Index

Constants

View Source
const (
	CorrelationIdCtxKey = "correlation_id"
	DigestCtxKey        = "digest"
	FileChunkCtxKey     = "file_chunk"
	BlobUrlCtxKey       = "blob_url"
	BlobRangeCtxKey     = "blob_range"
	NamespaceCtxKey     = "namespace"
	ReferenceCtxKey     = "reference"
	RefTypeCtxKey       = "ref_type"
	LoggerCtxKey        = "logger"
)

Context keys.

View Source
const (
	P2PHeaderKey         = "X-MS-Peerd-RequestFromPeer"
	CorrelationHeaderKey = "X-MS-Peerd-CorrelationId"
	NodeHeaderKey        = "X-MS-Peerd-Node"
)

Request headers.

View Source
const (
	PeerResolutionStartLog     = "peer resolution start"
	PeerResolutionStopLog      = "peer resolution stop"
	PeerNotFoundLog            = "peer not found"
	PeerResolutionExhaustedLog = "peer resolution exhausted"
	PeerRequestErrorLog        = "peer request error"
)

Log messages.

View Source
const (
	// KubeConfigPath is the path of the kubeconfig file.
	KubeConfigPath = "/opt/peerd/kubeconfig"
)

Variables

View Source
var (
	NodeName, _ = os.Hostname()
)

Functions

func BlobUrl

func BlobUrl(c Context) string

BlobUrl extracts the blob URL from the incoming request URL.

func FillCorrelationId

func FillCorrelationId(c Context)

FillCorrelationId fills the correlation ID in the context.

func IsRequestFromAPeer

func IsRequestFromAPeer(c Context) bool

IsRequestFromAPeer indicates if the current request is from a peer.

func Logger

func Logger(c Context) zerolog.Logger

Logger gets the logger with request specific fields.

func RangeStartIndex

func RangeStartIndex(rangeValue string) (int64, error)

RangeStartIndex returns the start index of a byte range specified in the given range header value. It expects the range value to be in the format "bytes=startIndex-endIndex".

func SetOutboundHeaders

func SetOutboundHeaders(r *http.Request, c Context)

SetOutboundHeaders sets the mandatory headers for all outbound requests.

Types

type Context

type Context struct {
	*gin.Context
}

Context is the request context that can be passed around to various components to provide request specific information.

func FromContext

func FromContext(c *gin.Context) Context

FromContext creates a new context from the given gin context.

func (Context) Copy

func (c Context) Copy() Context

Copy creates a copy of the context that can be safely used outside the request's scope.

Jump to

Keyboard shortcuts

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