xresp

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ResponseSTD

type ResponseSTD[D any, E any] struct {
	Code    any    `json:"code"`
	Msg     string `json:"msg"`
	Data    D      `json:"data"`
	Err     E      `json:"err"`
	TraceID any    `json:"traceId,omitempty"`
	// contains filtered or unexported fields
}

A Standard Response For API

func (*ResponseSTD[D, E]) DelHeader

func (r *ResponseSTD[D, E]) DelHeader(key string) *ResponseSTD[D, E]

func (*ResponseSTD[D, E]) JSON

func (r *ResponseSTD[D, E]) JSON(w io.Writer)

func (*ResponseSTD[D, E]) JSONText

func (r *ResponseSTD[D, E]) JSONText() (string, error)

func (*ResponseSTD[D, E]) RestJSON

func (r *ResponseSTD[D, E]) RestJSON()

func (*ResponseSTD[D, E]) RestRawJSON added in v1.0.0

func (r *ResponseSTD[D, E]) RestRawJSON()

func (*ResponseSTD[D, E]) SetCode

func (r *ResponseSTD[D, E]) SetCode(code any) *ResponseSTD[D, E]

func (*ResponseSTD[D, E]) SetData

func (r *ResponseSTD[D, E]) SetData(data D) *ResponseSTD[D, E]

func (*ResponseSTD[D, E]) SetError

func (r *ResponseSTD[D, E]) SetError(err E) *ResponseSTD[D, E]

func (*ResponseSTD[D, E]) SetHeader

func (r *ResponseSTD[D, E]) SetHeader(key string, value string) *ResponseSTD[D, E]

func (*ResponseSTD[D, E]) SetMsg

func (r *ResponseSTD[D, E]) SetMsg(msg string) *ResponseSTD[D, E]

func (*ResponseSTD[D, E]) SetStatusCode

func (r *ResponseSTD[D, E]) SetStatusCode(code int) *ResponseSTD[D, E]

func (*ResponseSTD[D, E]) SetTraceID

func (r *ResponseSTD[D, E]) SetTraceID(traceId string) *ResponseSTD[D, E]

type RestResponseSTD

type RestResponseSTD[D any, E any] interface {
	Msg(msg string) RestResponseSTD[D, E]
	Code(code any) RestResponseSTD[D, E]
	Data(data D) RestResponseSTD[D, E]
	Error(err E) RestResponseSTD[D, E]

	// Setter HTTP Response Status Code
	//
	// HTTP status codes as registered with IANA.
	// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
	StatusCode(code int) RestResponseSTD[D, E]

	// Add HTTP Response Header, this is equal function with:
	//	responseWriter.Header().Add(key, value)
	AddHeader(key string, value string) RestResponseSTD[D, E]

	// Delete HTTP Response Header by Key, this is equal function with:
	//	responseWriter.Header().Del(key)
	DelHeader(key string) RestResponseSTD[D, E]

	// A Method that Usefull for Run Interceptor Only,
	//
	// When you not need a response api that only need run interceptor.
	Done() error

	// A JSON Response Encoder for HTTP Response Writer, this is also auto set header and status code
	//	responseWriter.Header().Add("Accept", "application/json")
	//	responseWriter.Header().Add("Content-Type", "application/json")
	//
	//	// Default httpStatusCode is 200
	//	responseWriter.WriteHeader(httpStatusCode)
	JSON() error
	RawJSON() error

	// A General Purpose JSON Response Encoder to text
	JSONText() (string, error)
}

A Wrapper Standard Response For HTTP REST API

HTTP Rest API Response Builder

func NewRestResponse

func NewRestResponse[D, E any](e echo.Context) RestResponseSTD[D, E]

A Wrapper HTTP Rest API Response Builder Initiator

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL