-
- Downloads
"controller/interfaces/networkelement/networkElement.go" did not exist on "4a3fd2bba790a1e503202b36533c79e40daab4ae"
Prepared client for POST/PUT/PATCH/DELETE
1. Fixed issue with concating urls, removed use of path.Join The problem here: With path.Join, the trailing slash has been removed on each call. Even when using `NewRequest(..., "/api/XXX/", nil)`. As a result, Do always queries `http://nebox.example.com/api/XXX`, getting back a 301 and retries the new Location. While this works well with GET, it breaks all the pushing methods. To not override too much, or too less, of `Client.u`, I append/prepend slashes if necessary. 2. Added two new functions to construct requests * c.NewDataRequest to create a request with body * c.NewJSONRequest to make posts more convenient * Changed c.NewRequest to be a wrap for NewJSONRequest As a result, using NewRequest stays the same, but NewJSONRequest can be used to create "writing" functions, without the need of repeatedly checking for errors. e.g. for `tenant-groups`: ``` func (s *TenantGroupsService) Update(group *TenantGroup) (*TenantGroup, error) { req, err := s.c.NewJSONRequest( http.MethodPatch, fmt.Sprintf("api/tenancy/tenant-groups/%d/", group.ID), nil, group) if err != nil { return nil, err } g := new(TenantGroup) err = s.c.Do(req, g) return g, err } func (s *TenantGroupsService) Delete(group *TenantGroup) error { req, err := s.c.NewRequest( http.MethodDelete, fmt.Sprintf("api/tenancy/tenant-groups/%d/", group.ID), nil) if err != nil { return err } return s.c.Do(req, nil) } ```
Please register or sign in to comment