Code Monkey home page Code Monkey logo

Comments (5)

LukasKalbertodt avatar LukasKalbertodt commented on May 20, 2024

@amkartashov could you describe your use case in more detail? Maybe some example code how you wish confique would work?

from confique.

amkartashov avatar amkartashov commented on May 20, 2024

Thanks @LukasKalbertodt
My usecase is to support mutually exclusive sections in config file. I'm writing app which can use different backend types, so it can store blobs on a filesystem or in KV storage or something else.

In config it looks like this (filesystem as backend):

backend:
  actions:
    module: fs
    options:
      path: /tmp/cache/ac
  blobs:
    module: fs
    options:
      path: /tmp/cache/cas
      max_chunk_size: 10000000

or like this (GRPC service as backend for actions, TiKV as backend for blobs)

backend:
  actions:
    module: grpc
    options:
      url: grpc://localhost:8980
  blobs:
    module: tikv
    options:
      db_url:  ...
      max_chunk_size: 10000000

As of now, I use serde to parse config file:

#[derive(Debug, Deserialize, Config, Clone)]
pub struct Conf {
...
    #[config(nested)]
    pub backend: BackendConf,
}

#[derive(Debug, Deserialize, Config, Clone)]
pub struct BackendConf {
...
    pub actions: Option<ActionStorageConf>,
    pub blobs: Option<BlobStorageConf>,
}



#[derive(Debug, Deserialize, Clone)]
#[serde(tag = "module", content = "options")]
pub enum ActionStorageConf {
    #[serde(alias = "fs")]
    FS(FsActionStorageConf),
   ...
}

#[derive(Debug, Deserialize, Clone)]
#[serde(tag = "module", content = "options")]
pub enum BlobStorageConf {
    #[serde(alias = "fs")]
    FS(FsBlobStorageConf),
    ...
}

#[derive(Debug, Deserialize, Clone)]
pub struct FsActionStorageConf {
    pub path: PathBuf,
}

#[derive(Debug, Deserialize, Clone)]
pub struct FsBlobStorageConf {
    pub path: PathBuf,
    #[serde(default = "default_fs_blob_max_chunk_size")]
    pub max_chunk_size: usize,
}

from confique.

amkartashov avatar amkartashov commented on May 20, 2024

So basically, it works this far with serde, but I can't use confique features like using env vars for example.

from confique.

LukasKalbertodt avatar LukasKalbertodt commented on May 20, 2024

Thanks for the example! Seems like a useful feature to me. Is probably related to #14. I will dig into this in the future, trying to come up with a nice API. But no promises as to when. For now I'm happy with 0.2.0. Of course if you want to, you can suggest a specific way confique would derive Config for enums (as comment first, no need to implement it already).

from confique.

milesj avatar milesj commented on May 20, 2024

Require this (specifically tagging stuff) before I can adopt this crate. Here's some examples of our enums:

#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
#[serde(
    untagged,
    expecting = "expected a project name or dependency config object"
)]
pub enum ProjectDependsOn {
    String(ProjectID),
    Object(DependencyConfig),
}


#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
#[serde(
    untagged,
    expecting = "expected a sequence of globs or a map of projects"
)]
pub enum WorkspaceProjects {
    Both {
        globs: Vec<FileGlob>,
        sources: ProjectsMap,
    },
    Globs(Vec<FileGlob>),
    Sources(ProjectsMap),
}

from confique.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.