go: github.com/stellar/go/support/render/hal Index | Files

package hal

import "github.com/stellar/go/support/render/hal"

Index

Package Files

handler.go io.go link.go link_builder.go page.go paging_token.go

Constants

const StandardPagingOptions = "{?cursor,limit,order}"

StandardPagingOptions is a helper string to make creating paged collection URIs simpler.

func ExecuteFunc Uses

func ExecuteFunc(ctx context.Context, fn, param interface{}) (interface{}, bool, error)

func Handler Uses

func Handler(fn, param interface{}) (http.Handler, error)

func Render Uses

func Render(w http.ResponseWriter, data interface{})

Render write data to w, after marshalling to json

type BasePage Uses

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

func (*BasePage) Add Uses

func (p *BasePage) Add(rec Pageable)

Add appends the provided record onto the page

func (*BasePage) Init Uses

func (p *BasePage) Init()

Init initialized the Records slice. This ensures that an empty page renders its records as an empty array, rather than `null`

type Link struct {
    Href      string `json:"href"`
    Templated bool   `json:"templated,omitempty"`
}
func NewLink(href string) Link

func (*Link) PopulateTemplated Uses

func (l *Link) PopulateTemplated()

type LinkBuilder Uses

type LinkBuilder struct {
    Base *url.URL
}

LinkBuilder is a helper for constructing URLs in horizon.

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 Uses

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 (lb *LinkBuilder) PagedLink(parts ...string) Link

PagedLink creates a link using the `Link` method and appends the common paging options

type Links struct {
    Self Link `json:"self"`
    Next Link `json:"next"`
    Prev Link `json:"prev"`
}

Links represents the Links in a Page

type Page Uses

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 Uses

func (p *Page) InvertedOrder() string

InvertedOrder returns the inversion of the page's current order. Used to populate the prev link

func (p *Page) PopulateLinks()

PopulateLinks sets the common links for a page.

type Pageable Uses

type Pageable interface {
    PagingToken() string
}

Pageable implementors can be added to hal.Page collections

Package hal imports 8 packages (graph) and is imported by 56 packages. Updated 2020-08-01. Refresh now. Tools for package owners.