feat: artifacts client
All checks were successful
default / ensure tests work (push) Successful in 29s

This commit is contained in:
Louis Seubert 2026-09-13 10:53:42 +02:00
commit 402ecfd760
Signed by: louis9902
GPG key ID: 4B9DB28F826553BD

View file

@ -2,16 +2,25 @@ package sdk
import (
"fmt"
"mime"
"net/http"
"net/url"
"strings"
)
// NewClient returns an HTTP client that resolves relative request URLs against
// base and sets the Authorization header to "Bearer token" on every request.
func NewClient(base, token string) *Client {
return &Client{
Client: &http.Client{},
base: base,
token: fmt.Sprintf("Bearer %s", token),
}
}
func (a *Action) Client() *Client {
c := &Client{Client: &http.Client{}}
context := a.Context()
c.base = context.APIURL
c.token = fmt.Sprintf("Bearer %s", context.Token)
return c
return NewClient(context.APIURL, context.Token)
}
type Client struct {
@ -31,3 +40,23 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) {
}
return c.Client.Do(req)
}
// HasContentType reports whether the response content-type matches the given
// media type. An empty content-type is treated as application/octet-stream.
func HasContentType(r *http.Response, mimetype string) bool {
contentType := r.Header.Get("content-type")
if contentType == "" {
return mimetype == "application/octet-stream"
}
for _, v := range strings.Split(contentType, ",") {
t, _, err := mime.ParseMediaType(v)
if err != nil {
break
}
if t == mimetype {
return true
}
}
return false
}