/* * Copyright 2026 Oleg Borodin * * 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[T any] struct { Error bool `json:"error" yaml:"error"` Message string `json:"message,omitempty" yaml:"message,omitempty"` Result T `json:"result,omitempty" yaml:"result,result"` } func NewResponse[T any]() *Response[T] { return &Response[T]{} } func (hand *Handler) SendResult(rctx *router.Context, result any) { response := &Response[any]{ Error: false, Result: result, } rctx.SendJSON(http.StatusOK, response) } func (hand *Handler) SendError(rctx *router.Context, err error) { response := &Response[any]{ Error: true, Message: err.Error(), } rctx.SendJSON(http.StatusOK, response) }