Documentation
¶
Index ¶
- func Render(rw http.ResponseWriter, options *WriteOptions) error
- type WriteOptions
- func (s *WriteOptions) AddHeaders(kvs ...string) *WriteOptions
- func (s *WriteOptions) Form(payload interface{}) *WriteOptions
- func (s *WriteOptions) HTML(payload interface{}) *WriteOptions
- func (s *WriteOptions) JSON(payload interface{}) *WriteOptions
- func (s *WriteOptions) PlainText(payload interface{}) *WriteOptions
- func (s *WriteOptions) WithBody(body interface{}, codec httpcodec.Encoder) *WriteOptions
- func (s *WriteOptions) WithStatus(status int) *WriteOptions
- func (s *WriteOptions) XML(payload interface{}) *WriteOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Render ¶
func Render(rw http.ResponseWriter, options *WriteOptions) error
Render renders the response according to WriteOptions.
Types ¶
type WriteOptions ¶
type WriteOptions struct {
// contains filtered or unexported fields
}
func Options ¶
func Options() *WriteOptions
Options is the entrypoint for configuration WriteOptions. By default, it assumes 200 status and plain body
func (*WriteOptions) AddHeaders ¶
func (s *WriteOptions) AddHeaders(kvs ...string) *WriteOptions
AddHeaders adds the key value pairs to response headers. If the pairs are not even numbered, the method panics.
func (*WriteOptions) Form ¶
func (s *WriteOptions) Form(payload interface{}) *WriteOptions
Form sets the payload and also the "Content-Type" header to "application/x-www-form-urlencoded". If payload is nil, this method is noop. Check github.com/absurdlab/pkg/httpcodec for accepted types.
func (*WriteOptions) HTML ¶
func (s *WriteOptions) HTML(payload interface{}) *WriteOptions
HTML sets the payload and also the "Content-Type" header to "text/html". If payload is nil, this method is noop. Check github.com/absurdlab/pkg/httpcodec for accepted types.
func (*WriteOptions) JSON ¶
func (s *WriteOptions) JSON(payload interface{}) *WriteOptions
JSON sets the payload and also the "Content-Type" header to "application/json". If payload is nil, this method is noop.
func (*WriteOptions) PlainText ¶
func (s *WriteOptions) PlainText(payload interface{}) *WriteOptions
PlainText sets the payload and also the "Content-Type" header to "text/plain". If payload is nil, this method is noop. Check github.com/absurdlab/pkg/httpcodec for accepted types.
func (*WriteOptions) WithBody ¶
func (s *WriteOptions) WithBody(body interface{}, codec httpcodec.Encoder) *WriteOptions
WithBody sets custom payload and encoder. If either is nil, this method is noop.
func (*WriteOptions) WithStatus ¶
func (s *WriteOptions) WithStatus(status int) *WriteOptions
WithStatus sets the response status.
func (*WriteOptions) XML ¶
func (s *WriteOptions) XML(payload interface{}) *WriteOptions
XML sets the payload and also the "Content-Type" header to "application/xml". If payload is nil, this method is noop.