Giter Club home page Giter Club logo

configurationtools's Introduction

ConfigurationTools

交流反馈QQ群: 717324776
This is a tool that can simplify the process for programmers to process configuration files.
It has the following features:

  • better profile operation through proxy mode
  • automatic refresh of file updates
  • json, yaml and properties formats
  • configuration file group, that is, all configuration files under the specified folder of batch agent
  • asynchronous update and synchronous modification
  • By annotating the binding node, there will also be a default implementation, that is, binding according to the method name

Simpler, for example you can quickly access a yaml configuration using the method provided in ConfigurationTools.
First, suppose you have a yaml configuration file named config.yml as follows

settings:
  enable: true
  debug: false

Then, write the corresponding configuration interface according to the yaml configuration file

@Configuration
interface SettingsConfig extends AutoConfiguration {
    
    @Binding("settings.enable")
    boolean isEnabled();
    
    @Binding("settings.debug")
    boolean isDebug();
    
}

Next, you can enhance the SettingsConfig using ConfigurationEnhancer#enhance and get a proxy SettingsConfig object

SettingsConfig settingsConfig = ConfigurationEnhancer.enhance(SettingsConfig.class);
settingsConfig.isEnabled();
settingsConfig.isDebug();

For more complex ones, suppose you have a folder datas which contains all players' data, and the data of each player is like this

name: 'rokuko'
password: '******'
count: 100
hobbies:
 - 'programming'
 - 'gaming'
 - 'traveling'

Then, you can generate proxy objects for them by configuring file groups

@Configuration(group = true, folder = "datas")
interface DataConfig extends AutoConfigurationGroup<DataConfig> {

    @Binding("name")
    String getName();

    @Binding("password")
    String getPassword();

    @Binding("count")
    Integer getCount();

    @Binding("hobbies")
    List<String> getHobbies();

}

Finally, you can obtain all the configuration file data through the enhanced object's groups method

DataConfig datas = ConfigurationEnhancer.enhance(DataConfig.class);
datas.groups().forEach(playerData -> {
    logger.info(
        "name: {}, password: {}, count: {}, hobbies: {}",
        playerData.getName(),
        playerData.getPassword(),
        playerData.getCount(),
        playerData.getHobbies()
    );
});

Due to the space problem, only the most basic usage is shown here.
If you are interested in this project, welcome star and contribute code to it.
Your support will be the greatest encouragement.

configurationtools's People

Contributors

rokukoo avatar

Stargazers

 avatar  avatar

Watchers

 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.