Coder Social home page Coder Social logo

jitsi-metaconfig's Introduction

Java CI with Maven Code Coverage

jitsi-metaconfig

jitsi-metaconfig is not a config library. jitsi-metaconfig helps solve the problems around the evolution of configuration properties, such as:

  1. Property names changing
  2. Changing property file locations or formats
  3. The value type of a property key changing (e.g. it was a number of milliseconds but is now a Duration)

jitsi-metaconfig allows defining properties in code in such a way that names, locations and types can all be changed while still supporting the old format so deployments which use old keys/types/files won't break. It also supports marking old properties as deprecated to ease the transition to removing support for them.

Example config properties:

class Foo {
    // A simple property with just a key and a source
    val enabled: Boolean by config("app.enabled".from(myConfigSource))

    // Optional property
    val optionalParam: String? by optionalconfig("app.client.optional-param".from(myConfigSource))

    // Convert the type (retrieve as a Long, convert to a Duration)
    val interval: Duration by config {
        "app.interval-ms".from(myConfigSource).convertFrom<Long>(Duration::ofMillis)
    }

    // Transform the value (invert the retrieved boolean value)
    val enabled: Boolean by config {
        "app.disabled".from(myConfigSource).andTransformBy { !it }
    }

    // Search for value in a legacy config file and then the new one
    val enabled: Boolean by config {
        "old.path.app.enabled".from(legacyConfigSource)
        "new.path.app.enabled".from(newConfigSource)
    }

    // Search for value in a legacy config file and then the new one, mark the old one as deprecated
    val enabled: Boolean by config {
        "old.path.app.enabled".from(legacyConfigSource).softDeprecated("use 'new.path.app.enabled' in new config source")
        "new.path.app.enabled".from(newConfigSource)
    }

    // Use the result of a lambda as a value
    val port: Int by config {
        "path.to.port".from(newConfigSource)
        "default" { 8080 }
    }

    // Only allow access to port if 'enabled' is true (throws an exception otherwise)
    val port: Int by config {
        onlyIf("Server is enabled", ::enabled) {
            "path.to.port".from(newConfigSource)
        }
    }
}

Read more:

jitsi-metaconfig's People

Contributors

bbaldino avatar bgrozev 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.