Beispiel #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))
	}
}
Beispiel #2
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))
	}
}