enhance joinURL and return error on gitea client on start instead while running

This commit is contained in:
6543 2022-06-11 21:42:28 +02:00
parent 35b35c5d67
commit 1596ab9764
4 changed files with 23 additions and 18 deletions

View file

@ -16,7 +16,7 @@ const giteaAPIRepos = "/api/v1/repos/"
var ErrorNotFound = errors.New("not found")
type Client struct {
giteaRoot string
giteaRoot *url.URL
giteaAPIToken string
fastClient *fasthttp.Client
infoTimeout time.Duration
@ -29,18 +29,22 @@ type FileResponse struct {
Body []byte
}
func joinURL(giteaRoot string, paths ...string) string { return giteaRoot + path.Join(paths...) }
func joinURL(baseURL *url.URL, paths ...string) string {
baseURL.Path = path.Join(append([]string{baseURL.Path}, paths...)...)
return baseURL.String()
}
func (f FileResponse) IsEmpty() bool { return len(f.Body) != 0 }
func NewClient(giteaRoot, giteaAPIToken string) *Client {
func NewClient(giteaRoot, giteaAPIToken string) (*Client, error) {
rootURL, err := url.Parse(giteaRoot)
return &Client{
giteaRoot: giteaRoot,
giteaRoot: rootURL,
giteaAPIToken: giteaAPIToken,
infoTimeout: 5 * time.Second,
contentTimeout: 10 * time.Second,
fastClient: getFastHTTPClient(),
}
}, err
}
func (client *Client) GiteaRawContent(targetOwner, targetRepo, ref, resource string) ([]byte, error) {