当前位置: 首页>>代码示例>>Golang>>正文


Golang candiedyaml.NewDecoder函数代码示例

本文整理汇总了Golang中github.com/cloudfoundry-incubator/candiedyaml.NewDecoder函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDecoder函数的具体用法?Golang NewDecoder怎么用?Golang NewDecoder使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewDecoder函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: parseStartCommand

func parseStartCommand(cloudfoundryDropletDir string) (startCommand []string) {
	stagingInfoFile, err := os.Open(cloudfoundryDropletDir + "/staging_info.yml")
	if err == nil {
		stagingInfo := new(StagingInfoYml)
		decoder := candiedyaml.NewDecoder(stagingInfoFile)
		err = decoder.Decode(stagingInfo)
		if err != nil {
			log.Fatalf("Failed to decode document: %s", err)
		}
		startCommand = strings.Split(stagingInfo.StartCommand, " ")
		if startCommand[0] != "" {
			return
		}
		procfileFile, err := os.Open(cloudfoundryDropletDir + "/app/Procfile")
		if err == nil {
			procfileInfo := new(ProcfileYml)
			decoder := candiedyaml.NewDecoder(procfileFile)
			err = decoder.Decode(procfileInfo)
			if err != nil {
				log.Fatalf("Failed to decode document: %s", err)
			}
			startCommand = strings.Split(procfileInfo.Web, " ")
			return
		}
	}
	log.Fatal("Unable to find staging_info.yml")
	return
}
开发者ID:ronakbanka,项目名称:cloudfocker,代码行数:28,代码来源:run_config.go

示例2: generate

func generate(source io.Reader) {
	var spec builder.DeploymentSpec

	var err error

	err = candiedyaml.NewDecoder(source).Decode(&spec)
	if err != nil {
		panic(err)
	}

	former := aws.New(spec.Description)

	region := os.Getenv("AWS_DEFAULT_REGION")
	if region == "" {
		region = "us-east-1"
	}

	builder := builder.New(spec, region)

	err = builder.Build(former)
	if err != nil {
		panic(err)
	}

	err = json.NewEncoder(os.Stdout).Encode(former.Template)
	if err != nil {
		fatal(err)
	}
}
开发者ID:mmb,项目名称:boosh,代码行数:29,代码来源:generate.go

示例3: ParseFromIoReader

func (p yamlParser) ParseFromIoReader(r io.Reader) ([]models.Plugin, error) {
	document := new(interface{})
	decoder := candiedyaml.NewDecoder(r)
	err := decoder.Decode(document)

	if err != nil {
		p.logger.Write([]byte("Failed to decode document:" + err.Error()))
		return []models.Plugin{}, err
	}

	output, _ := expandProperties(*document)

	plugins := p.pluginsModel.PopulateModel(output)
	mirrorsInterface := output.(map[interface{}]interface{})["mirrors"]
	if mirrorsInterface == nil {
		return plugins, nil
	}
	for _, mirror := range mirrorsInterface.([]interface{}) {
		mirrorPlugins, err := p.ParseFromMirror(mirror.(string))
		if err != nil {
			return []models.Plugin{}, err
		}
		plugins = p.mergePlugins(plugins, mirrorPlugins)
	}
	return plugins, nil
}
开发者ID:ArthurHlt,项目名称:cli-plugin-repo,代码行数:26,代码来源:parser.go

示例4: Load

func Load(restoreConfigPath string) (Config, error) {
	file, err := os.Open(restoreConfigPath)
	if err != nil {
		return Config{}, err
	}

	var config Config
	if err := candiedyaml.NewDecoder(file).Decode(&config); err != nil {
		return Config{}, err
	}

	return config, nil
}
开发者ID:yacloud-io,项目名称:cf-redis-broker,代码行数:13,代码来源:config.go

示例5: Load

func Load(path string) (*Config, error) {
	file, err := os.Open(path)
	if err != nil {
		return nil, err
	}

	config := &Config{}
	if err := candiedyaml.NewDecoder(file).Decode(config); err != nil {
		return nil, err
	}

	return config, nil
}
开发者ID:nimbus-cloud,项目名称:cf-redis-broker,代码行数:13,代码来源:config.go

示例6: ParseConfig

func ParseConfig(path string) (Config, error) {
	file, err := os.Open(path)
	if err != nil {
		return Config{}, err
	}

	var config Config
	if err := candiedyaml.NewDecoder(file).Decode(&config); err != nil {
		return Config{}, err
	}

	return config, ValidateConfig(config.RedisConfiguration)
}
开发者ID:nimbus-cloud,项目名称:cf-redis-broker,代码行数:13,代码来源:config.go

示例7: parseManifest

func parseManifest(file io.Reader) (yamlMap generic.Map, err error) {
	decoder := candiedyaml.NewDecoder(file)
	yamlMap = generic.NewMap()
	err = decoder.Decode(yamlMap)
	if err != nil {
		return
	}

	if !generic.IsMappable(yamlMap) {
		err = errors.New(T("Invalid manifest. Expected a map"))
		return
	}

	return
}
开发者ID:nttlabs,项目名称:cli,代码行数:15,代码来源:manifest_disk_repository.go

示例8: ParseConfig

func ParseConfig(reader io.Reader) (*Config, error) {
	var config Config
	if err := candiedyaml.NewDecoder(reader).Decode(&config); err != nil {
		return nil, err
	}
	err := ValidateConfig(&config)
	if err != nil {
		return nil, err
	}

	if err := json.Unmarshal([]byte(config.Rabbitmq.Policy.EncodedDefinition), &config.Rabbitmq.Policy.Definition); err != nil {
		return nil, err
	}

	return &config, nil
}
开发者ID:pivotal-cf,项目名称:cf-rabbitmq-broker,代码行数:16,代码来源:config.go

示例9: ConvertIgnoreOmitEmpty

func ConvertIgnoreOmitEmpty(from, to interface{}) error {
	var buffer bytes.Buffer

	encoder := yaml.NewEncoder(&buffer)
	encoder.IgnoreOmitEmpty = true

	if err := encoder.Encode(from); err != nil {
		return err
	}

	decoder := yaml.NewDecoder(&buffer)

	if err := decoder.Decode(to); err != nil {
		return err
	}

	return nil
}
开发者ID:carriercomm,项目名称:os,代码行数:18,代码来源:util.go

示例10: release

func (runner *Runner) release(buildpackDir string) (Release, error) {
	output := new(bytes.Buffer)

	err := runner.run(exec.Command(path.Join(buildpackDir, "bin", "release"), runner.config.AppDir()), output)
	if err != nil {
		return Release{}, err
	}

	decoder := candiedyaml.NewDecoder(output)

	var parsedRelease Release

	err = decoder.Decode(&parsedRelease)
	if err != nil {
		return Release{}, newDescriptiveError(err, "buildpack's release output invalid")
	}

	return parsedRelease, nil
}
开发者ID:hatofmonkeys,项目名称:cloudfocker,代码行数:19,代码来源:runner.go

示例11: startCommandFromStagingInfo

func startCommandFromStagingInfo(stagingInfoPath string) (string, error) {
	stagingInfoFile, err := os.Open(stagingInfoPath)
	if err != nil {
		if os.IsNotExist(err) {
			return "", nil
		}
		return "", err
	}
	defer stagingInfoFile.Close()

	info := stagingInfo{}

	err = candiedyaml.NewDecoder(stagingInfoFile).Decode(&info)
	if err != nil {
		return "", errors.New("invalid YAML")
	}

	return info.StartCommand, nil
}
开发者ID:davidwadden,项目名称:lattice-release,代码行数:19,代码来源:main.go

示例12: parseYAMLStream

// parseYAMLStream takes an encoded YAML stream and turns it into a slice of JSON-marshalable
// objects, one for each document in the stream.
func parseYAMLStream(in io.Reader) ([]interface{}, error) {
	// Use candiedyaml because it's the only one that supports streams.
	decoder := candiedyaml.NewDecoder(in)
	var document interface{}
	stream := []interface{}{}
	for {
		err := decoder.Decode(&document)
		if err != nil {
			if strings.Contains(err.Error(), "Expected document start at line") {
				return stream, nil
			}
			return nil, err
		}
		// Now it's held in document but we have to do a bit of a dance to get it in a form that can
		// be marshaled as JSON for our API response.  The fundamental problem is that YAML is a
		// superset of JSON in that it can represent non-string keys, and full IEEE floating point
		// values (NaN etc).  JSON only allows string keys and its definition of a number is based
		// around a sequence of digits.

		// Kubernetes does not make use of these features, as it uses YAML as just "pretty JSON".
		// Consequently this does not affect Helm either.  However, both candiedyaml and go-yaml
		// return types that are too wide for JSON marshalling (i.e. map[interface{}]interface{}
		// instead of map[string]interface{}), so we have to do some explicit conversion.  Luckily,
		// ghodss/yaml has code to help with this, since decoding from YAML to JSON-marshalable
		// values is exactly the problem that it was designed to solve.

		// 1) Marshal it back to YAML string.
		yamlBytes, err := candiedyaml.Marshal(document)
		if err != nil {
			return nil, err
		}

		// 2) Use ghodss/yaml to unmarshal that string into JSON-compatible data structures.
		var jsonObj interface{}
		if err := yaml.Unmarshal(yamlBytes, &jsonObj); err != nil {
			return nil, err
		}

		// Now it's suitable for embedding in an API response.
		stream = append(stream, jsonObj)
	}
}
开发者ID:jackgr,项目名称:helm,代码行数:44,代码来源:expander.go

示例13: GenerateAndSetDeploymentManifest

func (bosh *Bosh) GenerateAndSetDeploymentManifest(manifest interface{}, manifestGenerateScripts string, stubs ...string) {
	cmd := exec.Command(manifestGenerateScripts, stubs...)
	session, err := Start(cmd, GinkgoWriter, GinkgoWriter)
	Expect(err).ToNot(HaveOccurred())
	Eventually(session, 10*time.Second).Should(Exit(0))

	tmpFile, err := ioutil.TempFile(os.TempDir(), "")
	Expect(err).ToNot(HaveOccurred())
	_, err = tmpFile.Write(session.Out.Contents())
	Expect(err).ToNot(HaveOccurred())
	tmpFile.Close()

	Expect(bosh.Command("deployment", tmpFile.Name())).To(Exit(0))

	tmpFile, err = os.Open(tmpFile.Name())
	Expect(err).ToNot(HaveOccurred())

	decoder := candiedyaml.NewDecoder(tmpFile)
	err = decoder.Decode(manifest)
	Expect(err).ToNot(HaveOccurred())
}
开发者ID:digideskweb,项目名称:etcd-release,代码行数:21,代码来源:bosh.go

示例14: Parse

func (p yamlParser) Parse() ([]models.Plugin, error) {
	file, err := os.Open(p.filePath)
	if err != nil {
		p.logger.Write([]byte("File does not exist:" + err.Error()))
		return []models.Plugin{}, err
	}

	document := new(interface{})
	decoder := candiedyaml.NewDecoder(file)
	err = decoder.Decode(document)

	if err != nil {
		p.logger.Write([]byte("Failed to decode document:" + err.Error()))
		return []models.Plugin{}, err
	}

	output, _ := expandProperties(*document)

	plugins := p.pluginsModel.PopulateModel(output)

	return plugins, nil
}
开发者ID:jeaniejung,项目名称:cli-plugin-repo,代码行数:22,代码来源:parser.go

示例15: detectStartCommandFromProcfile

func (runner *Runner) detectStartCommandFromProcfile() (string, error) {
	procFile, err := os.Open(filepath.Join(runner.config.BuildDir(), "Procfile"))
	if err != nil {
		if os.IsNotExist(err) {
			// Procfiles are optional
			return "", nil
		}

		return "", err
	}

	defer procFile.Close()

	processes := map[string]string{}

	err = candiedyaml.NewDecoder(procFile).Decode(&processes)
	if err != nil {
		// clobber candiedyaml's super low-level error
		return "", errors.New("invalid YAML")
	}

	return processes["web"], nil
}
开发者ID:davidwadden,项目名称:lattice-release,代码行数:23,代码来源:runner.go


注:本文中的github.com/cloudfoundry-incubator/candiedyaml.NewDecoder函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。