Documentation ¶
Index ¶
- func SetViewFolder(folder string)
- func ViewFolder() string
- type Action
- type Exchange
- func (x *Exchange) GetBool(key string) (bool, bool)
- func (x *Exchange) GetBoolOrDefault(key string, defaultVal bool) bool
- func (x *Exchange) GetFloat(key string) (float64, bool)
- func (x *Exchange) GetFloatOrDefault(key string, defaultVal float64) float64
- func (x *Exchange) GetID() (int, bool)
- func (x *Exchange) GetIDString() string
- func (x *Exchange) GetInt(key string) (int, bool)
- func (x *Exchange) GetIntOrDefault(key string, defaultVal int) int
- func (x *Exchange) GetString(key string) string
- func (x *Exchange) GetStringOrDefault(key string, defaultVal string) string
- func (x *Exchange) MustGetBool(key string) bool
- func (x *Exchange) MustGetFloat(key string) float64
- func (x *Exchange) MustGetID() int
- func (x *Exchange) MustGetIDString() string
- func (x *Exchange) MustGetInt(key string) int
- func (x *Exchange) MustGetString(key string) string
- func (x *Exchange) Request() *http.Request
- func (x *Exchange) Writer() http.ResponseWriter
- type Handler
- type Responder
- func Binary(reader io.Reader) Responder
- func Error(statusCode int, message string) Responder
- func ImagePNG(img image.Image) Responder
- func JSON(v interface{}) Responder
- func Nop() Responder
- func PlainText(text string) Responder
- func View(path string, model interface{}) Responder
- func XML(v interface{}) Responder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetViewFolder ¶
func SetViewFolder(folder string)
SetViewFolder sets the file path of the local directory that contains the view templates.
func ViewFolder ¶
func ViewFolder() string
ViewFolder returns the file path of the local directory that contains the view templates.
Types ¶
type Exchange ¶
type Exchange struct {
// contains filtered or unexported fields
}
Exchange contains information about a HTTP exchange (request and response), providing comfort functions to get typed form or query values.
func (*Exchange) GetBool ¶
GetBool returns the boolean value passed by query or form with the given key. If the given key is not present or in the wrong format, false is returned for the second return value.
func (*Exchange) GetBoolOrDefault ¶
GetBoolOrDefault returns the boolean value passed by query or form with the given key or the specified default value if no such value is present.
func (*Exchange) GetFloat ¶
GetFloat returns the floating-point value passed by query or form with the given key. If the given key is not present or in the wrong format, false is returned for the second return value.
func (*Exchange) GetFloatOrDefault ¶
GetFloatOrDefault returns the floating-point value passed by query or form with the given key or the specified default value if no such value is present.
func (*Exchange) GetID ¶
GetID returns the numeric ID passed with the request, which is the last element of the requested URL path (e.g. for http://host:port/item/action/1, GetID would return 1). If no numeric ID is present, false is returned for the second return value.
func (*Exchange) GetIDString ¶
GetIDString returns the ID passed with the request (see GetID) or an empty string if no ID is present.
func (*Exchange) GetInt ¶
GetInt returns the integer value passed by query or form with the given key. If the given key is not present or in the wrong format, false is returned for the second return value.
func (*Exchange) GetIntOrDefault ¶
GetIntOrDefault returns the integer value passed by query or form with the given key or the specified default value if no such value is present.
func (*Exchange) GetString ¶
GetString returns the string value passed by query or form with the given key or the empty string if no value with the given key is present.
func (*Exchange) GetStringOrDefault ¶
GetStringOrDefault returns the string value passed by query or form with the given key or the specified default if no value with the given key is present.
func (*Exchange) MustGetBool ¶
MustGetBool returns the boolean value passed by query or form with the given key or panics if not present or the found value is in the wrong format.
func (*Exchange) MustGetFloat ¶
MustGetFloat returns the floating-point value passed by query or form with the given key or panics if not present or the found value is in the wrong format.
func (*Exchange) MustGetID ¶
MustGetID returns the numeric ID passed with the request (see GetID) or panics if no numeric ID is present. The goobar HTTP handler will recover from this panic and write a 404 error to the client.
func (*Exchange) MustGetIDString ¶
MustGetIDString returns the ID passed with the request (see GetID) or panics if no ID is present. The goobar HTTP handler will recover from this panic and write a 404 error to the client.
func (*Exchange) MustGetInt ¶
MustGetInt returns the integer value passed by query or form with the given key or panics if not present or the found value is in the wrong format.
func (*Exchange) MustGetString ¶
MustGetString returns the string value passed by query or form with the given key or panics if no value with the given key is present.
func (*Exchange) Writer ¶
func (x *Exchange) Writer() http.ResponseWriter
Writer returns the http.ResponseWriter contained in the Exchange.
type Handler ¶
type Handler struct {
Get, Post, Put, Delete, Options Action
}
Handler stores a record of functions that handle different HTTP methods invoked for a common path. It stores Actions for GET, POST, PUT, DELETE and OPTIONS.
func AnyMethod ¶
AnyMethod returns a Handler with only one action for all supported HTTP actions (GET, POST, PUT, DELETE, OPTIONS)
type Responder ¶
type Responder interface { // Respond writes an HTTP response to the specified io.Writer. Respond(writer io.Writer) error // ContentType returns the MIME type that describes the format // of the data returned by Respond. ContentType() string }
Responder is the type returned by all goobar exchange handlers.
func JSON ¶
func JSON(v interface{}) Responder
JSON returns a Responder that sends an object in JSON format to the client.
func Nop ¶
func Nop() Responder
Nop returns a responder that does not write any data back to the client. The handler that returns Nop() is responsible for writing to the client using Exchange.Writer().
func PlainText ¶
PlainText returns a Responder that writes a plain UTF-8 encoded text response to the client.