splitted one operator module to file, account, image operators; splitted operator functions; etc
This commit is contained in:
@@ -15,9 +15,9 @@ func NewClient(transport http.RoundTripper, mwFuncs ...MiddlewareFunc) *Client {
|
||||
if transport == nil {
|
||||
transport = NewDefaultTransport()
|
||||
}
|
||||
for _, mwFunc := range mwFuncs {
|
||||
transport = mwFunc(transport)
|
||||
}
|
||||
for _, mwFunc := range mwFuncs {
|
||||
transport = mwFunc(transport)
|
||||
}
|
||||
httpClient := &http.Client{
|
||||
Transport: transport,
|
||||
}
|
||||
@@ -38,7 +38,6 @@ func (cli *Client) UseMiddleware(mwFunc MiddlewareFunc) {
|
||||
cli.httpClient.Transport = mwFunc(cli.httpClient.Transport)
|
||||
}
|
||||
|
||||
|
||||
// BasicAuthMiddleware
|
||||
func NewBasicAuthMiddleware(user, pass string) MiddlewareFunc {
|
||||
return func(next http.RoundTripper) http.RoundTripper {
|
||||
@@ -60,10 +59,10 @@ func newBasicAuthMW(next http.RoundTripper, user, pass string) *BasicAuthMW {
|
||||
}
|
||||
|
||||
func (tran BasicAuthMW) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
if tran.user != "" && tran.pass != "" {
|
||||
pair := base64.StdEncoding.EncodeToString([]byte(tran.user + ":" + tran.pass))
|
||||
req.Header.Set("Authorization", "Basic "+pair)
|
||||
}
|
||||
if tran.user != "" && tran.pass != "" {
|
||||
pair := base64.StdEncoding.EncodeToString([]byte(tran.user + ":" + tran.pass))
|
||||
req.Header.Set("Authorization", "Basic "+pair)
|
||||
}
|
||||
return tran.next.RoundTrip(req)
|
||||
}
|
||||
|
||||
@@ -110,7 +109,6 @@ func (wrap *DefaultTransport) RoundTrip(req *http.Request) (*http.Response, erro
|
||||
return wrap.transport.RoundTrip(req)
|
||||
}
|
||||
|
||||
|
||||
// ExampleMiddleware
|
||||
func NewExampleMiddleware() MiddlewareFunc {
|
||||
return func(next http.RoundTripper) http.RoundTripper {
|
||||
|
||||
@@ -11,7 +11,7 @@ func (cli *Client) FileInfo(ctx context.Context, rawpath string) (bool, int64, s
|
||||
var err error
|
||||
var exist bool
|
||||
var size int64
|
||||
var digest string
|
||||
var digest string
|
||||
|
||||
ref, err := ParsePath(rawpath)
|
||||
if err != nil {
|
||||
|
||||
+12
-12
@@ -3,8 +3,8 @@ package filecli
|
||||
import (
|
||||
"net/url"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -17,13 +17,13 @@ type Repository struct {
|
||||
urlobj *url.URL
|
||||
user, pass string
|
||||
resource string
|
||||
values url.Values
|
||||
values url.Values
|
||||
}
|
||||
|
||||
func ParsePath(rawpath string) (*Repository, error) {
|
||||
repo := &Repository{
|
||||
values: url.Values{},
|
||||
}
|
||||
values: url.Values{},
|
||||
}
|
||||
if !strings.Contains(rawpath, "://") {
|
||||
rawpath = "https://" + rawpath
|
||||
}
|
||||
@@ -39,17 +39,17 @@ func ParsePath(rawpath string) (*Repository, error) {
|
||||
repo.resource = path.Join("/", urlobj.Path)
|
||||
urlobj.Path = "/"
|
||||
repo.urlobj = urlobj
|
||||
repo.values = urlobj.Query()
|
||||
repo.values = urlobj.Query()
|
||||
return repo, err
|
||||
}
|
||||
|
||||
func (repo *Repository) Raw() string {
|
||||
res := path.Join(repo.urlobj.Host, repo.resource)
|
||||
query := repo.values.Encode()
|
||||
if query != "" {
|
||||
return res + "?" + query
|
||||
}
|
||||
return res
|
||||
query := repo.values.Encode()
|
||||
if query != "" {
|
||||
return res + "?" + query
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func (repo *Repository) SetResource(resource string) {
|
||||
@@ -61,11 +61,11 @@ func (repo *Repository) JoinResource(resource string) {
|
||||
}
|
||||
|
||||
func (repo *Repository) PathType(typ string) {
|
||||
repo.values.Set("pathType", typ)
|
||||
repo.values.Set("pathType", typ)
|
||||
}
|
||||
|
||||
func (repo *Repository) DryRun(yesno bool) {
|
||||
repo.values.Set("dryRun", strconv.FormatBool(yesno))
|
||||
repo.values.Set("dryRun", strconv.FormatBool(yesno))
|
||||
}
|
||||
|
||||
func (repo *Repository) File() string {
|
||||
|
||||
Reference in New Issue
Block a user