mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-25 06:16:58 +00:00
we need a own implementation :/
This commit is contained in:
parent
c97468dd70
commit
ef4d64b0a8
2 changed files with 23 additions and 14 deletions
|
@ -4,7 +4,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/valyala/fasthttp"
|
||||
|
@ -16,7 +16,7 @@ const giteaAPIRepos = "/api/v1/repos/"
|
|||
var ErrorNotFound = errors.New("not found")
|
||||
|
||||
type Client struct {
|
||||
giteaRoot *url.URL
|
||||
giteaRoot string
|
||||
giteaAPIToken string
|
||||
fastClient *fasthttp.Client
|
||||
infoTimeout time.Duration
|
||||
|
@ -29,18 +29,27 @@ type FileResponse struct {
|
|||
Body []byte
|
||||
}
|
||||
|
||||
func joinURL(baseURL *url.URL, paths ...string) string {
|
||||
b := *baseURL
|
||||
b.Path = path.Join(append([]string{b.Path}, paths...)...)
|
||||
return b.String()
|
||||
func joinURL(baseURL string, paths ...string) string {
|
||||
p := make([]string, 0, len(paths))
|
||||
for i := range paths {
|
||||
path := strings.TrimSpace(paths[i])
|
||||
path = strings.Trim(path, "/")
|
||||
if len(path) != 0 {
|
||||
p = append(p, path)
|
||||
}
|
||||
}
|
||||
|
||||
return baseURL + "/" + strings.Join(p, "/")
|
||||
}
|
||||
|
||||
func (f FileResponse) IsEmpty() bool { return len(f.Body) != 0 }
|
||||
|
||||
func NewClient(giteaRoot, giteaAPIToken string) (*Client, error) {
|
||||
rootURL, err := url.Parse(giteaRoot)
|
||||
giteaRoot = strings.Trim(rootURL.String(), "/")
|
||||
|
||||
return &Client{
|
||||
giteaRoot: rootURL,
|
||||
giteaRoot: giteaRoot,
|
||||
giteaAPIToken: giteaAPIToken,
|
||||
infoTimeout: 5 * time.Second,
|
||||
contentTimeout: 10 * time.Second,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue