Documentation ¶
Index ¶
- func Dejsonify(s string) string
- func GetTagValueByName(tfield reflect.StructField, name string) string
- func Jsonify(s string) string
- func Marshal(data interface{}) (map[string]interface{}, error)
- func MarshalToJSON(val interface{}) ([]byte, error)
- func MarshalToJSONWithURLs(val interface{}, information ServerInformation) ([]byte, error)
- func MarshalWithURLs(data interface{}, information ServerInformation) (map[string]interface{}, error)
- func Pluralize(word string) string
- func Singularize(word string) string
- func Unmarshal(input map[string]interface{}, target interface{}) error
- func UnmarshalFromJSON(data []byte, target interface{}) error
- func UnmarshalInto(input map[string]interface{}, targetStructType reflect.Type, ...) error
- func UnmarshalRelationshipsData(target interface{}, name string, links interface{}) error
- type EditToManyRelations
- type MarshalIdentifier
- type MarshalIncludedRelations
- type MarshalLinkedRelations
- type MarshalReferences
- type Reference
- type ReferenceID
- type ServerInformation
- type UnmarshalIdentifier
- type UnmarshalToManyRelations
- type UnmarshalToOneRelations
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetTagValueByName ¶
func GetTagValueByName(tfield reflect.StructField, name string) string
GetTagValueByName returns one api2go setting. settings must be of the format `jsonapi:"name=newName,body=newbody"
func Marshal ¶
Marshal thats the input from `data` which can be a struct, a slice, or a pointer of it. Any struct in `data`or data itself, must at least implement the `MarshalIdentifier` interface. If so, it will generate a map[string]interface{} matching the jsonapi specification.
func MarshalToJSON ¶
MarshalToJSON marshals a struct to json it works like `Marshal` but returns json instead
func MarshalToJSONWithURLs ¶
func MarshalToJSONWithURLs(val interface{}, information ServerInformation) ([]byte, error)
MarshalToJSONWithURLs marshals a struct to json with URLs in `links`
func MarshalWithURLs ¶
func MarshalWithURLs(data interface{}, information ServerInformation) (map[string]interface{}, error)
MarshalWithURLs can be used to include the generation of `related` and `self` links
func Unmarshal ¶
Unmarshal reads a JSONAPI map to a model struct target must at least implement the `UnmarshalIdentifier` interface.
func UnmarshalFromJSON ¶
UnmarshalFromJSON reads a JSONAPI compatible JSON document to a model struct target must be a struct or a slice of it
func UnmarshalInto ¶
func UnmarshalInto(input map[string]interface{}, targetStructType reflect.Type, targetSliceVal *reflect.Value) error
UnmarshalInto reads input params for one struct from `input` and marshals it into `targetSliceVal`, which may be a slice of targetStructType or a slice of pointers to targetStructType.
func UnmarshalRelationshipsData ¶
UnmarshalRelationshipsData is used by api2go.API to only unmarshal references inside a data object. The target interface must implement UnmarshalToOneRelations or UnmarshalToManyRelations interface. The linksMap is the content of the data object from the json
Types ¶
type EditToManyRelations ¶
type EditToManyRelations interface { AddToManyIDs(name string, IDs []string) error DeleteToManyIDs(name string, IDs []string) error }
The EditToManyRelations interface can be optionally implemented to add and delete to-many relationships on a already unmarshalled struct. These methods are used by our API for the to-many relationship update routes.
There are 3 HTTP Methods to edit to-many relations:
PATCH /v1/posts/1/comments Content-Type: application/vnd.api+json Accept: application/vnd.api+json { "data": [ { "type": "comments", "id": "2" }, { "type": "comments", "id": "3" } ] }
this replaces all of the comments that belong to post with ID 1 and the SetToManyReferenceIDs method will be called
POST /v1/posts/1/comments Content-Type: application/vnd.api+json Accept: application/vnd.api+json { "data": [ { "type": "comments", "id": "123" } ] }
adds a new comment to the post with ID 1. The AddToManyIDs methid will be called.
DELETE /v1/posts/1/comments Content-Type: application/vnd.api+json Accept: application/vnd.api+json { "data": [ { "type": "comments", "id": "12" }, { "type": "comments", "id": "13" } ] }
deletes comments that belong to post with ID 1. The DeleteToManyIDs method will be called.
type MarshalIdentifier ¶
type MarshalIdentifier interface {
GetID() string
}
MarshalIdentifier interface is necessary to give an element a unique ID. This interface must be implemented for marshal and unmarshal in order to let them store elements
type MarshalIncludedRelations ¶
type MarshalIncludedRelations interface { MarshalReferences MarshalIdentifier GetReferencedStructs() []MarshalIdentifier }
MarshalIncludedRelations must be implemented if referenced structs should be included
type MarshalLinkedRelations ¶
type MarshalLinkedRelations interface { MarshalReferences MarshalIdentifier GetReferencedIDs() []ReferenceID }
MarshalLinkedRelations must be implemented if there are references and the reference IDs should be included
type MarshalReferences ¶
type MarshalReferences interface {
GetReferences() []Reference
}
MarshalReferences must be implemented if the struct to be serialized has relations. This must be done because jsonapi needs information about relations even if many to many relations or many to one relations are empty
type ReferenceID ¶
ReferenceID contains all necessary information in order to reference another struct in jsonapi
type ServerInformation ¶
ServerInformation can be passed to MarshalWithURLs to generate the `self` and `related` urls inside `links`
type UnmarshalIdentifier ¶
UnmarshalIdentifier interface to set ID when unmarshalling
type UnmarshalToManyRelations ¶
UnmarshalToManyRelations must be implemented to unmarshal to-many relations
type UnmarshalToOneRelations ¶
UnmarshalToOneRelations must be implemented to unmarshal to-one relations