本文整理汇总了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
}
开发者ID:bac,项目名称:juju,代码行数:28,代码来源:uniter.go
示例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
}
开发者ID:bac,项目名称:juju,代码行数:36,代码来源:uniter.go
注:本文中的github.com/juju/juju/state.Settings类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论