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


Golang values.String类代码示例

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


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

示例1: validateRequireStringValue

func (instance Config) validateRequireStringValue(value values.String, fieldName string, isAllowedMethod func() bool) error {
	if isAllowedMethod() {
		if value.IsEmpty() {
			return errors.New("There is no %s set for type %v.", fieldName, instance.Type)
		}
	}
	return nil
}
开发者ID:echocat,项目名称:caretakerd,代码行数:8,代码来源:config.go

示例2: WriteToYamlFile

// WriteToYamlFile writes the config of the current instance to the given yaml file.
func (instance Config) WriteToYamlFile(fileName values.String) error {
	content, err := yaml.Marshal(instance)
	if err != nil {
		return errors.New("Could not write config to '%v'.", fileName).CausedBy(err)
	}
	if err := ioutil.WriteFile(fileName.String(), content, 0744); err != nil {
		return errors.New("Could not write marshalled config to '%v'.", fileName).CausedBy(err)
	}
	return nil
}
开发者ID:echocat,项目名称:caretakerd,代码行数:11,代码来源:configYaml.go

示例3: parseCertificatesInFile

func parseCertificatesInFile(filename values.String) ([]tls.Certificate, error) {
	pemInEnv := os.Getenv("CTD_PEM")
	if len(pemInEnv) > 0 {
		return parseCertificates([]byte(pemInEnv))
	}
	fileContent, err := ioutil.ReadFile(filename.String())
	if err != nil {
		return nil, errors.New("Could not read pem file '%v'.", filename).CausedBy(err)
	}
	return parseCertificates(fileContent)
}
开发者ID:echocat,项目名称:caretakerd,代码行数:11,代码来源:client.go

示例4: LoadFromYamlFile

// LoadFromYamlFile loads the caretakerd config from the given yaml file.
func LoadFromYamlFile(fileName values.String) (Config, error) {
	result := NewConfig()
	content, err := ioutil.ReadFile(fileName.String())
	if err != nil {
		if os.IsNotExist(err) {
			return Config{}, ConfigDoesNotExistError{fileName: fileName.String()}
		}
		return Config{}, errors.New("Could not read config from '%v'.", fileName).CausedBy(err)
	}
	if err := yaml.Unmarshal(content, &result); err != nil {
		return Config{}, errors.New("Could not unmarshal config from '%v'.", fileName).CausedBy(err)
	}
	return result, nil
}
开发者ID:echocat,项目名称:caretakerd,代码行数:15,代码来源:configYaml.go

示例5: validateStringOnlyAllowedValue

func (instance Config) validateStringOnlyAllowedValue(value values.String, fieldName string, isAllowedMethod func() bool, defaultValue values.String) error {
	if !isAllowedMethod() && value != defaultValue && !value.IsEmpty() {
		return errors.New("There is no %s allowed for type %v.", fieldName, instance.Type)
	}
	return nil
}
开发者ID:echocat,项目名称:caretakerd,代码行数:6,代码来源:config.go


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