added pkg/filecli/

This commit is contained in:
2026-03-02 11:05:29 +02:00
parent 4f7bc221cf
commit 957e655694
8 changed files with 409 additions and 0 deletions
+49
View File
@@ -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
}