Packages

response

Standard JSON response envelope. Consistent shape across all endpoints.


Functions

import "github.com/BounkhongDev/bkgo/response"

// 200 success with data
c.JSON(response.Success(user))
// {"success":true,"data":{...}}

// 200 success with message only
c.JSON(response.SuccessMessage("user deleted"))
// {"success":true,"message":"user deleted"}

// Paginated list
c.JSON(response.Paginated(users, page, limit, total))
// {"success":true,"data":[...],"meta":{"page":1,"limit":20,"total":100}}

// Error
c.Status(404).JSON(response.Error("NOT_FOUND", "user not found"))
// {"success":false,"error":"NOT_FOUND","message":"user not found"}

Response struct

type Response struct {
    Success   bool   `json:"success"`
    Data      any    `json:"data,omitempty"`
    ErrorCode string `json:"error,omitempty"`
    Message   string `json:"message,omitempty"`
    Meta      *Meta  `json:"meta,omitempty"`
}

type Meta struct {
    Page  int `json:"page"`
    Limit int `json:"limit"`
    Total int `json:"total"`
}