Giter VIP home page Giter VIP logo

mconfig's Introduction

Build Status

Introduction

MConfig is a flexible and practical library used for getting configuration information for the application.

Features

  • Multiple Source Suppport:

    • Server
    • File
    • Class's static filed, such as BuildField in Android project.
    • Other channels with your own logic
  • Multiple Data Structure Suppport:

    • Map
    • Property
    • Other structures with your own logic
  • Custom Piority

Getting started

Base Java Lib

In your build.gradle

dependencies {
   compile 'tech.saymagic:mconfig-base:1.0.1'
} 

Android Feature Support

In your build.gradle

dependencies {
   compile 'tech.saymagic:mconfig-android:1.0.1'
} 

Example Usage

Suppose we have three configuration source :

  • Default Config: written in source code.
  • Remote Config: used for updating default config, fetch from server.
  • File Config: used for debug. fetch form local file.

We can init MConfig like this:

//Default config, piority is 0.
Map<String, String> defaultMap = new HashMap<String, String>(){{
        put("first", "Mercury");
        put("second", "Venus");
        //...
    }};
IConfigProvider<String, String> defaultProvider = new MapConfigProvider<String, String>(defaultMap, 0);

//Remote config, piority is 1.
MapConfigProvider<String, String> serverProvider = HttpConfigProvider.builder()
            .setMapParser(new PropertiesParser())
            .setUrl("Your Server Path")
            .setExector(MConfig.DEFAULT_EXECTOR)
            .setPriority(1).build();
    
//File config, piority is 2.
File file = new File("Your file path");
MapConfigProvider<String, String> fileProvider = FileConfigProvider.builder()
            .setMapParser(new PropertiesParser())
            .setSource(file)
            .setPriority(2).build();
            
//Init MConfig
MConfig<String, String> config = new MConfig<>();
config.init(defaultProvider, serverProvider, fileProvider);

Completing the above logic, you can use method config.getProperty("***") to get the value you want. MConfig will select the appropriate value according to the piority.

Authors and Contributors

The author is saymagic

Support or Contact

If you have any problems with the library, or want to help, please contact me: saymagic.dev#gmail.com and I will try to reply as soon as I can.

License

Copyright 2017 saymagic

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

mconfig's People

Contributors

saymagic avatar

Stargazers

 avatar

Watchers

 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.