Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor creating provider in CLI #54

Merged
merged 5 commits into from Aug 3, 2022
Merged

Refactor creating provider in CLI #54

merged 5 commits into from Aug 3, 2022

Conversation

rossf7
Copy link
Contributor

@rossf7 rossf7 commented Aug 3, 2022

Towards #44

Last PR for the refactoring.

@rossf7 rossf7 changed the title Refactor creating provider in CLI WIP: Refactor creating provider in CLI Aug 3, 2022
"github.com/thegreenwebfoundation/grid-intensity-go/pkg/provider"
)

func getClient(providerName string, cacheFile string) (provider.Interface, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used by both the root and exporter commands to set up a client for the relevant provider.

@rossf7 rossf7 marked this pull request as ready for review August 3, 2022 13:54
@rossf7 rossf7 changed the title WIP: Refactor creating provider in CLI Refactor creating provider in CLI Aug 3, 2022
Copy link
Member

@mrchrisadams mrchrisadams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with this - just one query. It's not a blocker for merging this in

return nil, fmt.Errorf("could not make electricity map provider, %w", err)
}
case provider.Ember:
client, err = provider.NewEmber()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've discussed pulling monthly data as a future feature, now that Ember is now publishing, and this got me thinking.

These New Ember and NewElectricityMap examples are because we have this temporary state of both being in use, right?

In a later release we'd revert to just having one Ember provider, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I'm not sure on this. I thought we wanted to keep the ElectricityMap provider?

For Ember right now we're using the embedded data but we could extend this provider to fetch the monthly data instead?

Or if we wanted to support both the data file and fetching data I think we'd need to add another arg to grid-intensity to specify a time period. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, sorry - I should have been clear - I think we'd still totally keep the electricitymap provider. I was referring to Ember/NewEmber, and should have been more specific.

Yeah, I'm in favour of being able to extend the provider with extra command line args rather than having a separate provider for this. I'll create an issue to discuss that separately though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah got it thanks for clarifying.

Go doesn't strictly have constructors but this is the equivalent.
https://go.dev/doc/effective_go#composite_literals

I agree better to add optional parameters in the CLI instead of adding another provider.

@rossf7 rossf7 merged commit 49cb68b into main Aug 3, 2022
@rossf7 rossf7 deleted the client-cmd branch August 3, 2022 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants