Documentation ¶
Index ¶
- func EmptyBody() []byte
- type FailHttpImmediately
- type FailMsg
- type HttpStep
- type Runner
- func EncodeJson(val interface{}, target *[]byte) Runner
- func QueryString(req *http.Request, key string, idx int, target *string) Runner
- func QueryStringParseBool(req *http.Request, key string, idx int, target *bool) Runner
- func ReadBody(req *http.Request, target *[]byte) Runner
- func ReadJson(req *http.Request, target interface{}) Runner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FailHttpImmediately ¶
type FailHttpImmediately struct {
// contains filtered or unexported fields
}
a server that executes all of its steps and writes the output, failure or success to the provided http.ResponseWriter. if all steps succeeded, writes SuccCode and SuccMsg to the ResponseWriter. otherwise, stops execution immediately after the failed HttpStep and writes details on the failed HttpStep to the same ResponseWriter. example usage:
steps := []*server.HttpStep { &server.HttpStep { Runner: func() error { //do nothing return nil }, FailCode: http.StatusInternalServerError, FailMsg: server.JsonErr() }, } NewFailImmediately(resp, steps, http.StatusOK, []byte("OK!")).Execute()
func NewFailHttpImmediately ¶
func NewFailHttpImmediately(resp http.ResponseWriter, steps []*HttpStep, succCode int, succMsg []byte) *FailHttpImmediately
create a new FailHttpImmediately server
func (*FailHttpImmediately) Execute ¶
func (fh *FailHttpImmediately) Execute() []error
execute the series of steps in the FailHttpImmediately
type Runner ¶
type Runner func() error
the function to actually run each HttpStep
func EncodeJson ¶
a Runner that: - encodes val to json - writes the resulting bytes to *target - returns nil if there were errors at any step, does not write to *target and returns the error
func QueryString ¶
a Runner to extract a value from a query string key. intended for use as a HttpStep.runner. the returned Runner will: - gets the query string from the given http.Request - gets the value(s) for the given key from that query string - of the values for that key, attempts to get the value at index idx - writes that value to *target - returns nil if any of the above steps fails, the function returns an appropriate error and writes nothing to *target. idx is 0 based
func QueryStringParseBool ¶
a Runner that: - executes QueryString - attempts to convert the output of QueryString to a bool - writes that value to *target - returns nil if anything went wrong along the way, return an appropriate error and write nothing to *target
func ReadBody ¶
a Runner that: - reads the entire body from req - writes the body to *target if there were errors at any step, returns the error and does not write to *target
func ReadJson ¶
a Runner that: - reads the entire body from req - attempts to decode json from that body to target if there were errors at any step, returns the error. make sure to pass an address to the data structure to read, similar to what you'd do with the encoding/json package for example:
var targetMap map[string]string server.ReadJson(req, &targetMap)
when the ReadJson runner is executed, the json will be written into targetMap if there were no errors