chore: make codes the repository root
This commit is contained in:
21
internal/response/response.go
Normal file
21
internal/response/response.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package response
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
type Envelope struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func OK(c *gin.Context, data interface{}) {
|
||||
c.JSON(200, Envelope{Code: "OK", Message: "success", Data: data})
|
||||
}
|
||||
|
||||
func Created(c *gin.Context, data interface{}) {
|
||||
c.JSON(201, Envelope{Code: "CREATED", Message: "created", Data: data})
|
||||
}
|
||||
|
||||
func Error(c *gin.Context, status int, code, message string) {
|
||||
c.AbortWithStatusJSON(status, Envelope{Code: code, Message: message})
|
||||
}
|
||||
Reference in New Issue
Block a user