move a method higher for godoc

This commit is contained in:
Sam Woodard 2015-07-10 17:16:26 -07:00
parent 9b8432d9d9
commit 68c4bcfbb0
1 changed files with 28 additions and 28 deletions

View File

@ -10,6 +10,34 @@ import (
"time" "time"
) )
func MarshalOnePayload(w io.Writer, model interface{}) error {
rootNode, included, err := visitModelNode(model, true)
if err != nil {
return err
}
payload := &OnePayload{Data: rootNode}
uniqueIncluded := make(map[string]*Node)
for i, n := range included {
k := fmt.Sprintf("%s,%s", n.Type, n.Id)
if uniqueIncluded[k] == nil {
uniqueIncluded[k] = n
} else {
included = deleteNode(included, i)
}
}
payload.Included = included
if err := json.NewEncoder(w).Encode(payload); err != nil {
return err
}
return nil
}
func MarshalManyPayload(w io.Writer, models Models) error { func MarshalManyPayload(w io.Writer, models Models) error {
d := models.GetData() d := models.GetData()
data := make([]*Node, 0, len(d)) data := make([]*Node, 0, len(d))
@ -60,34 +88,6 @@ func MarshalOnePayloadEmbedded(model interface{}) (*OnePayload, error) {
} }
func MarshalOnePayload(w io.Writer, model interface{}) error {
rootNode, included, err := visitModelNode(model, true)
if err != nil {
return err
}
payload := &OnePayload{Data: rootNode}
uniqueIncluded := make(map[string]*Node)
for i, n := range included {
k := fmt.Sprintf("%s,%s", n.Type, n.Id)
if uniqueIncluded[k] == nil {
uniqueIncluded[k] = n
} else {
included = deleteNode(included, i)
}
}
payload.Included = included
if err := json.NewEncoder(w).Encode(payload); err != nil {
return err
}
return nil
}
func visitModelNode(model interface{}, sideload bool) (*Node, []*Node, error) { func visitModelNode(model interface{}, sideload bool) (*Node, []*Node, error) {
node := new(Node) node := new(Node)