Reduce Code Duplication in Service Layer
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Request/Response Pattern Duplication
Examples (before):
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
if err != nil { return nil, nil, err }
var result []*SomeType
resp, err := s.client.Do(req, &result)
req, err := s.client.NewRequest(http.MethodPost, u, body, options)
if err != nil { return nil, nil, err }
var item *Item
resp, err := s.client.Do(req, &item)
Examples (after):
resp, err := s.requestHandler.ListWithOptions(u, opt, &result, options...)
resp, err := s.requestHandler.Create(u, body, &item, options...)
Impact:
Makes API methods 75% shorter and easier to maintain.
Implementation Details
- This Issue would create a new, generic parameterized
DoRequest
function that could be used to initialize the the generic struct before calling theDo
function. - Once the initial generic function is created, multiple smaller MRs can be submitted, each refactoring a single
service
file to follow the new format.
Edited by 🤖 GitLab Bot 🤖