package utils import ( "net/http" "github.com/gin-gonic/gin" "github.com/rs/zerolog/log" ) const APIVersion = "v1" func AssembleResponse(c *gin.Context, data interface{}, err error, opts ...ResponseDataOptionFunc) { code := http.StatusOK if err != nil { log.Error().Err(err) code = http.StatusInternalServerError c.JSON(code, FailResponse{ APIVersion: APIVersion, Error: RespErr{ Code: code, Message: err.Error(), }, }) return } resp := SuccessResponse{ APIVersion: APIVersion, Data: data, } for _, opt := range opts { opt(&resp) } c.JSON(code, resp) }