GithubHelp home page GithubHelp logo

seedstack / coffig Goto Github PK

View Code? Open in Web Editor NEW
3.0 10.0 6.0 552 KB

Lightweight configuration library written in Java.

License: Mozilla Public License 2.0

Java 100.00%
java configuration yaml seedstack

coffig's Introduction

SeedStack config library "Coffig"

Build status Coverage Status Maven Central

Coffig is a simple and powerful configuration library for the Java language. It is built upon the idea of mapping configuration trees to Java objects. The following configuration tree in YAML:

some:
  string: value1
  array: [1, 2, 3]
  object:
    attr1: value1
    attr2: [iris, jasmine, kiwi]

Can be retrieved as simply as:

Coffig coffig = Coffig.builder().withProviders(new JacksonProvider().addSource("url/to/file.yaml")).build();
    
String stringValue = coffig.get(String.class, "some.string");
int[] intArray = coffig.get(int[].class, "some.array");
MyPojo myPojo = coffig.get(MyPojo.class, "some.object");
String defaultValue = coffig.getOptional(String.class, "unknown.node").orElse("default");

Mapping

Coffig is able to map any Java class by introspecting its members but can handle special cases with dedicated mappers. Mappers for several types are built-in:

  • Array,
  • List,
  • Set,
  • Map,
  • Enum,
  • Optional,
  • URI/URL,
  • Properties,
  • Class.

You can add you own mappers by implementing the ConfigurationMapper interface and registering it through the ServiceLoader mechanism.

Providers

Multiple providers can be used at once, each providing a separate configuration tree that will be merged into a global one. Several providers are built-in:

  • Jackson (for YAML and JSON sources),
  • Environment variables,
  • System properties.

You can add you own mappers by implementing the ConfigurationProvider interface and registering it through the ServiceLoader mechanism.

Copyright and license

This source code is copyrighted by The SeedStack Authors and released under the terms of the Mozilla Public License 2.0.

coffig's People

Contributors

adrienlauer avatar dependabot[bot] avatar pith avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coffig's Issues

Add an expression language system

A simple EL system would be very useful to declare aliases, use custom piped functions (for cypting, default values, etc.)

Here is a sample of what it could be. A more strict grammar will be defined later.

app.yml

security:
  username: user1
  password: ${"45f4sq654fgq6s54" | decrypt(env.keystore, "sha-256") | trim() | or("password") }

database:
  url: ${etcd.services.toto.url}

Create a Git config provider

This config provider would provide configuration from a set of files from a Git repository. This would support git refs like branches and tags.

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.