@@ -10,6 +10,7 @@ import (
1010 "strings"
1111
1212 "github.com/julienschmidt/httprouter"
13+ "github.com/univedo/api2go/jsonapi"
1314)
1415
1516// DataSource provides methods needed for CRUD.
@@ -106,7 +107,7 @@ func (api *API) addResource(prototype interface{}, source DataSource) *resource
106107 panic ("pass an empty resource struct to AddResource!" )
107108 }
108109
109- name := jsonify ( pluralize (resourceType .Name ()))
110+ name := jsonapi . Jsonify ( jsonapi . Pluralize (resourceType .Name ()))
110111 res := resource {
111112 resourceType : resourceType ,
112113 name : name ,
@@ -242,11 +243,11 @@ func (res *resource) handleLinked(api *API, w http.ResponseWriter, r *http.Reque
242243 // Iterate over all struct fields and determine the type of linked
243244 for i := 0 ; i < res .resourceType .NumField (); i ++ {
244245 field := res .resourceType .Field (i )
245- fieldName := jsonify (field .Name )
246+ fieldName := jsonapi . Jsonify (field .Name )
246247 kind := field .Type .Kind ()
247248 if (kind == reflect .Ptr || kind == reflect .Slice ) && fieldName == linked {
248249 // Check if there is a resource for this type
249- fieldType := pluralize ( jsonify (field .Type .Elem ().Name ()))
250+ fieldType := jsonapi . Pluralize ( jsonapi . Jsonify (field .Type .Elem ().Name ()))
250251 for _ , resource := range api .resources {
251252 if resource .name == fieldType {
252253 request := Request {
@@ -279,7 +280,9 @@ func (res *resource) handleCreate(w http.ResponseWriter, r *http.Request, prefix
279280 return err
280281 }
281282 newObjs := reflect .MakeSlice (reflect .SliceOf (res .resourceType ), 0 , 0 )
282- err = unmarshalInto (ctx , res .resourceType , & newObjs )
283+
284+ //TODO remove necessecity to call unmarshal into
285+ err = jsonapi .UnmarshalInto (ctx , res .resourceType , & newObjs )
283286 if err != nil {
284287 return err
285288 }
@@ -320,7 +323,9 @@ func (res *resource) handleUpdate(w http.ResponseWriter, r *http.Request, ps htt
320323 }
321324 updatingObjs := reflect .MakeSlice (reflect .SliceOf (res .resourceType ), 1 , 1 )
322325 updatingObjs .Index (0 ).Set (reflect .ValueOf (obj ))
323- err = unmarshalInto (ctx , res .resourceType , & updatingObjs )
326+
327+ //TODO remove call to unmarshalInto
328+ err = jsonapi .UnmarshalInto (ctx , res .resourceType , & updatingObjs )
324329 if err != nil {
325330 return err
326331 }
@@ -359,7 +364,7 @@ func (res *resource) handleDelete(w http.ResponseWriter, r *http.Request, ps htt
359364}
360365
361366func respondWith (obj interface {}, prefix string , status int , w http.ResponseWriter ) error {
362- data , err := MarshalToJSONPrefix (obj , prefix )
367+ data , err := jsonapi . MarshalToJSONPrefix (obj , prefix )
363368 if err != nil {
364369 return err
365370 }
0 commit comments