working commit
This commit is contained in:
+21
-14
@@ -13,40 +13,47 @@ import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
username string
|
||||
password string
|
||||
}
|
||||
type Client struct{}
|
||||
|
||||
func NewClient() *Client {
|
||||
return &Client{}
|
||||
}
|
||||
|
||||
func NewClientWithAuth(username, password string) *Client {
|
||||
return &Client{
|
||||
username: username,
|
||||
password: password,
|
||||
func convertServiceURI(ref string) (string, error) {
|
||||
var err error
|
||||
var res string
|
||||
const serviceAPI = "/v3/api/service/"
|
||||
const serviceScheme = "https"
|
||||
uri, err := url.Parse(ref)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
uri.Path = serviceAPI
|
||||
uri.Scheme = serviceScheme
|
||||
res = uri.String()
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (cli *Client) ServiceHello(ctx context.Context, ref string, timeout time.Duration) (bool, error) {
|
||||
func (cli *Client) ServiceHello(ctx context.Context, serviceuri string, timeout time.Duration) (bool, error) {
|
||||
var res bool
|
||||
var err error
|
||||
|
||||
ctx, _ = context.WithTimeout(ctx, timeout)
|
||||
|
||||
ref, err = convertServiceRefer(ref)
|
||||
serviceuri, _, _, err = repackServiceURI(serviceuri)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, ref, nil)
|
||||
serviceuri, err = convertServiceURI(serviceuri)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, serviceuri, nil)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
transport := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
|
||||
Reference in New Issue
Block a user