Ejemplo n.º 1
0
func (srv *Server) getcounter(c *gin.Context) {
	key := c.Param("key")
	if res, err := srv.keystorage.GetCounter(key); err == nil {
		obj := model.NewOvoCounterResponse(res)
		result := model.NewOvoResponse("done", "0", obj)
		c.JSON(http.StatusOK, result)
	} else {
		c.JSON(http.StatusNotFound, model.NewOvoResponse("error", "101", nil))
	}
}
Ejemplo n.º 2
0
func (srv *Server) getAndRemove(c *gin.Context) {
	key := c.Param("key")
	if res, err := srv.keystorage.GetAndRemove(key); err == nil {
		obj := model.NewOvoKVResponse(res)
		srv.outcmdproc.Enqueu(&command.Command{OpCode: "delete", Obj: &storage.MetaDataUpdObj{Key: key}})
		result := model.NewOvoResponse("done", "0", obj)
		c.JSON(http.StatusOK, result)
	} else {
		c.JSON(http.StatusNotFound, model.NewOvoResponse("error", "101", nil))
	}
}
Ejemplo n.º 3
0
func (srv *Server) setcounter(c *gin.Context) {
	var counter model.OvoCounter
	if c.BindJSON(&counter) == nil {
		obj := model.NewMetaDataCounter(&counter)
		cnt := srv.keystorage.SetCounter(obj)
		srv.outcmdproc.Enqueu(&command.Command{OpCode: "setcounter", Obj: cnt.MetaDataUpdObj()})
		c.JSON(http.StatusOK, model.NewOvoResponse("done", "0", model.NewOvoCounterResponse(cnt)))
	} else {
		c.JSON(http.StatusBadRequest, model.NewOvoResponse("error", "10", nil))
	}
}
Ejemplo n.º 4
0
func (srv *Server) post(c *gin.Context) {
	var kv model.OvoKVRequest
	if c.BindJSON(&kv) == nil {
		obj := model.NewMetaDataObj(&kv)
		srv.keystorage.Put(obj)
		srv.outcmdproc.Enqueu(&command.Command{OpCode: "put", Obj: obj.MetaDataUpdObj()})
		c.JSON(http.StatusOK, model.NewOvoResponse("done", "0", nil))
	} else {
		c.JSON(http.StatusBadRequest, model.NewOvoResponse("error", "10", nil))
	}
}
Ejemplo n.º 5
0
func (srv *Server) deleteValueIfEqual(c *gin.Context) {
	key := c.Param("key")
	var kv model.OvoKVRequest
	if c.BindJSON(&kv) == nil {
		obj := model.NewMetaDataObj(&kv)
		obj.Key = key
		err := srv.keystorage.DeleteValueIfEqual(obj)
		if err == nil {
			srv.outcmdproc.Enqueu(&command.Command{OpCode: "delete", Obj: obj.MetaDataUpdObj()})
			c.JSON(http.StatusOK, model.NewOvoResponse("done", "0", nil))
		} else {
			c.JSON(http.StatusForbidden, model.NewOvoResponse("error", "103", nil))
		}
	} else {
		c.JSON(http.StatusBadRequest, model.NewOvoResponse("error", "10", nil))
	}
}
Ejemplo n.º 6
0
func (srv *Server) deletecounter(c *gin.Context) {
	key := c.Param("key")
	srv.keystorage.DeleteCounter(key)
	srv.outcmdproc.Enqueu(&command.Command{OpCode: "deletecounter", Obj: &storage.MetaDataUpdObj{Key: key}})
	c.JSON(http.StatusOK, model.NewOvoResponse("done", "0", nil))
}
Ejemplo n.º 7
0
func (srv *Server) getCurrentNode(c *gin.Context) {
	res := model.NewOvoTopologyNode(srv.config.ServerNode)
	result := model.NewOvoResponse("done", "0", res)
	c.JSON(http.StatusOK, result)
}
Ejemplo n.º 8
0
func (srv *Server) getTopology(c *gin.Context) {
	res := model.NewOvoTopology(&srv.config.Topology)
	result := model.NewOvoResponse("done", "0", res)
	c.JSON(http.StatusOK, result)
}
Ejemplo n.º 9
0
func (srv *Server) keys(c *gin.Context) {
	keys := srv.keystorage.Keys()
	res := &model.OvoKVKeys{Keys: keys}
	result := model.NewOvoResponse("done", "0", res)
	c.JSON(http.StatusOK, result)
}
Ejemplo n.º 10
0
func (srv *Server) count(c *gin.Context) {
	res := srv.keystorage.Count()
	result := model.NewOvoResponse("done", "0", res)
	c.JSON(http.StatusOK, result)
}