Files
mstore/app/handler/response.go
T
2026-02-06 15:31:35 +02:00

39 lines
934 B
Go

/*
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
*
* This work is published and licensed under a Creative Commons
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
*
* Distribution of this work is permitted, but commercial use and
* modifications are strictly prohibited.
*/
package handler
import (
"net/http"
"mstore/app/router"
)
type Response struct {
Error bool `json:"error" yaml:"error"`
Message string `json:"message,omitempty" yaml:"message,omitempty"`
Result any `json:"result,omitempty" yaml:"result,result"`
}
func (hand *Handler) SendResult(rctx *router.Context, result any) {
response := &Response{
Error: false,
Result: result,
}
rctx.SendJSON(http.StatusOK, response)
}
func (hand *Handler) SendError(rctx *router.Context, err error) {
response := &Response{
Error: true,
Message: err.Error(),
}
rctx.SendJSON(http.StatusOK, response)
}