Giter VIP home page Giter VIP logo

node-util-qconf's Introduction

blued-qconf

基于 qconf 的简易封装。

npm install @blued-core/qconf

Usage

目前除mysql配置以外,其余结构都可以简写为key: value,而不需要key: { qconf: value }

import { Qconf } from '@blued/qconf'

const configs = {
  mysqlConf: {
    qconf: 'XXX',     // qconf 路径 ⚠️ 无需包涵 /master /slave 的字眼
    database: 'XXX',  // optional 数据库 database
    modelPath: 'XXX', // optional sequelize 模型路径
  },
  redisConf: {
    qconf: 'XXX',     // qconf 路径
  },
  normalHost: {
    qconf: 'XXX',     // qconf 路径
  },
  normalConf: 'XXX',     // qconf 路径
  redisStringConf: 'XXX',
  normalStringHost: 'XXX',
  normalStringConf: 'XXX'
}

const qconf = new Qconf(config)

// 可选的 flag 参数用于使用不同环境下的配置文件
qconf.flag = 'production'

qconf.getConf('mysqlConf')

除了 MySQL 相关的配置外,其他的都可以直接简写为key: value 而不需要携带 qconf 属性。

API

getConf/getHost

获取一个key所对应的confkey必须存在于实例化qconf时传入的configs
如不存在则会抛出异常can not found conf with key: [key]

qconf.getConf('key') // => string
qconf.getHost('key') // => string

getQconfHost/getQconfConf/getQconfAllHost

根据qconf路径获取对应的参数

qconf.getQconfConf('/qconf/xxx/key')        // => string
qconf.getQconfHost('/qconf/xxx/key')        // => string
qconf.getQconfAllHost('/qconf/xxx/key')     // => string[]

getRedisConf

根据传入的key获取 redis 配置

qconf.getRedisConf('key') // => { host: 'XXX', port: '1234' }

getMysqlConf

根据传入的key获取 mysql 配置

qconf.getMysqlConf('key')

// 返回值如下
{
  masterHost: 'XXX',              // 主库地址
  slaveHost: ['XXX', 'XXX'],      // 从库地址
  username: 'XXX',                // 用户名
  password: 'XXX',                // 密码
  database: 'XXX' || undefined,   // 数据库
  modelPath: 'XXX' || undefined,  // sequelize 对应的模型地址
}

node-util-qconf's People

Contributors

jiasm avatar ryli avatar dependabot[bot] avatar

Watchers

James Cloos avatar Darren avatar supermin avatar Mark avatar Jason Liang avatar  avatar 熊朝阳 avatar dujun 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.