github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/ibus/utils.go (about)

     1  /*
     2  * Copyright (c) 2022-present unTill Pro, Ltd.
     3  * @author Maxim Geraskin
     4   */
     5  
     6  package ibus
     7  
     8  import (
     9  	"context"
    10  	"net/http"
    11  )
    12  
    13  func NewResult(response interface{}, err error, errMsg string, errData string) (resp interface{}, status Status, e error) {
    14  	if err == nil {
    15  		return response, Status{HTTPStatus: http.StatusOK}, nil
    16  	}
    17  
    18  	httpStatus, ok := ErrStatuses[err]
    19  	if !ok {
    20  		httpStatus = http.StatusInternalServerError
    21  	}
    22  	status = Status{
    23  		HTTPStatus:   httpStatus,
    24  		ErrorMessage: errMsg,
    25  		ErrorData:    errData,
    26  	}
    27  	return response, status, err
    28  }
    29  
    30  func NullHandler(responsePart interface{}) {}
    31  
    32  func EchoReceiver(_ context.Context, request interface{}, sectionsWriter SectionsWriterType) (response interface{}, status Status, err error) {
    33  	return NewResult(request, nil, "", "")
    34  }