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

How to define user configuration. #240

Closed
wbtlb opened this issue May 17, 2024 · 6 comments
Closed

How to define user configuration. #240

wbtlb opened this issue May 17, 2024 · 6 comments
Labels
question Further information is requested stale

Comments

@wbtlb
Copy link

wbtlb commented May 17, 2024

How can I add new user config settings.

@andrewhavck andrewhavck added the question Further information is requested label May 17, 2024
@drcaramelsyrup
Copy link
Contributor

Sorry for the delay on responding. What do you mean by user config settings?

If you're asking about a configuration file like nginx's, Pingora's current config files are more limited than nginx's and are limited to environment setup, e.g. see the (as-of-today) YAML formatted ServerConf and the user guide.

@wbtlb
Copy link
Author

wbtlb commented May 24, 2024

I mean extand ServerConf with my own configuration parameters.

@johnhurt
Copy link
Contributor

I think your best bet is to use serde's ability to flatten de/serialized structures. Our serverconf is just a struct with a few derives. If you wanted to add some extra configurations to the same file, you could so something like

#[derive(Serialize, Deserialize)]
struct CombinedConf {
    // All pingora configurations come in here
    #[serde(flatten)]
    base_conf: ServerConf,
    
    // Any of your configurations can go here
    #[serde(flatten)]
    custom_conf: CustomConf,
}

#[derive(Serialize, Deserialize)]
struct CustomConf {
    awesomeness_count: f64
    // ...
}

@eaufavor
Copy link
Member

For certain format like yaml and json you can even add your custom field directly into the server_conf.yaml

---
version: 1
threads: 2
awesomeness_count: 3

The yaml above can be directly deserialized to CustomConf. All the fields that are not in your CustomConf are ignored. All the custom fields are ignored by the ServerConf as well.

Copy link

github-actions bot commented Jun 8, 2024

This question has been stale for a week. It will be closed in an additional day if not updated.

@github-actions github-actions bot added the stale label Jun 8, 2024
Copy link

github-actions bot commented Jun 9, 2024

This issue has been closed because it has been stalled with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested stale
Projects
None yet
Development

No branches or pull requests

5 participants