mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-07 21:19:51 +00:00
41 lines
644 B
Go
41 lines
644 B
Go
package resp
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/pocketbase/pocketbase/core"
|
|
|
|
"github.com/usual2970/certimate/internal/domain"
|
|
)
|
|
|
|
type Response struct {
|
|
Code int `json:"code"`
|
|
Msg string `json:"msg"`
|
|
Data interface{} `json:"data"`
|
|
}
|
|
|
|
func Ok(e *core.RequestEvent, data interface{}) error {
|
|
rs := &Response{
|
|
Code: 0,
|
|
Msg: "success",
|
|
Data: data,
|
|
}
|
|
return e.JSON(http.StatusOK, rs)
|
|
}
|
|
|
|
func Err(e *core.RequestEvent, err error) error {
|
|
code := 500
|
|
|
|
xerr, ok := err.(*domain.Error)
|
|
if ok {
|
|
code = xerr.Code
|
|
}
|
|
|
|
rs := &Response{
|
|
Code: code,
|
|
Msg: err.Error(),
|
|
Data: nil,
|
|
}
|
|
return e.JSON(http.StatusOK, rs)
|
|
}
|