mirror of
https://github.com/distribution/distribution.git
synced 2025-09-24 20:46:52 +00:00
cleanup: move init funcs to the top of the source (#4172)
This commit is contained in:
@@ -20,6 +20,13 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// init registers the cloudfront layerHandler backend.
|
||||
func init() {
|
||||
if err := storagemiddleware.Register("cloudfront", newCloudFrontStorageMiddleware); err != nil {
|
||||
logrus.Errorf("failed to register cloudfront middleware: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// cloudFrontStorageMiddleware provides a simple implementation of layerHandler that
|
||||
// constructs temporary signed CloudFront URLs from the storagedriver layer URL,
|
||||
// then issues HTTP Temporary Redirects to this CloudFront content URL.
|
||||
@@ -224,10 +231,3 @@ func (lh *cloudFrontStorageMiddleware) RedirectURL(r *http.Request, path string)
|
||||
}
|
||||
return cfURL, nil
|
||||
}
|
||||
|
||||
// init registers the cloudfront layerHandler backend.
|
||||
func init() {
|
||||
if err := storagemiddleware.Register("cloudfront", newCloudFrontStorageMiddleware); err != nil {
|
||||
logrus.Errorf("failed to register cloudfront middleware: %v", err)
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,12 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func init() {
|
||||
if err := storagemiddleware.Register("redirect", newRedirectStorageMiddleware); err != nil {
|
||||
logrus.Errorf("tailed to register redirect storage middleware: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
type redirectStorageMiddleware struct {
|
||||
storagedriver.StorageDriver
|
||||
scheme string
|
||||
@@ -51,9 +57,3 @@ func (r *redirectStorageMiddleware) RedirectURL(_ *http.Request, urlPath string)
|
||||
u := &url.URL{Scheme: r.scheme, Host: r.host, Path: urlPath}
|
||||
return u.String(), nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
if err := storagemiddleware.Register("redirect", newRedirectStorageMiddleware); err != nil {
|
||||
logrus.Errorf("tailed to register redirect storage middleware: %v", err)
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,14 @@ import (
|
||||
// Test hooks up gocheck into the "go test" runner.
|
||||
func Test(t *testing.T) { check.TestingT(t) }
|
||||
|
||||
// randomBytes pre-allocates all of the memory sizes needed for the test. If
|
||||
// anything panics while accessing randomBytes, just make this number bigger.
|
||||
var randomBytes = make([]byte, 128<<20)
|
||||
|
||||
func init() {
|
||||
_, _ = crand.Read(randomBytes) // always returns len(randomBytes) and nil error
|
||||
}
|
||||
|
||||
// RegisterSuite registers an in-process storage driver test suite with
|
||||
// the go test runner.
|
||||
func RegisterSuite(driverConstructor DriverConstructor, skipCheck SkipCheck) {
|
||||
@@ -1343,14 +1351,6 @@ func randomFilename(length int64) string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// randomBytes pre-allocates all of the memory sizes needed for the test. If
|
||||
// anything panics while accessing randomBytes, just make this number bigger.
|
||||
var randomBytes = make([]byte, 128<<20)
|
||||
|
||||
func init() {
|
||||
_, _ = crand.Read(randomBytes) // always returns len(randomBytes) and nil error
|
||||
}
|
||||
|
||||
func randomContents(length int64) []byte {
|
||||
return randomBytes[:length]
|
||||
}
|
||||
|
Reference in New Issue
Block a user