Documentation
¶
Index ¶
- type RenderType
- type Response
- func (r Response) GetCallers() string
- func (r Response) GetContext() context.Context
- func (r Response) GetError() error
- func (r Response) GetHTTPCode() int
- func (r Response) GetLevel() log.Level
- func (r Response) GetRenderType() RenderType
- func (r Response) RenderString() string
- func (r Response) WithData(data any) Response
- func (r Response) WithError(err error) Response
- func (r Response) WithHTTPCode(code int) Response
- func (r Response) WithLevel(level log.Level) Response
- func (r Response) WithMessage(message string) Response
- func (r Response) WithRenderType(renderType RenderType) Response
- func (r Response) WrapCallers(depth ...int) Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RenderType ¶
type RenderType uint8
RenderType defines the response content rendering type.
const ( // JSON render full JSON response with code, message and data. JSON RenderType = iota // DataOnlyJSON render only data portion as JSON. DataOnlyJSON // String render response data as String content. String )
type Response ¶
type Response struct { Code ecodes.Code `json:"code"` Message string `json:"message"` Data any `json:"data,omitempty"` // contains filtered or unexported fields }
Response represents a standardized API response structure.
func NewSuccess ¶
NewSuccess creates a successful API response.
func (Response) GetCallers ¶
GetCallers return the callers of the response.
func (Response) GetContext ¶
GetContext return the HTTP status code of the response.
func (Response) GetHTTPCode ¶
GetHTTPCode return the HTTP status code of the response.
func (Response) GetRenderType ¶
func (r Response) GetRenderType() RenderType
GetRenderType return the render type of the response.
func (Response) RenderString ¶
RenderString return the string based on the render type.
func (Response) WithHTTPCode ¶
WithHTTPCode overrides default HTTP status code.
func (Response) WithMessage ¶
WithMessage sets custom message for the response.
func (Response) WithRenderType ¶
func (r Response) WithRenderType(renderType RenderType) Response
WithRenderType specifies response content rendering format.
func (Response) WrapCallers ¶
WrapCallers appends current caller information to the stack trace.