Skip to content

[Refactor][Framework] Refactor Extractors and Converters to use Generics #3616

@keon94

Description

@keon94

What and why to refactor

Extract functions use raw objects which they manually have to json-deserialize into predefined structs. This is needless boilerplate now that Go supports generics. Refactor the api_extractor.go (and other relevant framework files) to performs these deserializations under the hood and send the resulting Go structs to the user (Extract) functions.
The Converters suffer from this as well, although there's less boilerplate there. Refactor accordingly.

Describe the solution you'd like

Example:
currently we have:

Extract: func(row *helper.RawData) ([]interface{}, errors.Error) {
	apiAccountOrgs := &[]GithubAccountOrgsResponse{}
	err := json.Unmarshal(row.Data, apiAccountOrgs)
	if err != nil {
		return nil, errors.Convert(err)
	}
	simpleAccount := &SimpleAccountWithId{}
	err = json.Unmarshal(row.Input, simpleAccount)
	if err != nil {
		return nil, errors.Convert(err)
	}
	// more logic...
}

it should become like:

Extract: func(orgs []GithubAccountOrgsResponse, input *SimpleAccountWithId) ([]interface{}, errors.Error) {
	// more logic...
}

The API extractor will need to take two generic parameters: for the row data and the row input - initialization will look like this:

helper.NewApiExtractor[[]GithubAccountOrgsResponse, SimpleAccountWithId](...)

Related issues

n/a

Additional context

n/a

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions