8000 feat(service): add a config package to load application configuration using Viper by akkahshh24 · Pull Request #27 · Zomato/espresso · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(service): add a config package to load application configuration using Viper #27

New issue < 8000 button aria-label="Close dialog" data-close-dialog="" type="button" data-view-component="true" class="Link--muted btn-link position-absolute p-4 right-0">

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

Open
wants to merge 30 commits into
base: dev
Choose a base branch
from

Conversation

akkahshh24
Copy link

What does this PR do?

Introduces a new config package that loads application configuration from a YAML file espressoconfig.yaml 8000 at startup.

Why is this change necessary?

Centralizing configuration management makes the application more maintainable.
Loading configuration from a YAML file allows easier updates without modifying code.

Module

service

Related Issues

Related to #25

@akkahshh24 akkahshh24 changed the title feat: add a config package to load application configuration using Viper feat(service): add a config package to load application configuration using Viper May 13, 2025
db:
host: "localhost"
port: 3308
Copy link
Contributor

Choose a reason for hiding this comment

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

3306? check dockercompose

Copy link
Author

Choose a reason for hiding this comment

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

As I was running Espresso service in my local machine (in debug mode) and not as a docker container, I had mapped the host as localhost and port as 3308 instead of 3306. I will resolve this error and push it.

)

func Load() (model.Config, error) {
viper.AutomaticEnv()
Copy link
Contributor

Choose a reason for hiding this comment

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

move to service/internal pkg

Copy link
Author

Choose a reason for hiding this comment

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

service/internal/pkg/config/config.go ?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes

"github.com/Zomato/espresso/lib/s3"
)

type Config struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

move this to service/internal pkg

Copy link
Author

Choose a reason for hiding this comment

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

service/internal/pkg/config/model/config.go ?

Copy link
Contributor

Choose a reason for hiding this comment

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

..pkg/config/model.go for models and pkg/config/config.go for logic

@Ashish-walkingn8mare
Copy link
Contributor

related to #25

@akkahshh24
Copy link
Author

@Ashish-walkingn8mare A lot of dependencies are being created at the time of handling requests which should be created at the time of application startup.

For example,

  1. Problem: Certificate and key files are loaded for every request.

service/controller/pdf_generation/pdf_generation.go

Screenshot 2025-05-23 at 12 11 58 PM

Possible Solution:
Can we add a Signer object in the EspressoService struct and load these signing credentials once during startup?

  1. Problem: The file storage and template storage adapters are being initialized in the GeneratePDFStream() function every time a request is being handled.

service/internal/service/generateDoc/generatePdf.go

Screenshot 2025-05-23 at 12 13 29 PM

Possible Solution:
Can we use the MySQL TemplateStorageAdapter which is already initialized at startup and only create a stream type FileStorageAdapter?

@akkahshh24 akkahshh24 force-pushed the feature/config_service_dev branch from fe9c180 to f18c11d Compare May 23, 2025 11:33
@akkahshh24
Copy link
Author

@Ashish-walkingn8mare how should we proceed?

@Ashish-walkingn8mare
Copy link
Contributor

@akkahshh24 lets first close the issue at hand, this can be a new issue, although service is only made as a demo, its not necessary to add these improvements

9E88
@Ashish-walkingn8mare
Copy link
Contributor

@akkahshh24 lmk when changes are ready to review, please test throughly before that

@akkahshh24
Copy link
Author

@Ashish-walkingn8mare I will pass mySQL DSN and other parameters to these functions to get rid of viper.GetString() at all places. Will let you know once done.

@Ashish-walkingn8mare
Copy link
Contributor
Ashish-walkingn8mare commented May 28, 2025

@akkahshh24 I see what you were saying earlier, passing these env variables like DSN into the functions is not correct.

For Prob1- Initilize all the certificates from the config at init into the espresso service. Make sure to add support for new certificate config keys in the same format
For Prob2- The backend API in itself is capable of using the other adapters, (check GeneratePDF in controllers), so we cannot remove that option for the user. Whereas our UI is only capable of using the mysql adapter, which is why we are initializing the mysql adapters each time in generatePdfStream(which powers our UI). A better solution for this would be to create another env variable, specifically for our UI APIs, and use that here. Do not pass the DSN into the adapter funcs.

@akkahshh24
Copy link
Author

@Ashish-walkingn8mare Added Credential Store.

@akkahshh24
Copy link
Author

@Ashish-walkingn8mare any changes to be made?

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.

2 participants
0