Nothing Special   »   [go: up one dir, main page]

Skip to content
/ storus Public

A library that simplifies the life of rust developers by abstracting the low level communication protocols (REST/gRPC) when they want to use StooKV as their configurations management tool.

License

Notifications You must be signed in to change notification settings

mwangox/storus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Storus

A library that simplifies the life of rust developers by abstracting the low level communication protocols (REST/gRPC) when they want to use StooKV as their configurations management tool.

Crates.io Documentation MIT licensed

Usage

To use storus, include the dependency in your Cargo.toml as :

[dependencies]
storus = "0.1.4"

Next, add this to your crate:

use storus::stoo::Stoo;
use storus::stoo_config::StooConfig;

fn main() {
    // ...
}

Examples

Create stoo client from minimal configurations:

use storus::stoo::Stoo;
use storus::stoo_config::StooConfig;

#[tokio::main]
async fn main() {
    let config = StooConfig::from("http://localhost:50051");
    let mut stookv = Stoo::new(config).await;
}

Create stoo client from extended configurations:

use crate::stoo::Stoo;
use crate::stoo_config::StooConfig;

#[tokio::main]
async fn main() {
    let config = StooConfig::from("https://localhost:50051")
        .response_timeout(Duration::from_millis(20000))
        .connect_timeout(Duration::from_millis(1000))
        .default_namespace("my-app")
        .default_profile("prod")
        .ca_certificate("/tmp/ca_cert.pem")
        .domain("x.test.example.com");
    let mut stookv = Stoo::new(config).await;
}

Complete example:

use storus::stoo::Stoo;
use storus::stoo_config::StooConfig;

#[tokio::main]
async fn main() {
    let config = StooConfig::from("http://localhost:50051");
    let mut stookv = Stoo::new(config).await;

    //set value to a key
    let result1 = stookv.set("my-app", "prod", "database.username", "admin3").await.unwrap();
    println!("result1: {}", result1);

    //get value from key
    let result2 = stookv.get("my-app", "prod", "database.username").await.unwrap();
    println!("result2: {}", result2);

    //get all key value pairs by from a given namespace and profile
    let result3 = stookv.get_all_by_namespace_and_profile("my-app", "prod").await.unwrap();
    println!("result3: {:?}", result3);

    //get a value from default namespace and profile as initially specified
    let result4 = stookv.get_default("database.username").await.unwrap();
    println!("result4: {}", result4);

    //set secret key
    let result5 = stookv.set_secret("my-app", "prod", "database.password", "qwerty@1234").await.unwrap();
    println!("result5: {}", result5);
}

License

The project is licensed under MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Storus by you, shall be licensed as MIT, without any additional terms or conditions.

About

A library that simplifies the life of rust developers by abstracting the low level communication protocols (REST/gRPC) when they want to use StooKV as their configurations management tool.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages