本文整理汇总了Golang中github.com/juju/juju/state.Settings类的典型用法代码示例。如果您正苦于以下问题:Golang Settings类的具体用法?Golang Settings怎么用?Golang Settings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Settings类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ReadSettings
// ReadSettings returns the local settings of each given set of
// relation/unit.
func (u *UniterAPIV3) ReadSettings(args params.RelationUnits) (params.SettingsResults, error) {
result := params.SettingsResults{
Results: make([]params.SettingsResult, len(args.RelationUnits)),
}
canAccess, err := u.accessUnit()
if err != nil {
return params.SettingsResults{}, err
}
for i, arg := range args.RelationUnits {
unit, err := names.ParseUnitTag(arg.Unit)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
relUnit, err := u.getRelationUnit(canAccess, arg.Relation, unit)
if err == nil {
var settings *state.Settings
settings, err = relUnit.Settings()
if err == nil {
result.Results[i].Settings, err = convertRelationSettings(settings.Map())
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例2: UpdateSettings
// UpdateSettings persists all changes made to the local settings of
// all given pairs of relation and unit. Keys with empty values are
// considered a signal to delete these values.
func (u *UniterAPIV3) UpdateSettings(args params.RelationUnitsSettings) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.RelationUnits)),
}
canAccess, err := u.accessUnit()
if err != nil {
return params.ErrorResults{}, err
}
for i, arg := range args.RelationUnits {
unit, err := names.ParseUnitTag(arg.Unit)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
relUnit, err := u.getRelationUnit(canAccess, arg.Relation, unit)
if err == nil {
var settings *state.Settings
settings, err = relUnit.Settings()
if err == nil {
for k, v := range arg.Settings {
if v == "" {
settings.Delete(k)
} else {
settings.Set(k, v)
}
}
_, err = settings.Write()
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}