本文整理匯總了Golang中github.com/echocat/caretakerd/values.String.String方法的典型用法代碼示例。如果您正苦於以下問題:Golang String.String方法的具體用法?Golang String.String怎麽用?Golang String.String使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/echocat/caretakerd/values.String
的用法示例。
在下文中一共展示了String.String方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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)
}
示例3: 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
}