added repocli
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package repocli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (cli *Client) GetUpload(ctx context.Context, rawrepo string) (string, error) {
|
||||
var err error
|
||||
var loc string
|
||||
|
||||
ref, err := NewRepository(rawrepo)
|
||||
if err != nil {
|
||||
return loc, err
|
||||
}
|
||||
uri := ref.Upload()
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, uri, nil)
|
||||
if err != nil {
|
||||
return loc, err
|
||||
}
|
||||
req.Header.Set("User-Agent", cli.userAgent)
|
||||
req.Header.Set("Accept", "*/*")
|
||||
resp, err := cli.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return loc, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
fmt.Printf("=== %++v\n", resp.Header)
|
||||
|
||||
if resp.StatusCode != http.StatusAccepted {
|
||||
err := fmt.Errorf("Unxected response code %s", resp.Status)
|
||||
return loc, err
|
||||
}
|
||||
loc = resp.Header.Get("Location")
|
||||
|
||||
if loc == "" {
|
||||
err := fmt.Errorf("Empty location declaration")
|
||||
return loc, err
|
||||
}
|
||||
return loc, err
|
||||
}
|
||||
Reference in New Issue
Block a user