mirror of
https://github.com/genuinetools/reg.git
synced 2024-09-20 16:51:03 -04:00
e29a4fdc2e
* change accepts header * change accepts header * skip gcr ping check * update go.sum * fix lint errors * fix lint errors * update go.mod
28 lines
627 B
Go
28 lines
627 B
Go
package registry
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// Pingable checks pingable
|
|
func (r *Registry) Pingable() bool {
|
|
// Currently *.gcr.io/v2 can't be ping if users have each projects auth
|
|
return !strings.HasSuffix(r.URL, "gcr.io")
|
|
}
|
|
|
|
// Ping tries to contact a registry URL to make sure it is up and accessible.
|
|
func (r *Registry) Ping(ctx context.Context) error {
|
|
url := r.url("/v2/")
|
|
r.Logf("registry.ping url=%s", url)
|
|
req, err := http.NewRequest("GET", url, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
resp, err := r.Client.Do(req.WithContext(ctx))
|
|
if resp != nil {
|
|
defer resp.Body.Close()
|
|
}
|
|
return err
|
|
}
|