added pkg/filecli/
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package filecli
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Repository struct {
|
||||
urlobj *url.URL
|
||||
user, pass string
|
||||
resource string
|
||||
}
|
||||
|
||||
func ParsePath(rawpath string) (*Repository, error) {
|
||||
repo := &Repository{}
|
||||
if !strings.Contains(rawpath, "://") {
|
||||
rawpath = "https://" + rawpath
|
||||
}
|
||||
urlobj, err := url.Parse(rawpath)
|
||||
if err != nil {
|
||||
return repo, err
|
||||
}
|
||||
if urlobj.User != nil {
|
||||
repo.user = urlobj.User.Username()
|
||||
repo.pass, _ = urlobj.User.Password()
|
||||
urlobj.User = nil
|
||||
}
|
||||
repo.resource = repo.urlobj.Path
|
||||
repo.urlobj = urlobj
|
||||
repo.urlobj.Path = "/"
|
||||
repo.urlobj = urlobj
|
||||
|
||||
return repo, err
|
||||
}
|
||||
|
||||
func (repo *Repository) File() string {
|
||||
curl := repo.urlobj.JoinPath("/v3/api/file", repo.resource)
|
||||
return curl.String()
|
||||
}
|
||||
|
||||
func (repo *Repository) Files() string {
|
||||
curl := repo.urlobj.JoinPath("/v3/api/files", repo.resource)
|
||||
return curl.String()
|
||||
}
|
||||
|
||||
|
||||
func (repo *Repository) Userinfo() (string, string) {
|
||||
return repo.user, repo.pass
|
||||
}
|
||||
Reference in New Issue
Block a user