本文整理匯總了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
}
示例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
}
示例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)
}
示例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
}
示例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
}