GithubHelp home page GithubHelp logo

konfig's Introduction

Konfig

Build Status Release Snapshot

Konfig is a simple config library for Kotlin that makes use of kotlinx.serialization

Quick Start

Basic Usage

To create your config object, create a new class that inherits from the Konfig class, along with some config property values.

class ServerConfig: Konfig<JsonElement>(JsonEngine()) {
	val host: String by required("host-here")
	val username by required<String>("root")
	val password by required("root-password")
}

To start using this config, you will need to create an instance of it and call the init method.

// create instance
val config = ServerConfig()

// this will generate the config (if it doesn't exist) and load the values from the config file
config.init("server_config.json")

If a config file at that path was not found, it will generate the following.

{
	"host": "host-here",
	"username": "root",
	"password": "root-password"
}

Just like that, you are free to start using the config!

println(config.host) // host-here
println(config.username) // root
println(config.password) // root-password

Mutable Properties

If you have a value that you want to be able to modify in your config, you will need to define the property as being mutable by creating the property as a var

var int: Int by required(0)

You can change the value of this property similar to how you reassign variables.

int = 5

However, this change has not been saved in the config yet. To save this change you will need to call the write method on the config instance.

config.write()

Engines

Since kotlinx.serialization allows you to serialize your objects into different types, konfig also supports this by using serialization engines.

Supported serialization types:

Json -> JsonEngine konfig-core Yaml -> YamlEngine konfig-yaml

Installation

Gradle (Kotlin)

repositories {
    mavenCentral()

	// snapshot repository
    maven("https://s01.oss.sonatype.org/content/repositories/snapshots")
}

dependencies {
    implementation("io.github.qbosst:konfig-core:{version}")
}

Gradle (Groovy)

repositories {
    mavenCentral() 

	// snapshot repository
    maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots" }
}

dependencies {
    implementation "io.github.qbosst:konfig-core:{version}"
}

Maven

<!--snapshot repository-->
<repositories>
    <repository>
        <id>s01-snapshots-repo</id>
        <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
</repositories>

<dependency>
    <groupId>io.github.qbosst</groupId>
    <artifactId>konfig-core</artifactId>
    <version>{version}</version>
</dependency>

konfig's People

Contributors

bosukas 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.