1
0
This repository has been archived on 2025-03-04. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Matheus Sampaio Queiroga d4fb42f9ac Fix release
Signed-off-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
2025-03-04 18:25:12 -03:00

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
}