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 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 NopCloseRequest(r *http.Request) *http.Request
- func StringValue(v *string) string
- func ToBool(v interface{}) bool
- func Truncate(str, suffix string, n int) string
- func ValidateHTTPURL(s string) (string, 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
- type ArtifactInfo
- type Authorizer
- type Link
- type Links
- type ResponseBuffer
- 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" )
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(/.*)?$`) // 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 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 StringValue ¶
StringValue returns the value of the string pointer or "" if the pointer is nil
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 it, return the URL in format "scheme://host:port" to avoid the SSRF
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
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) 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