Signed-off-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"net/url"
|
|
"path"
|
|
|
|
"sirherobrine23.com.br/go-bds/go-bds/request/v2"
|
|
)
|
|
|
|
func Upload(Token, Owner, Distribution, Component string, Dpkg io.Reader) error {
|
|
targetHost, err := url.Parse(*Host)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
targetHost.Path = path.Join(targetHost.Path, "/api/packages", Owner, "/debian/pool", Distribution, Component, "/upload")
|
|
|
|
_, err = request.MakeRequestWithStatus(targetHost, &request.Options{
|
|
Method: "PUT",
|
|
Body: Dpkg,
|
|
Header: request.Header{
|
|
"Authorization": fmt.Sprintf("token %s", Token),
|
|
},
|
|
CodeProcess: request.MapCode{
|
|
201: func(res *http.Response) (*http.Response, error) {
|
|
res.Body.Close()
|
|
return nil, nil
|
|
},
|
|
400: func(res *http.Response) (*http.Response, error) {
|
|
res.Body.Close()
|
|
return nil, fmt.Errorf("the package is invalid")
|
|
},
|
|
409: func(res *http.Response) (*http.Response, error) {
|
|
res.Body.Close()
|
|
return nil, fmt.Errorf("a package file with the same combination of parameters exists already")
|
|
},
|
|
},
|
|
})
|
|
return err
|
|
}
|