Help us shape the future of Go! Take the 2026 Go Developer Survey

haljson

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2019 License: MIT Imports: 6 Imported by: 3

README

haljson

Hal+JSON implementation in go

Documentation

Index

Constants

View Source
const (
	// NAME is a name link, curie property
	NAME = "name"
	// HREF is a href link, curie property
	HREF = "href"
	// HREFLANG is a hreflang link property
	HREFLANG = "hreflang"
	// TEMPLATED is a templated link, curie property
	TEMPLATED = "templated"
	// PROFILE is a profile link property
	PROFILE = "profile"
	// TITLE is a title link property
	TITLE = "title"
	// TYPE is a type link property
	TYPE = "type"
	// DEPRECATION is a deprecation link property
	DEPRECATION = "deprecation"
)

Variables

View Source
var (
	// ErrNoCurie is returned when a curied link was added without the associated curie
	ErrNoCurie = errors.New("Must add curie before adding a curied link")
)

Functions

This section is empty.

Types

type Curie

type Curie struct {
	Name      string `json:"name"`
	Href      string `json:"href"`
	Templated bool   `json:"templated"`
}

Curie respresents a curie

type Embeds

type Embeds struct {
	Relations map[string][]Resource
}

Embeds holds embedded relations by reltype

func NewEmbeds

func NewEmbeds() *Embeds

NewEmbeds creates and initializes Embeds

func (*Embeds) MarshalJSON

func (e *Embeds) MarshalJSON() ([]byte, error)

MarshalJSON marshals embeds

func (*Embeds) UnmarshalJSON

func (e *Embeds) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals embeds

type Link struct {
	Deprecation *string `json:"deprecation,omitempty"`
	Href        string  `json:"href,omitempty"`
	HrefLang    *string `json:"hreflang,omitempty"`
	Profile     *string `json:"profile,omitempty"`
	Templated   bool    `json:"templated,omitempty"`
	Title       *string `json:"title,omitempty"`
	Type        *string `json:"type,omitempty"`
}

Link represents a link

type Links struct {
	Self   *Link    `json:"-"`
	Curies *[]Curie `json:"curies,omitempty"`
	// When serializing to JSON we need to handle this specially
	Relations map[string][]*Link
}

Links is a container of Link, mapped by relation, and contains Curies

func NewLinks() *Links

NewLinks creates and initializes Links

func (*Links) AddCurie

func (l *Links) AddCurie(curie *Curie) error

AddCurie adds a curie to the links

func (l *Links) AddLink(reltype string, link *Link) error

AddLink adds a link to reltype

func (*Links) MarshalJSON

func (l *Links) MarshalJSON() ([]byte, error)

MarshalJSON to marshal Links properly

func (*Links) UnmarshalJSON

func (l *Links) UnmarshalJSON(b []byte) error

UnmarshalJSON to unmarshal links

type Resource

type Resource struct {
	Links  *Links  `json:"_links,omitempty"`
	Embeds *Embeds `json:"_embedded,omitempty"`
	// When serializing to JSON we need to handle this specially
	Data map[string]interface{} `json:"-"`
}

Resource represents a Resource with Links and Embeds with Data

func NewResource

func NewResource() *Resource

NewResource creates a Resource and initializes it

func (*Resource) AddCurie

func (r *Resource) AddCurie(curie *Curie) error

AddCurie adds a curie to the links

func (*Resource) AddEmbed

func (r *Resource) AddEmbed(reltype string, embed *Resource) error

AddEmbed adds a Resource by reltype

func (r *Resource) AddLink(reltype string, link *Link) error

AddLink adds a link to reltype

func (*Resource) MarshalJSON

func (r *Resource) MarshalJSON() ([]byte, error)

MarshalJSON marshals a resource properly

func (*Resource) Self

func (r *Resource) Self(uri string)

Self is used to add a self link

func (*Resource) UnmarshalJSON

func (r *Resource) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals embeds

Jump to

Keyboard shortcuts

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