working commit
This commit is contained in:
+49
-1
@@ -15,6 +15,7 @@ import (
|
||||
)
|
||||
|
||||
const fileAPI = "/v3/api/file/"
|
||||
const serviceAPI = "/v3/api/service/"
|
||||
|
||||
type Client struct{}
|
||||
|
||||
@@ -22,6 +23,38 @@ func NewClient() *Client {
|
||||
return &Client{}
|
||||
}
|
||||
|
||||
func (cli *Client) ServiceHello(ctx context.Context, ref string) (bool, error) {
|
||||
var res bool
|
||||
var err error
|
||||
|
||||
ref, err = convertServiceLink(ref)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", ref, nil)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
transport := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
},
|
||||
}
|
||||
client := &http.Client{
|
||||
Transport: transport,
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
res = true
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (cli *Client) FileExists(ctx context.Context, ref string) (bool, error) {
|
||||
var res bool
|
||||
var err error
|
||||
@@ -34,7 +67,6 @@ func (cli *Client) FileExists(ctx context.Context, ref string) (bool, error) {
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
authValue := createBasicAuthPair
|
||||
|
||||
transport := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
@@ -76,6 +108,22 @@ func convertFileLink(ref string) (string, error) {
|
||||
return res, err
|
||||
}
|
||||
|
||||
func convertServiceLink(ref string) (string, error) {
|
||||
var err error
|
||||
var res string
|
||||
if !strings.Contains(ref, "://") {
|
||||
ref = "https://" + ref
|
||||
}
|
||||
url, err := url.Parse(ref)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
url.Path = path.Join(serviceAPI, url.Path)
|
||||
url.User = nil
|
||||
res = url.String()
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (cli *Client) GetFile(ctx context.Context, ref, filename string) error {
|
||||
var err error
|
||||
ref, err = convertFileLink(ref)
|
||||
|
||||
Reference in New Issue
Block a user