representor

package
v0.0.0-...-a57bf8e Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2020 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseRepresentor

type BaseRepresentor struct {
	// contains filtered or unexported fields
}

BaseRepresentor is a basic template implementation of a Representor. It is basically a 'body' of a request or response.

This should not be used, refer to hal.go for the HalRepresentor as a good default option to use.

func New

func New(u string, ct string, b string) *BaseRepresentor

New creates a new Representor object

func (*BaseRepresentor) GetBody

func (r *BaseRepresentor) GetBody() string

GetBody

func (r *BaseRepresentor) GetLink(rt string) *link.Link

GetLink

func (r *BaseRepresentor) GetLinks(rt string) []*link.Link

GetLinks

func (r *BaseRepresentor) HasLink(rt string) bool

HasLink

type HALBody

type HALBody struct {
	// TODO: This does not handle multiple "item" links. Need to handle
	// either a single HALLink or an array of HALLinks
	Links map[string][]HALLink `json:"_links,omitempty"`
	// This should be only JSON acceptable types: string, int, float, bool
	Properties map[string]interface{} `json:"-"`
	Embedded   map[string]HALBody     `json:"_embedded,omitempty"`
}

func (HALBody) MarshalJSON

func (b HALBody) MarshalJSON() ([]byte, error)

MarshalJSON will properly convert a HALBody into JSON.

func (*HALBody) UnmarshalJSON

func (b *HALBody) UnmarshalJSON(d []byte) error

UnmarshalJSON will properly convert JSON back into a HALBody object.

type HALLink struct {
	HRef  string `json:"href"`
	Name  string `json:"name,omitempty"`
	Title string `json:"title"`
	// Templated string
	Type string `json:"type,omitempty"`
}

type HALRepresentor

type HALRepresentor struct {
	URI         url.URL
	ContentType string
	Body        interface{}
	Links       link.LinkSet
}

HALRepresentor is a basic template implementation of a Representor. It is basically a 'body' of a request or response.

This should not be used, refer to hal.go for the HalRepresentor as a good default option to use.

func NewHALRepresentor

func NewHALRepresentor(u url.URL, ct string, b []byte) (*HALRepresentor, error)

New creates a new Representor object.

func (*HALRepresentor) GetBody

func (r *HALRepresentor) GetBody() interface{}

GetBody

func (r *HALRepresentor) GetLink(rt string) (*link.Link, error)

GetLink

func (r *HALRepresentor) GetLinks(rt string) []link.Link

GetLinks

func (r *HALRepresentor) HasLink(rt string) bool

HasLink

type Representor

type Representor interface {
	GetBody() interface{}
	GetLink(rt string) (*link.Link, error)
	GetLinks(rt string) []link.Link
	HasLink(rt string) bool
	// contains filtered or unexported methods
}

Representor interface provides a way to handle many different types of acceptable representations.

func Create

func Create(u url.URL, t string, b []byte) (Representor, error)

Create creates a Representor based on the Content-Type.

func CreateFromResponse

func CreateFromResponse(u url.URL, r http.Response, b []byte) (Representor, error)

CreateFromResponse pulls the necessary information from the request and passes it on to the Create function.

Jump to

Keyboard shortcuts

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