Documentation ¶
Index ¶
- Constants
- Variables
- func BoolValue(v *bool) bool
- func GetAPIVersion(ctx context.Context) string
- func GetAuthMode(ctx context.Context) string
- func GetCarrySession(ctx context.Context) bool
- func GetXRequestID(ctx context.Context) string
- func Int64Value(v *int64) int64
- func JSONCopy(dst, src interface{}) error
- func MatchBlobURLPattern(path string) (repository, digest string, match bool)
- func MatchBlobUploadURLPattern(path string) (repository string, match bool)
- func MatchManifestURLPattern(path string) (repository, reference string, match bool)
- func NewReader(r io.ReadCloser, kb int32) io.ReadCloser
- func NopCloseRequest(r *http.Request) *http.Request
- func ShuffleStringSlice(slice []string)
- func StringValue(v *string) string
- func Title(s string) string
- func ToBool(v interface{}) bool
- func TrimLineBreaks(s string) string
- func Truncate(str, suffix string, n int) string
- func ValidateHTTPURL(s string) (string, error)
- func ValidateQuotaLimit(storageLimit int64) error
- func WithAPIVersion(ctx context.Context, version string) context.Context
- func WithArtifactInfo(ctx context.Context, art ArtifactInfo) context.Context
- func WithAuthMode(ctx context.Context, mode string) context.Context
- func WithCarrySession(ctx context.Context, carrySession bool) context.Context
- func WithXRequestID(ctx context.Context, version string) context.Context
- type ArtifactInfo
- type Authorizer
- type Link
- type Links
- type RateOpts
- type ResponseBuffer
- func (r *ResponseBuffer) Buffer() []byte
- func (r *ResponseBuffer) Flush() (int, error)
- func (r *ResponseBuffer) Header() http.Header
- func (r *ResponseBuffer) Reset() error
- func (r *ResponseBuffer) StatusCode() int
- func (r *ResponseBuffer) Success() bool
- func (r *ResponseBuffer) Write(data []byte) (int, error)
- func (r *ResponseBuffer) WriteHeader(statusCode int)
- type ResponseRecorder
- type Set
- type WorkerPool
Constants ¶
const ( // RepositorySubexp is the name for sub regex that maps to repository name in the url RepositorySubexp = "repository" // ReferenceSubexp is the name for sub regex that maps to reference (tag or digest) url ReferenceSubexp = "reference" // DigestSubexp is the name for sub regex that maps to digest in the url DigestSubexp = "digest" )
const KBRATE = 1024 / 8
Variables ¶
var ( // V2ManifestURLRe is the regular expression for matching request v2 handler to view/delete manifest V2ManifestURLRe = regexp.MustCompile(fmt.Sprintf(`^/v2/(?P<%s>%s)/manifests/(?P<%s>.*)$`, RepositorySubexp, reference.NameRegexp.String(), ReferenceSubexp)) // V2TagListURLRe is the regular expression for matching request to v2 handler to list tags V2TagListURLRe = regexp.MustCompile(fmt.Sprintf(`^/v2/(?P<%s>%s)/tags/list`, RepositorySubexp, reference.NameRegexp.String())) // V2BlobURLRe is the regular expression for matching request to v2 handler to retrieve head/delete a blob V2BlobURLRe = regexp.MustCompile(fmt.Sprintf(`^/v2/(?P<%s>%s)/blobs/(?P<%s>%s)$`, RepositorySubexp, reference.NameRegexp.String(), DigestSubexp, digest.DigestRegexp.String())) // V2BlobUploadURLRe is the regular expression for matching the request to v2 handler to upload a blob, the upload uuid currently is not put into a group V2BlobUploadURLRe = regexp.MustCompile(fmt.Sprintf(`^/v2/(?P<%s>%s)/blobs/uploads[/a-zA-Z0-9\-_\.=]*$`, RepositorySubexp, reference.NameRegexp.String())) // V2CatalogURLRe is the regular expression for matching the request to v2 handler to list catalog V2CatalogURLRe = regexp.MustCompile(`^/v2/_catalog(/.*)?$`) // V2ReferrersURLRe is the regular expression for matching request to v2 handler to list referrers V2ReferrersURLRe = regexp.MustCompile(fmt.Sprintf(`^/v2/(?P<%s>%s)/referrers/(?P<%s>.*)$`, RepositorySubexp, reference.NameRegexp.String(), ReferenceSubexp)) // RepositoryNameRe is the regular expression for matching repository name RepositoryNameRe = regexp.MustCompile(fmt.Sprintf("^%s$", reference.NameRegexp)) )
Functions ¶
func GetAPIVersion ¶
GetAPIVersion gets the API version from the context
func GetAuthMode ¶
GetAuthMode gets the auth mode from the context
func GetCarrySession ¶
GetCarrySession gets the "carry session" from the context indicates whether the request carries session or not
func GetXRequestID ¶
GetXRequestID gets the XRequestID from the context
func Int64Value ¶
Int64Value returns the value of the int64 pointer or 0 if the pointer is nil
func JSONCopy ¶
func JSONCopy(dst, src interface{}) error
JSONCopy copy from src to dst with json marshal and unmarshal. NOTE: copy from one struct to another struct may miss some values depend on the json tag in the fields, you should know what will happened when call this function.
func MatchBlobURLPattern ¶
MatchBlobURLPattern checks whether the provided path matches the blob URL pattern, if does, returns the repository and reference as well
func MatchBlobUploadURLPattern ¶
MatchBlobUploadURLPattern checks whether the provided path matches the blob upload URL pattern, if does, returns the repository as well
func MatchManifestURLPattern ¶
MatchManifestURLPattern checks whether the provided path matches the manifest URL pattern, if does, returns the repository and reference as well
func NewReader ¶
func NewReader(r io.ReadCloser, kb int32) io.ReadCloser
NewReader returns a Reader that is rate limited
func ShuffleStringSlice ¶
func ShuffleStringSlice(slice []string)
ShuffleStringSlice shuffles the string slice in place.
func StringValue ¶
StringValue returns the value of the string pointer or "" if the pointer is nil
func Title ¶
Title uppercase the first character, and lower case the rest, for example covert MANUAL to Manual
func TrimLineBreaks ¶
TrimLineBreaks trims line breaks in string.
func Truncate ¶
Truncate tries to append the "suffix" to the "str". If the length of the appended string exceeds "n", the function truncates the "str" to make sure the "suffix" is appended
func ValidateHTTPURL ¶
ValidateHTTPURL checks whether the provided string is a valid HTTP URL. If it is, return the URL in format "scheme://host:port" to avoid the SSRF
func ValidateQuotaLimit ¶
func WithAPIVersion ¶
WithAPIVersion returns a context with APIVersion set
func WithArtifactInfo ¶
func WithArtifactInfo(ctx context.Context, art ArtifactInfo) context.Context
WithArtifactInfo returns a context with ArtifactInfo set
func WithAuthMode ¶
WithAuthMode returns a context with auth mode set
func WithCarrySession ¶
WithCarrySession returns a context with "carry session" set that indicates whether the request carries session or not
Types ¶
type ArtifactInfo ¶
type ArtifactInfo struct { Repository string Reference string ProjectName string Digest string Tag string BlobMountRepository string BlobMountProjectName string BlobMountDigest string }
ArtifactInfo wraps the artifact info extracted from the request to "/v2/"
func GetArtifactInfo ¶
func GetArtifactInfo(ctx context.Context) (art ArtifactInfo)
GetArtifactInfo gets the ArtifactInfo from the context
type Links ¶
type Links []*Link
Links is a link object array
func ParseLinks ¶
ParseLinks parses the link header into Links e.g. <http://example.com/TheBook/chapter2>; rel="previous"; title="previous chapter" , <http://example.com/TheBook/chapter4>; rel="next"; title="next chapter"
type ResponseBuffer ¶
type ResponseBuffer struct {
// contains filtered or unexported fields
}
ResponseBuffer is a wrapper for the http.ResponseWriter to buffer the response data
func NewResponseBuffer ¶
func NewResponseBuffer(w http.ResponseWriter) *ResponseBuffer
NewResponseBuffer creates a ResponseBuffer object
func (*ResponseBuffer) Buffer ¶
func (r *ResponseBuffer) Buffer() []byte
Buffer returns the buffer of ResponseBuffer
func (*ResponseBuffer) Flush ¶
func (r *ResponseBuffer) Flush() (int, error)
Flush the status code, header and data into the underlying response writer
func (*ResponseBuffer) Header ¶
func (r *ResponseBuffer) Header() http.Header
Header returns the header of the buffer
func (*ResponseBuffer) Reset ¶
func (r *ResponseBuffer) Reset() error
Reset reset the response buffer
func (*ResponseBuffer) StatusCode ¶
func (r *ResponseBuffer) StatusCode() int
StatusCode returns the status code
func (*ResponseBuffer) Success ¶
func (r *ResponseBuffer) Success() bool
Success checks whether the status code is >= 200 & <= 399
func (*ResponseBuffer) Write ¶
func (r *ResponseBuffer) Write(data []byte) (int, error)
Write writes the data into the buffer without writing to the underlying response writer
func (*ResponseBuffer) WriteHeader ¶
func (r *ResponseBuffer) WriteHeader(statusCode int)
WriteHeader writes the status code into the buffer without writing to the underlying response writer
type ResponseRecorder ¶
type ResponseRecorder struct { StatusCode int http.ResponseWriter // contains filtered or unexported fields }
ResponseRecorder is a wrapper for the http.ResponseWriter to record the response status code
func NewResponseRecorder ¶
func NewResponseRecorder(w http.ResponseWriter) *ResponseRecorder
NewResponseRecorder creates a response recorder
func (*ResponseRecorder) Success ¶
func (r *ResponseRecorder) Success() bool
Success checks whether the status code is >= 200 & <= 399
func (*ResponseRecorder) Write ¶
func (r *ResponseRecorder) Write(data []byte) (int, error)
Write records the status code before writing data to the underlying writer
func (*ResponseRecorder) WriteHeader ¶
func (r *ResponseRecorder) WriteHeader(statusCode int)
WriteHeader records the status code before writing the code to the underlying writer
type Set ¶
type Set map[interface{}]void
Set a simple set
type WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool controls the concurrency limit of task/process
func NewWorkerPool ¶
func NewWorkerPool(size int32) *WorkerPool
NewWorkerPool creates a new worker pool with specified size
func (*WorkerPool) GetWorker ¶
func (w *WorkerPool) GetWorker()
GetWorker hangs until a free worker available
func (*WorkerPool) ReleaseWorker ¶
func (w *WorkerPool) ReleaseWorker()
ReleaseWorker hangs until the worker return back into the pool