GithubHelp home page GithubHelp logo

etcd2json's Introduction

etcd2json

turn etcd configs to json

Rules

  • A Dictionary is an Object or Array.
  • A Property is a key-value pair, or Array Element.
  • If the name of Dictionary or Property is a number, then the parent node will be casted into an Array
  • String true and false will be turned into Boolean
  • If number and letter key name exists in the same level, the final result will be decided by the last element.
  • Empty Property and Dictionary will be turned into '' and {}

Usage

var etcd2json = require('etcd2json');
var etcdHosts = process.env.ETCD_HOST.split(',') || ['127.0.0.1:2379'];
var etcdClient = new Etcd(etcdHosts);
var defaultResult = etcd2json.retrieve(etcdClient, '/v1/production/default');
var appResult = etcd2json.retrieveMultiPath(etcdClient, ['/v1/production/default', '/v1/production/app1']);

There are two functions, retrieve and retrieveMultiPath. You can pass an array to retrieveMultiPath function. The latter value will overwrite the previous value, if they have the same key.

Examples

Etcd Configs

  • + v1
    • + production
      • + default
        • - mongoUrl: localhost
        • - rabbitmqUrl: localhost
        • + redis:
          • + 1
            • - host: 127.0.0.1
            • - port: 3306
          • + 2
            • - host: 127.0.0.2
            • - port: 3306
      • + app1
        • - mongoUrl: 127.0.0.1:12345
        • - isDeploy: true
        • - special: (Empty)
        • + elasticSearch
          • - 1: 127.0.0.1:9200
          • - 1: 127.0.0.2:9200
          • - 1: 127.0.0.2:9200

JSON Result

{
  "mongoUrl": "127.0.0.1:12345",
  "rabbitmqUrl": "localhost",
  "isDeploy": true,
  "special": "",
  "redis": [
    {
      host: "127.0.0.1",
      port: "3306"
    },
    {
      host: "127.0.0.2",
      port: "3306"
    }
  ],
  "elasticSearch": [
    "127.0.0.1:9200",
    "127.0.0.2:9200",
    "127.0.0.3:9200"
  ]
}

etcd2json's People

Contributors

tiant167 avatar

Watchers

James Cloos 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.