Beispiel #1
0
// 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
}
Beispiel #2
0
// 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
}