client rebuilding in progress
This commit is contained in:
+47
-6
@@ -2,17 +2,27 @@ package filecli
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
PathTypeIdentic = "identic"
|
||||
PathTypePrefix = "prefix"
|
||||
PathTypeRegexp = "regexp"
|
||||
)
|
||||
|
||||
type Repository struct {
|
||||
urlobj *url.URL
|
||||
user, pass string
|
||||
resource string
|
||||
resource string
|
||||
values url.Values
|
||||
}
|
||||
|
||||
func ParsePath(rawpath string) (*Repository, error) {
|
||||
repo := &Repository{}
|
||||
repo := &Repository{
|
||||
values: url.Values{},
|
||||
}
|
||||
if !strings.Contains(rawpath, "://") {
|
||||
rawpath = "https://" + rawpath
|
||||
}
|
||||
@@ -25,14 +35,30 @@ func ParsePath(rawpath string) (*Repository, error) {
|
||||
repo.pass, _ = urlobj.User.Password()
|
||||
urlobj.User = nil
|
||||
}
|
||||
repo.resource = repo.urlobj.Path
|
||||
repo.resource = urlobj.Path
|
||||
urlobj.Path = "/"
|
||||
repo.urlobj = urlobj
|
||||
repo.urlobj.Path = "/"
|
||||
repo.urlobj = urlobj
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func (repo *Repository) SetResource(resource string) {
|
||||
repo.resource = resource
|
||||
}
|
||||
|
||||
func (repo *Repository) PathType(typ string) {
|
||||
repo.values.Set("pathType", typ)
|
||||
}
|
||||
|
||||
func (repo *Repository) File() string {
|
||||
curl := repo.urlobj.JoinPath("/v3/api/file", repo.resource)
|
||||
return curl.String()
|
||||
@@ -43,7 +69,22 @@ func (repo *Repository) Files() string {
|
||||
return curl.String()
|
||||
}
|
||||
|
||||
func (repo *Repository) Collection() string {
|
||||
curl := repo.urlobj.JoinPath("/v3/api/collection", repo.resource)
|
||||
return curl.String()
|
||||
}
|
||||
|
||||
func (repo *Repository) Collections() string {
|
||||
curl := repo.urlobj.JoinPath("/v3/api/collections", repo.resource)
|
||||
return curl.String()
|
||||
}
|
||||
|
||||
func (repo *Repository) Userinfo() (string, string) {
|
||||
return repo.user, repo.pass
|
||||
}
|
||||
|
||||
func (repo *Repository) SetUserinfo(user, pass string) {
|
||||
if user != "" && pass != "" {
|
||||
repo.user, repo.pass = user, pass
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user