Coder Social home page Coder Social logo

cfgsrv's Introduction

CfgSrv

It is a very simple config server. I bet most of you have already done something similar but maybe this could be useful for someone else.

Usage:

Save your config files with ".config" extension wherever you want. In my case this will be priv/config/dev and priv/config/prod

Example structure of "priv" directory: Example tree output for priv directory

Example config file content (more examples could be found in priv/config directory of the project):

Example config content

  • Starting Cfgsrv
cfgsrv:start(),
cfgsrv:set_path("priv/config/dev"). %% Default path when application was started is priv/config
  • Reading config values
cfgsrv:get("app", "key"), %% "Value"
cfgsrv:get("app.key_with_subkeys", "subkey2"). %% subkey2_value
cfgsrv:get("app.key_with_subkeys", "nonexistent_key", my_default_value). %% my_default_value
  • Reading multiple values from config
%% You can also pass tuple {Key, Default_value} to get Default_value instead of 'undefined' when the key was not found
cfgsrv:get_multiple("app.key_with_subkeys.subkey1", ["subsubkey1", {"subsubkey2", default_value}, {"subsubkey3", default_value}]).
%% The result will be [subsubkey1_value, subsubkey2_value, default_value]
  • Updating configs
cfgsrv:update() %% This will update all configs data from the initial :PATH
cfgsrv:update("app") %% This will update only app.config data from the initial :PATH ("priv/config/dev")
  • Updating configs path
cfgsrv:set_path("priv/config/prod") %% This will change path from "dev" to "prod" and load new configs

cfgsrv's People

Contributors

chvanikoff avatar d0rc avatar

Watchers

 avatar  avatar  avatar

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.