Documentation ¶
Index ¶
- Constants
- Variables
- func ExecuteFunc(ctx context.Context, fn, param interface{}) (interface{}, bool, error)
- func Handler(fn, param interface{}) (http.Handler, error)
- func Render(w http.ResponseWriter, data interface{})
- func ReqBodyHandler(fn interface{}) (http.Handler, error)
- type BasePage
- type Link
- type LinkBuilder
- type Links
- type Page
- type Pageable
Constants ¶
const StandardPagingOptions = "{?cursor,limit,order}"
StandardPagingOptions is a helper string to make creating paged collection URIs simpler.
Variables ¶
var DefaultResponse = json.RawMessage(`{"message":"ok"}`)
var ErrBadRequest = errors.New("bad request")
Functions ¶
func ExecuteFunc ¶
ExecuteFunc executes the fn with the param after checking whether the function signature is valid or not by calling Handler. The first return value is the result that fn returns. The second return value is a boolean indicating whether the caller should panic on the err or not. If it's true, it means the caller can process the error normally; if it's false, it means the caller should probably panic on the error. The third return value is an error either from Handler() or from fn, if any.
func Handler ¶
Handler returns an HTTP Handler for function fn. If fn returns a non-nil error, the handler will use problem.Render. Please refer to funcParamType for the allowed function signature. The caller of this function should probably panic on the returned error, if any.
func Render ¶
func Render(w http.ResponseWriter, data interface{})
Render write data to w, after marshalling to json
func ReqBodyHandler ¶
ReqBodyHandler returns an HTTP Handler for function fn. If fn has an input type, it will try to decode the request body into the function's input type. If fn returns a non-nil error, the handler will use problem.Render. Please refer to funcParamType for the allowed function signature. The caller of this function should probably panic on the returned error, if any.
Types ¶
type BasePage ¶
type BasePage struct { FullURL *url.URL `json:"-"` Embedded struct { Records []Pageable `json:"records"` } `json:"_embedded"` }
BasePage represents the simplest page: one with no links and only embedded records. Can be used to build custom page-like resources
type Link ¶
func (*Link) PopulateTemplated ¶
func (l *Link) PopulateTemplated()
type LinkBuilder ¶
LinkBuilder is a helper for constructing URLs in horizon.
func (*LinkBuilder) Link ¶
func (lb *LinkBuilder) Link(parts ...string) Link
Link returns a hal.Link whose href is each of the provided parts joined by '/'
func (*LinkBuilder) Linkf ¶
func (lb *LinkBuilder) Linkf(format string, args ...interface{}) Link
Linkf provides a helper function that returns a link with an href created by passing the arguments into fmt.Sprintf
func (*LinkBuilder) PagedLink ¶
func (lb *LinkBuilder) PagedLink(parts ...string) Link
PagedLink creates a link using the `Link` method and appends the common paging options
type Page ¶
type Page struct { Links Links `json:"_links"` BasePage Order string `json:"-"` Limit uint64 `json:"-"` Cursor string `json:"-"` }
Page represents the common page configuration (i.e. has self, next, and prev links) and has a helper method `PopulateLinks` to automate their initialization.
func (*Page) InvertedOrder ¶
InvertedOrder returns the inversion of the page's current order. Used to populate the prev link
func (*Page) PopulateLinks ¶
func (p *Page) PopulateLinks()
PopulateLinks sets the common links for a page.