本文整理汇总了Golang中github.com/tmaiaroto/discfg/config.ResponseObject类的典型用法代码示例。如果您正苦于以下问题:Golang ResponseObject类的具体用法?Golang ResponseObject怎么用?Golang ResponseObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResponseObject类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: DeleteKey
// DeleteKey deletes a key from a configuration
func DeleteKey(opts config.Options) config.ResponseObject {
resp := config.ResponseObject{
Action: "delete",
}
key, keyErr := formatKeyName(opts.Key)
if keyErr == nil {
opts.Key = key
storageResponse, err := storage.Delete(opts)
if err != nil {
resp.Error = err.Error()
resp.Message = "Error getting key value"
} else {
resp.Item = storageResponse
resp.Item.Key = opts.Key
resp.Item.Value = nil
resp.Item.Version = storageResponse.Version + 1
resp.PrevItem.Key = opts.Key
resp.PrevItem.Version = storageResponse.Version
resp.PrevItem.Value = storageResponse.Value
// log.Println(storageResponse)
}
} else {
resp.Error = NotEnoughArgsMsg
}
return resp
}
开发者ID:tmaiaroto,项目名称:discfg,代码行数:27,代码来源:commands.go
示例2: Info
// Info about the configuration including global version/state and modified time
func Info(opts config.Options) config.ResponseObject {
resp := config.ResponseObject{
Action: "info",
}
if opts.CfgName != "" {
// Just get the root key
opts.Key = "/"
storageResponse, err := storage.Get(opts)
if err != nil {
resp.Error = err.Error()
} else {
// Debating putting the item value on here... (allowing users to store values on the config or "root")
// resp.Item = storageResponse
// Set the configuration version and modified time on the response
// Item.CfgVersion and Item.CfgModifiedNanoseconds are not included in the JSON output
resp.CfgVersion = storageResponse.CfgVersion
resp.CfgModified = 0
resp.CfgModifiedNanoseconds = storageResponse.CfgModifiedNanoseconds
// Modified in seconds
resp.CfgModified = storageResponse.CfgModifiedNanoseconds / int64(time.Second)
// Modified parsed
modified := time.Unix(0, storageResponse.CfgModifiedNanoseconds)
resp.CfgModifiedParsed = modified.Format(time.RFC3339)
// Set information about the storage engine
resp.CfgStorage.InterfaceName = opts.StorageInterfaceName
resp.CfgStorage.Name = storage.Name(opts)
resp.CfgStorage.Options = storage.Options(opts)
// Get the status (only applicable for some storage interfaces, such as DynamoDB)
resp.CfgState, err = storage.ConfigState(opts)
if err != nil {
resp.Error = err.Error()
} else {
var buffer bytes.Buffer
buffer.WriteString(opts.CfgName)
if resp.CfgState != "" {
buffer.WriteString(" (")
buffer.WriteString(resp.CfgState)
buffer.WriteString(")")
}
buffer.WriteString(" version ")
buffer.WriteString(strconv.FormatInt(resp.CfgVersion, 10))
buffer.WriteString(" last modified ")
buffer.WriteString(modified.Format(time.RFC1123))
resp.Message = buffer.String()
buffer.Reset()
}
}
} else {
resp.Error = NotEnoughArgsMsg
}
return resp
}
开发者ID:tmaiaroto,项目名称:discfg,代码行数:57,代码来源:commands.go
示例3: Which
// Which shows which discfg configuration is currently active for use
func Which(opts config.Options) config.ResponseObject {
resp := config.ResponseObject{
Action: "which",
}
currentCfg := GetDiscfgNameFromFile()
if currentCfg == "" {
resp.Error = NoCurrentWorkingCfgMsg
} else {
resp.Message = "Current working configuration: " + currentCfg
resp.CurrentDiscfg = currentCfg
}
return resp
}
开发者ID:tmaiaroto,项目名称:discfg,代码行数:14,代码来源:commands.go
示例4: Use
// Use sets a discfg configuration to use for all future commands until unset (it is optional, but conveniently saves a CLI argument - kinda like MongoDB's use)
func Use(opts config.Options) config.ResponseObject {
resp := config.ResponseObject{
Action: "use",
}
if len(opts.CfgName) > 0 {
cc := []byte(opts.CfgName)
err := ioutil.WriteFile(".discfg", cc, 0644)
if err != nil {
resp.Error = err.Error()
} else {
resp.Message = "Set current working discfg to " + opts.CfgName
resp.CurrentDiscfg = opts.CfgName
}
} else {
resp.Error = NotEnoughArgsMsg
}
return resp
}
开发者ID:tmaiaroto,项目名称:discfg,代码行数:19,代码来源:commands.go
示例5: GetKey
// GetKey gets a key from a configuration
func GetKey(opts config.Options) config.ResponseObject {
resp := config.ResponseObject{
Action: "get",
}
key, keyErr := formatKeyName(opts.Key)
if keyErr == nil {
opts.Key = key
storageResponse, err := storage.Get(opts)
if err != nil {
resp.Error = err.Error()
} else {
resp.Item = storageResponse
}
} else {
resp.Error = keyErr.Error()
}
return resp
}
开发者ID:tmaiaroto,项目名称:discfg,代码行数:19,代码来源:commands.go
示例6: DeleteCfg
// DeleteCfg deletes a configuration
func DeleteCfg(opts config.Options) config.ResponseObject {
resp := config.ResponseObject{
Action: "delete cfg",
}
if len(opts.CfgName) > 0 {
_, err := storage.DeleteConfig(opts)
if err != nil {
resp.Error = err.Error()
resp.Message = "Error deleting the configuration"
} else {
resp.Message = "Successfully deleted the configuration"
}
} else {
resp.Error = NotEnoughArgsMsg
// TODO: Error code for this, message may not be necessary - is it worthwhile to try and figure out exactly which arguments were missing?
// Maybe a future thing to do. I need to git er done right now.
}
return resp
}
开发者ID:tmaiaroto,项目名称:discfg,代码行数:20,代码来源:commands.go
示例7: UpdateCfg
// UpdateCfg updates a configuration's options/settings (if applicable, depends on the interface)
func UpdateCfg(opts config.Options, settings map[string]interface{}) config.ResponseObject {
resp := config.ResponseObject{
Action: "update cfg",
}
// Note: For some storage engines, such as DynamoDB, it could take a while for changes to be reflected.
if len(settings) > 0 {
_, updateErr := storage.UpdateConfig(opts, settings)
if updateErr != nil {
resp.Error = updateErr.Error()
resp.Message = "Error updating the configuration"
} else {
resp.Message = "Successfully updated the configuration"
}
} else {
resp.Error = NotEnoughArgsMsg
}
return resp
}
开发者ID:tmaiaroto,项目名称:discfg,代码行数:21,代码来源:commands.go
示例8: 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
}
开发者ID:tmaiaroto,项目名称:discfg,代码行数:41,代码来源:commands.go
注:本文中的github.com/tmaiaroto/discfg/config.ResponseObject类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论