response

package
v0.0.7-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrServiceNotFound = errors.New("service not found")
)

Functions

This section is empty.

Types

type HttpWriter

type HttpWriter interface {
	Write(w http.ResponseWriter, r *http.Request, status int, response interface{})
	WriteYaml(w http.ResponseWriter, status int, response interface{})
	WriteJson(w http.ResponseWriter, status int, response interface{})
	Success200(w http.ResponseWriter, r *http.Request, payload interface{})
	Success404(w http.ResponseWriter, r *http.Request, payload interface{}, err error)
	Error200(w http.ResponseWriter, r *http.Request, err error)
	Error401(w http.ResponseWriter, r *http.Request, err error)
	Error400(w http.ResponseWriter, r *http.Request, err error)
	Error404(w http.ResponseWriter, r *http.Request, err error)
	Error403(w http.ResponseWriter, r *http.Request, err error, payload interface{})
	Error500(w http.ResponseWriter, r *http.Request, err error)
}

func NewResponseWriter

func NewResponseWriter(
	logger *logging.Logger,
	session service.Session) HttpWriter

type ResponseWriter

type ResponseWriter struct {
	HttpWriter
	// contains filtered or unexported fields
}

func (*ResponseWriter) Error200

func (writer *ResponseWriter) Error200(w http.ResponseWriter, r *http.Request, err error)

func (*ResponseWriter) Error400

func (writer *ResponseWriter) Error400(w http.ResponseWriter, r *http.Request, err error)

func (*ResponseWriter) Error401

func (writer *ResponseWriter) Error401(w http.ResponseWriter, r *http.Request, err error)

func (*ResponseWriter) Error403

func (writer *ResponseWriter) Error403(w http.ResponseWriter, r *http.Request, err error, payload interface{})

func (*ResponseWriter) Error404

func (writer *ResponseWriter) Error404(w http.ResponseWriter, r *http.Request, err error)

func (*ResponseWriter) Error500

func (writer *ResponseWriter) Error500(w http.ResponseWriter, r *http.Request, err error)

func (*ResponseWriter) SetSession

func (writer *ResponseWriter) SetSession(session service.Session)

Sets the session. When present, log messages include session info.

func (*ResponseWriter) Success200

func (writer *ResponseWriter) Success200(w http.ResponseWriter, r *http.Request, payload interface{})

func (*ResponseWriter) Success404

func (writer *ResponseWriter) Success404(w http.ResponseWriter, r *http.Request, payload interface{}, err error)

func (*ResponseWriter) Write

func (writer *ResponseWriter) Write(w http.ResponseWriter, r *http.Request, status int, response interface{})

Writes a response to the http client using the client accept header to determine whether to use a JSON or YAML serializer and content-type header. Default is JSON if a valid header can not be found.

func (*ResponseWriter) WriteJson

func (writer *ResponseWriter) WriteJson(w http.ResponseWriter, status int, response interface{})

Writes a response to the http client using an application/json content-type header and JSON serializer

func (*ResponseWriter) WriteYaml

func (writer *ResponseWriter) WriteYaml(w http.ResponseWriter, status int, response interface{})

Writes a response to the http client using an application/yaml content-type header and YAML serializer

type WebServiceResponse

type WebServiceResponse struct {
	Code       int         `yaml:"code" json:"code"`
	Error      string      `yaml:"error" json:"error"`
	Success    bool        `yaml:"success" json:"success"`
	Payload    interface{} `yaml:"payload" json:"payload"`
	HttpWriter `yaml:"-" json:"-"`
}

Jump to

Keyboard shortcuts

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