本文整理匯總了Golang中github.com/tmaiaroto/discfg/config.ResponseObject.PrevItem方法的典型用法代碼示例。如果您正苦於以下問題:Golang ResponseObject.PrevItem方法的具體用法?Golang ResponseObject.PrevItem怎麽用?Golang ResponseObject.PrevItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/tmaiaroto/discfg/config.ResponseObject
的用法示例。
在下文中一共展示了ResponseObject.PrevItem方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SetKey
// SetKey sets a key value for a given configuration
func SetKey(opts config.Options) config.ResponseObject {
resp := config.ResponseObject{
Action: "set",
}
// Do not allow empty values to be set
if opts.Value == nil {
resp.Error = ValueRequiredMsg
return resp
}
if opts.CfgName == "" {
resp.Error = MissingCfgNameMsg
return resp
}
key, keyErr := formatKeyName(opts.Key)
if keyErr == nil {
opts.Key = key
storageResponse, err := storage.Update(opts)
if err != nil {
resp.Error = err.Error()
resp.Message = "Error updating key value"
} else {
resp.Item.Key = key
resp.Item.Value = opts.Value
resp.Item.Version = 1
// Only set PrevItem if there was a previous value
if storageResponse.Value != nil {
resp.PrevItem = storageResponse
resp.PrevItem.Key = key
// Update the current item's value if there was a previous version
resp.Item.Version = resp.PrevItem.Version + 1
}
}
} else {
resp.Error = keyErr.Error()
}
return resp
}