Skip to content

HTTP configuration service by defining a struct.

License

Notifications You must be signed in to change notification settings

Trisfald/choices

Folders and files

NameName
Last commit message
Last commit date
Feb 18, 2021
Oct 5, 2022
Oct 5, 2022
Oct 5, 2022
May 26, 2022
Oct 5, 2022
Jan 25, 2021
May 26, 2022
Oct 5, 2022
Jan 25, 2021
Feb 27, 2021
May 26, 2022
Feb 11, 2021

Repository files navigation

choices

works badge crates.io Released API docs License: MIT

Do you like structops and clap? Do you write microservices? Continue reading!

choices is a library that lets you expose your application's configuration over HTTP with a simple struct!

Look, it's easy

Given the following code:

use choices::Choices;
use lazy_static::lazy_static;
use std::sync::{Arc, Mutex};

#[derive(Choices)]
struct Config {
    debug: bool,
    id: Option<i32>,
    log_file: String,
}

lazy_static! {
    static ref CONFIG: Arc<Mutex<Config>> = {
        Arc::new(Mutex::new(Config {
            debug: false,
            id: Some(3),
            log_file: "log.txt".to_string()
        }))
    };
}

#[tokio::main]
async fn main() {
    CONFIG.run((std::net::Ipv4Addr::LOCALHOST, 8081)).await;
}

You can see all configuration fields at localhost:8081/config and the individual fields' values at localhost:8081/config/<field name>.
A field's value can be changed with a PUT, for instance curl -X PUT localhost:8081/config/debug -d "true".

More examples in examples.

Also check out the documentation.

Features

  • show all configuration fields
  • GET configuration field
  • PUT configuration field
  • user defined types
  • JSON support
  • custom validators
  • on set callbacks

Thanks

Special thanks to the authors of structops. It served as an inspiration to learn procedural macros.

About

HTTP configuration service by defining a struct.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages