// NewTypeResolver returns a new initialized TypeResolver.
func NewTypeResolver() TypeResolver {
	ret := &typeResolver{}
	client := http.DefaultClient
	//TODO (iantw): Make this a flag
	timeout, _ := time.ParseDuration("10s")
	client.Timeout = timeout
	ret.getter = util.NewHTTPClient(3, client, util.NewSleeper())
	ret.maxUrls = maxURLImports
	return ret
}
Esempio n. 2
0
// GetFile returns a file from the backing registry
func (m *manager) GetFile(registryName string, url string) (string, error) {
	r, err := m.registryProvider.GetRegistryByName(registryName)
	if err != nil {
		return "", err
	}

	getter := util.NewHTTPClient(3, r, util.NewSleeper())
	body, _, err := getter.Get(url)
	if err != nil {
		return "", err
	}
	return body, nil
}
Esempio n. 3
0
func (tr *typeResolver) performHTTPGet(d util.HTTPDoer, u string, allowMissing bool) (content string, err error) {
	g := tr.c
	if d != nil {
		g = util.NewHTTPClient(3, d, util.NewSleeper())
	}
	r, code, err := g.Get(u)
	if err != nil {
		return "", err
	}

	if allowMissing && code == http.StatusNotFound {
		return "", nil
	}

	if code != http.StatusOK {
		return "", fmt.Errorf(
			"Received status code %d attempting to fetch Type at %s", code, u)
	}

	return r, nil
}