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: cleanup producer code #161

Open
vmarchese opened this issue Aug 15, 2024 · 1 comment
Open

refactor: cleanup producer code #161

vmarchese opened this issue Aug 15, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request To be evaluated Still not clear if needs to be done

Comments

@vmarchese
Copy link
Collaborator

  • no need to different config flags (mongoConfig, redisConfig...). Use just --config`
  • naming should be consistent to avoid redundancy since it is already namescoped
    • e.g. change gcs.GCSProducer in gcs.Producer
  • move Producer interface in the producer package for consistency and isolation
  • define a factory for producer instead of different createXXX methods
  • change emitter.Emitter.Initialize sequence of if using factory with a producer factory map
    • e.g. producerFactory["mongodb"].createProducer()
@vmarchese vmarchese self-assigned this Aug 17, 2024
@vmarchese
Copy link
Collaborator Author

@ugol
In this branch

  • added factory in emitters to simplify the producers creation
  • changed the various --xxxConfig in --producerConfig
  • changed the Redis configuration to add the TTL in the config file to uniform the factory interface

In producers/factory.go there is an (unused for now) factory and the Producer interface. The Factory is filled with factory func by the init method that should go in every concrete impl (see https://github.com/ugol/jr/blob/161-refactor-cleanup-producer-code/pkg/producers/http/init.go for an example, unused for now)
It is true that that best practices say that "Go interfaces generally belong in the package that uses values of the interface type, not the package that implements those values" but I believe that it depends on how you structure the code. If you move everything that is not "exportable" to internal and use the pkg to export producers than I think it is better to have a producers.Producer interface (like io.Closer) in a separate package the defines the behaviour (someone could use JR as a framework and just implement his own producer somewhere else.
Moreover, if we leave the Producer interface in the emitter package the Factory must go there as well to avoid circular references

See the crypto and the aes or cipher std packages for an example
See also this

@vmarchese vmarchese added To be evaluated Still not clear if needs to be done enhancement New feature or request labels Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request To be evaluated Still not clear if needs to be done
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant