Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions server/controllers/locks.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewLockController(ctx *gin.Context) {

defer slock.ReleaseToPool()

ctx.IndentedJSON(http.StatusCreated, response.Ok(gin.H{
ctx.IndentedJSON(http.StatusCreated, response.Ok("lock created successfully", gin.H{
"token": slock.Token,
}))
}
Expand All @@ -79,9 +79,7 @@ func DeleteLockController(ctx *gin.Context) {
return
}

ctx.IndentedJSON(http.StatusOK, response.Ok(gin.H{
"message": "deleted lock successfully.",
}))
ctx.IndentedJSON(http.StatusOK, response.Ok("lock deleted successfully", nil))
}

func DoLeaseLockController(ctx *gin.Context) {
Expand All @@ -106,7 +104,7 @@ func DoLeaseLockController(ctx *gin.Context) {

defer slock.ReleaseToPool()

ctx.IndentedJSON(http.StatusCreated, response.Ok(gin.H{
ctx.IndentedJSON(http.StatusCreated, response.Ok("lease acquired successfully", gin.H{
"token": slock.Token,
}))
}
Expand Down
12 changes: 4 additions & 8 deletions server/controllers/records.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func GetRecordsController(ctx *gin.Context) {

defer rd.ReleaseToPool()

ctx.IndentedJSON(http.StatusOK, response.Ok(gin.H{
ctx.IndentedJSON(http.StatusOK, response.Ok("record queried successfully", gin.H{
"record": rd.Record,
}))
}
Expand Down Expand Up @@ -76,9 +76,7 @@ func PutRecordsController(ctx *gin.Context) {
return
}

ctx.IndentedJSON(http.StatusOK, response.Ok(gin.H{
"message": "record created successfully.",
}))
ctx.IndentedJSON(http.StatusOK, response.Ok("record created successfully", nil))
}

func DeleteRecordsController(ctx *gin.Context) {
Expand All @@ -94,9 +92,7 @@ func DeleteRecordsController(ctx *gin.Context) {
return
}

ctx.IndentedJSON(http.StatusOK, response.Ok(gin.H{
"message": "record deleted successfully.",
}))
ctx.IndentedJSON(http.StatusOK, response.Ok("record deleted successfully", nil))
}

type SearchRecordRequest struct {
Expand All @@ -123,7 +119,7 @@ func SearchRecordsController(ctx *gin.Context) {
return
}

ctx.IndentedJSON(http.StatusOK, response.Ok(gin.H{
ctx.IndentedJSON(http.StatusOK, response.Ok("search completed successfully", gin.H{
"column": res,
}))
}
Expand Down
27 changes: 9 additions & 18 deletions server/controllers/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func CreateTableController(ctx *gin.Context) {
}

if req.TTLSeconds < 0 {
ctx.IndentedJSON(http.StatusBadRequest, response.Fail("ttl cannot be negative."))
ctx.IndentedJSON(http.StatusBadRequest, response.Fail("ttl cannot be negative"))
return
}

Expand All @@ -55,9 +55,7 @@ func CreateTableController(ctx *gin.Context) {
return
}

ctx.IndentedJSON(http.StatusOK, response.Ok(gin.H{
"message": "table created successfully.",
}))
ctx.IndentedJSON(http.StatusOK, response.Ok("table created successfully", nil))
}

func DeleteTableController(ctx *gin.Context) {
Expand All @@ -73,9 +71,7 @@ func DeleteTableController(ctx *gin.Context) {
return
}

ctx.IndentedJSON(http.StatusOK, response.Ok(gin.H{
"message": "table deleted successfully.",
}))
ctx.IndentedJSON(http.StatusOK, response.Ok("table deleted successfully", nil))
}

func QueryTableController(ctx *gin.Context) {
Expand All @@ -91,7 +87,7 @@ func QueryTableController(ctx *gin.Context) {
return
}

ctx.IndentedJSON(http.StatusOK, response.Ok(gin.H{
ctx.IndentedJSON(http.StatusOK, response.Ok("table queried successfully", gin.H{
"table": tab.Table,
}))
}
Expand Down Expand Up @@ -121,9 +117,7 @@ func PatchRowsTableController(ctx *gin.Context) {
return
}

ctx.IndentedJSON(http.StatusOK, response.Ok(gin.H{
"message": "table rows updated successfully.",
}))
ctx.IndentedJSON(http.StatusOK, response.Ok("table rows patched successfully", nil))
}

type QueryRowsRequest struct {
Expand All @@ -150,7 +144,7 @@ func QueryRowsTableController(ctx *gin.Context) {
return
}

ctx.IndentedJSON(http.StatusOK, response.Ok(gin.H{
ctx.IndentedJSON(http.StatusOK, response.Ok("table queried rows successfully", gin.H{
"rows": rows,
}))
}
Expand All @@ -175,9 +169,7 @@ func RemoveRowsTabelController(ctx *gin.Context) {
return
}

ctx.IndentedJSON(http.StatusOK, response.Ok(gin.H{
"message": "table rows remove successfully.",
}))
ctx.IndentedJSON(http.StatusOK, response.Ok("table rows remove successfully", nil))
}

type InsertRowsRequest struct {
Expand All @@ -204,9 +196,8 @@ func InsertRowsTableController(ctx *gin.Context) {
return
}

ctx.IndentedJSON(http.StatusOK, response.Ok(gin.H{
"t_id": id,
"message": "table rows insert successfully.",
ctx.IndentedJSON(http.StatusOK, response.Ok("table rows insert successfully", gin.H{
"t_id": id,
}))
}

Expand Down
10 changes: 4 additions & 6 deletions server/controllers/variants.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ func DeleteVariantController(ctx *gin.Context) {
return
}

ctx.IndentedJSON(http.StatusOK, response.Ok(gin.H{
"message": "variant deleted successfully.",
}))
ctx.IndentedJSON(http.StatusOK, response.Ok("variant deleted successfully", nil))
}

func GetVariantController(ctx *gin.Context) {
Expand All @@ -58,7 +56,7 @@ func GetVariantController(ctx *gin.Context) {

defer variant.ReleaseToPool()

ctx.IndentedJSON(http.StatusOK, response.Ok(gin.H{
ctx.IndentedJSON(http.StatusOK, response.Ok("variant queried successfully", gin.H{
"variant": variant.Value,
}))
}
Expand Down Expand Up @@ -101,7 +99,7 @@ func CreateVariantController(ctx *gin.Context) {
}

// 成功响应
ctx.IndentedJSON(http.StatusOK, response.Ok(gin.H{
ctx.IndentedJSON(http.StatusOK, response.Ok("", gin.H{
"variant": new_variant.Value,
}))
}
Expand Down Expand Up @@ -131,7 +129,7 @@ func MathVariantController(ctx *gin.Context) {
return
}

ctx.IndentedJSON(http.StatusOK, response.Ok(gin.H{
ctx.IndentedJSON(http.StatusOK, response.Ok("variant incremented successfully", gin.H{
"variant": res_num,
}))
}
Expand Down
8 changes: 5 additions & 3 deletions server/response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ type ResponseEntity struct {
}

// 返回成功响应
func Ok(data interface{}) *ResponseEntity {
func Ok(message string, data interface{}) *ResponseEntity {
return &ResponseEntity{
Status: "success",
Data: data,
Status: "success",
Message: message,
Data: data,
}
}

Expand All @@ -33,5 +34,6 @@ func Fail(message string) *ResponseEntity {
return &ResponseEntity{
Status: "error",
Message: message,
Data: nil,
}
}