Make redirect middleware can use path

Signed-off-by: MATSUMOTO TAKEAKI <takeaki.matsumoto@linecorp.com>
This commit is contained in:
MATSUMOTO TAKEAKI 2020-07-17 13:58:06 +09:00 committed by Milos Gajdos
parent 53e18a9d9b
commit a1cfd267c8
No known key found for this signature in database
GPG key ID: 01300E5E6D417439

View file

@ -13,6 +13,7 @@ type redirectStorageMiddleware struct {
storagedriver.StorageDriver storagedriver.StorageDriver
scheme string scheme string
host string host string
path string
} }
var _ storagedriver.StorageDriver = &redirectStorageMiddleware{} var _ storagedriver.StorageDriver = &redirectStorageMiddleware{}
@ -37,10 +38,13 @@ func newRedirectStorageMiddleware(sd storagedriver.StorageDriver, options map[st
return nil, fmt.Errorf("no host specified for redirect baseurl") return nil, fmt.Errorf("no host specified for redirect baseurl")
} }
return &redirectStorageMiddleware{StorageDriver: sd, scheme: u.Scheme, host: u.Host}, nil return &redirectStorageMiddleware{StorageDriver: sd, scheme: u.Scheme, host: u.Host, path: u.Path}, nil
} }
func (r *redirectStorageMiddleware) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error) { func (r *redirectStorageMiddleware) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error) {
if r.path != "" {
path = r.path + path
}
u := &url.URL{Scheme: r.scheme, Host: r.host, Path: path} u := &url.URL{Scheme: r.scheme, Host: r.host, Path: path}
return u.String(), nil return u.String(), nil
} }