responder

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

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

View Source
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

func (c *CMD) Respond(data interface{}, err error)

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 HTTP

type HTTP struct {
	// contains filtered or unexported fields
}

func (HTTP) Respond

func (h HTTP) Respond(data interface{}, err error)

Respond generates an HTTP response based on the provided data and error. It sets the "X-Correlation-ID" header in the response and handles different response data types.

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

Jump to

Keyboard shortcuts

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