Giter Site home page Giter Site logo

wasiqb / coteafs-config Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 346 KB

:wrench: Simple multi format configuration support for your project.

License: Apache License 2.0

Java 99.06% HCL 0.94%
java json-config yaml-config xml-config properties pojo hacktoberfest

coteafs-config's Introduction

Simple multi format configuration support for your project created in Java.

Open Source Love CircleCI Test Coverage Quality Gate Maintainability Reliability Security Vulnerability Duplicate Code Maven Central Github Releases License

💥 What's this all about?

This is a simple library to parse Config files of different formats into POJO's. It can directly be dropped into your Maven / Gradle projects and can be used in the project without any hassle.

⛳ How to use?

To use this library, define your project specific config's POJO in whichever package as you may wish. Then define your POJO's fields using lowerCaseNamingConvention, and generate getter-setters for each field accordingly. Finally, define default values for your config class in it's constructor.

ServiceSetting.java

import com.github.wasiqb.coteafs.config.util.BasePojo;

public class ServiceSetting extends BasePojo {
  private int port;
  private String type;
  private String  url;

  // Define default values for the config.
  public ServiceSetting () {
    this.apiPort = 3000;
    this.apiType = "Rest";
    this.apiUrl = "https://localhost";
  }

  public int getPort () {
    return this.port;
  }

  public String getType () {
    return this.type;
  }

  public String getUrl () {
    return this.url;
  }

  public void setPort (final int port) {
    this.port = port;
  }

  public void setType (final String type) {
    this.type = type;
  }

  public void setUrl (final String url) {
    this.url = url;
  }
}

Once this is done, now you just need to define your POJO's corresponding config file for your project, as shown below:

Pro Tip! If you don't want to create the config file manually, then no need to worry, This library will create the config file for you with default values set in the constructor.

Yaml Config file

test-config.yaml

url: http://localhost
port: 8080
type: ${ENV_TYPE} # Environment variable placeholders are allowed.

JSON Config file

test-config.json

{
  "api_url": "http://localhost",
  "api_port": 8080,
  "api_type": "SOAP"
}

XML Config file

test-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<ServiceSetting>
  <api_url>http://localhost</api_url>
  <api_port>8080</api_port>
  <api_type>SOAP</api_type>
</ServiceSetting>

Properties Config file

test-config.properties

api_url = http://localhost
api_port = 8080
api_type = SOAP

Additional Tip!! This library also supports Environment and System property placeholders in the config file for string fields but only for YAML and JSON format configs.

Make sure that config keys are lower_case_with_words_separated_with_underscore.

The config file path can be provided in Environment variable with key coteafs.config, if it is not defined, then it will search System property with same key, if that is also not available then by default, it will search for file named test-config.yaml under src/test/resources directory.

You can define your own key by using withKey method of ConfigLoader class. You can also define default file name which can be found under resources folder using withDefault method.

Example

import static com.github.wasiqb.coteafs.config.loader.ConfigLoader.settings;
. . .
  ServiceSetting setting = settings ().withKey ("coteafs.xyz.setting")
    .withDefault ("test-config-xyz.json")
    .load (ServiceSetting.class);
. . .

📌 Usage?

You can use the following dependency into your pom.xml to use this library.

  <dependency>
    <groupId>com.github.wasiqb.coteafs</groupId>
    <artifactId>configs</artifactId>
    <version>2.2.0</version>
  </dependency>

Jar files can be directly downloaded from Release tab.

❓ Need Assistance?

  • Directly chat with me on my site and I'll revert to you as soon as possible.
  • Discuss your queries by writing to me @ [email protected]
  • If you find any issue which is bottleneck for you, search the issue tracker to see if it is already raised.
  • If not raised, then you can create a new issue with required details as mentioned in the issue template.

⭐ What you do if you like the project?

  • Spread the word with your network.
  • Star the project to make the project popular.
  • Stay updated with the project progress by Watching it.
  • Contribute to fix open issues, documentations or add new features. To know more, see our contributing page.
  • I would be delighted if you can Sponsor this project and provide your support to open source development by clicking on the Sponsor button on the top of this repository.

✔️ Contributors

🎫 Versioning ideology

©️Wasiq Bhamla

coteafs-config's People

Contributors

mfaisalkhatri avatar wasiqb avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

coteafs-config's Issues

Move to Java 11.

It is required to move to Java 11 as Sonar cloud is deprecating Java 8 and scanners using them will stop functioning after October 2020.

Interpolate field values to check for Env variable or System property.

Currently the field values are fetched from config file as it is, even when the field value contains a place holder.

It is now required that when there is a place holder in any field, then it should first check Environment variable, if that is not specified, then check system properties, if that is also not specified then return default value for that field.

Support for txt file.

Need to provide support to read txt config file.

Data in the file might come in any one format:

  1. Pipe Separated.
  2. Tab Separated.

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.