示例#1
0
文件: index.go 项目: convox/rack
func (s *SourceIndex) Fetch(out io.Writer) (string, error) {
	tmp, err := ioutil.TempDir("", "")
	if err != nil {
		return "", err
	}

	r, err := urlReader(s.URL)
	if err != nil {
		return "", err
	}

	defer r.Close()

	data, err := ioutil.ReadAll(r)
	if err != nil {
		return "", err
	}

	var index structs.Index

	if err := json.Unmarshal(data, &index); err != nil {
		return "", err
	}

	if err := provider.FromEnv().IndexDownload(&index, tmp); err != nil {
		return "", err
	}

	return tmp, nil
}
示例#2
0
文件: helpers.go 项目: convox/rack
// Provider returns the appropriate provider interface based on the env
func Provider() provider.Provider {
	if os.Getenv("PROVIDER") == "test" {
		return TestProvider
	}

	return provider.FromEnv()
}
示例#3
0
文件: main.go 项目: convox/rack
func init() {
	currentProvider = provider.FromEnv()

	var buf bytes.Buffer

	currentProvider.Initialize(structs.ProviderOptions{
		LogOutput: &buf,
	})
}
示例#4
0
文件: source.go 项目: convox/rack
func urlReader(url_ string) (io.ReadCloser, error) {
	u, err := url.Parse(url_)
	if err != nil {
		return nil, err
	}

	switch u.Scheme {
	case "file":
		fd, err := os.Open(u.Path)
		if err != nil {
			return nil, err
		}
		return fd, nil
	case "object":
		return provider.FromEnv().ObjectFetch(u.Path)
	}

	req, err := http.Get(url_)
	if err != nil {
		return nil, err
	}

	return req.Body, nil
}