Documentation ¶
Overview ¶
Package responder provides the functionality to populate the responses for the respective incoming requests
Package responder provides an HTTP response handler for Go applications. It allows generating responses in different formats (JSON, XML, or plain text) based on context and data types. Additionally, it sets headers and handles response codes for various HTTP methods and errors.
Index ¶
Constants ¶
const ( JSON responseType = iota XML TEXT )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CMD ¶
type CMD struct { // Logger is a logger object that can be used to log messages. Logger log.Logger }
CMD (Command) represents a command-line application configuration, including the ability to log messages.
The `CMD` type encapsulates configuration settings and tools for command-line applications, including a logger object (`Logger`) that can be used to log messages and output information.
It serves as a structured configuration for building command-line applications with logging capabilities.
func (*CMD) Respond ¶
Respond logs errors and prints responses based on the data and error provided. If an error is not nil, it logs the error using the provided logger and also prints it to the standard output. If the data is of type template.Template, it renders and prints the template content. If the data is of type template.File, it prints the content of the file. For other data types, it prints the data to the standard output.
type Responder ¶
type Responder interface {
Respond(data interface{}, err error)
}
func NewContextualResponder ¶
func NewContextualResponder(w http.ResponseWriter, r *http.Request) Responder
NewContextualResponder creates an HTTP responder which gives JSON/XML response based on context