Пример #1
0
// NewConfig returns a *ConfigFile object by parsing the given `str`
func NewConfig(str string) (*ConfigFile, error) {
	cfg, err := goconf.ReadConfigBytes([]byte(str))
	if err != nil {
		return nil, err
	}
	return &ConfigFile{cfg: cfg}, err
}
func getVerInfo(d *schema.ResourceData) (c *goconf.ConfigFile, err error) {
	url := fmt.Sprintf("http://%s.release.core-os.net/amd64-usr/current/version.txt", d.Get("channel").(string))
	resp, err := http.Get(url)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	bodyBytes, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	verInfo, err := goconf.ReadConfigBytes(bodyBytes)
	if err != nil {
		return nil, err
	}

	return verInfo, nil
}
func getVerInfo(d *schema.ResourceData) (val string, err error) {
	url := fmt.Sprintf(
		"http://%s.release.core-os.net/amd64-usr/%s/version.txt",
		d.Get("channel").(string),
		d.Get("version").(string))

	resp, err := http.Get(url)
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()

	bodyBytes, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return "", err
	}
	verInfo, err := goconf.ReadConfigBytes(bodyBytes)
	if err != nil {
		return "", err
	}

	return verInfo.GetString("default", "COREOS_VERSION")
}