Example #1
0
func (handler *KvHandlersImpl) PutValueHandler(params kv.PutValueParams) middleware.Responder {
	defer trace.End(trace.Begin(*params.KeyValue.Key))

	err := handler.defaultStore.Put(context.Background(), *params.KeyValue.Key, []byte(*params.KeyValue.Value))
	if err != nil {
		log.Errorf("Error Setting Key/Value: %s", err.Error())
		return kv.NewGetValueInternalServerError().WithPayload(&models.Error{
			Code:    swag.Int64(http.StatusInternalServerError),
			Message: err.Error(),
		})
	}
	return kv.NewPutValueOK()
}
Example #2
0
func (handler *KvHandlersImpl) DeleteValueHandler(params kv.DeleteValueParams) middleware.Responder {
	defer trace.End(trace.Begin(params.Key))

	err := handler.defaultStore.Delete(trace.NewOperation(context.Background(), "DeleteValue"), params.Key)
	if err != nil {
		switch err {
		case kvstore.ErrKeyNotFound:
			return kv.NewDeleteValueNotFound()
		default:
			log.Errorf("Error deleting Key/Value: %s", err.Error())
			return kv.NewGetValueInternalServerError().WithPayload(&models.Error{
				Code:    swag.Int64(http.StatusInternalServerError),
				Message: err.Error(),
			})
		}
	}
	return kv.NewDeleteValueOK()
}
Example #3
0
func (handler *KvHandlersImpl) GetValueHandler(params kv.GetValueParams) middleware.Responder {
	defer trace.End(trace.Begin(params.Key))

	val, err := handler.defaultStore.Get(params.Key)
	if err != nil {
		switch err {
		case kvstore.ErrKeyNotFound:
			return kv.NewGetValueNotFound()
		default:
			log.Errorf("Error Getting Key/Value: %s", err.Error())
			return kv.NewGetValueInternalServerError().WithPayload(&models.Error{
				Code:    swag.Int64(http.StatusInternalServerError),
				Message: err.Error(),
			})
		}
	}
	s := string(val)
	return kv.NewGetValueOK().WithPayload(&models.KeyValue{Key: &params.Key, Value: &s})
}