responder

package module
v0.0.0-...-8f135a5 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2020 License: MIT Imports: 4 Imported by: 7

README

Responder

Responder provides a means to respond differently according to a request's accepted mime type.

GoDoc

Documentation

https://doc.getqor.com/helpers/responder.html

License

Released under the MIT License.

Documentation

Overview

Package responder respond differently according to request's accepted mime type

Github: http://github.com/ecletus/responder

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(mimeType string, format string)

Register mime type and format

responder.Register("application/json", "json")

Types

type Responder

type Responder struct {
	DefaultResponder func()
	// contains filtered or unexported fields
}

Responder is holder of registed response handlers, response `Request` based on its accepted mime type

func With

func With(formats interface{}, fc func()) *Responder

With could be used to register response handler for mime type formats, the formats could be string or []string

responder.With("html", func() {
  writer.Write([]byte("this is a html request"))
}).With([]string{"json", "xml"}, func() {
  writer.Write([]byte("this is a json or xml request"))
})

func (*Responder) Respond

func (rep *Responder) Respond(request *http.Request)

Respond differently according to request's accepted mime type

func (*Responder) With

func (rep *Responder) With(formats interface{}, fc func()) *Responder

With could be used to register response handler for mime type formats, the formats could be string or []string

func (*Responder) XAccept

func (rep *Responder) XAccept() *Responder

Jump to

Keyboard shortcuts

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