All Projects → gurkankaymak → hocon

gurkankaymak / hocon

Licence: MIT license
go implementation of lightbend's HOCON configuration library https://github.com/lightbend/config

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to hocon

climatecontrol
Python library for loading settings and config data from files and environment variables
Stars: ✭ 20 (-59.18%)
Mutual labels:  environment-variables, configuration-parser
Config
configuration library for JVM languages using HOCON files
Stars: ✭ 5,459 (+11040.82%)
Mutual labels:  hocon, configuration-library
hocon-js
Hocon parser for JavaScript and NodeJS
Stars: ✭ 33 (-32.65%)
Mutual labels:  hocon, hocon-syntax
parse it
A python library for parsing multiple types of config files, envvars & command line arguments that takes the headache out of setting app configurations.
Stars: ✭ 86 (+75.51%)
Mutual labels:  environment-variables, json-parser
ZeroDepJson
A .NET Json parser in one .cs file, with zero dependencies.
Stars: ✭ 20 (-59.18%)
Mutual labels:  json-parser
format-to-json
An algorithm that can format a string to json-like template. 字符串JSON格式化的算法。
Stars: ✭ 30 (-38.78%)
Mutual labels:  json-parser
superconfig
Access environment variables. Also includes presence validation, type coercion and default values.
Stars: ✭ 33 (-32.65%)
Mutual labels:  environment-variables
paerser
No description or website provided.
Stars: ✭ 38 (-22.45%)
Mutual labels:  environment-variables
DynamicParametersBundle
[UNMAINTAINED] Runtime retrieval of parameters from environment variables for Symfony
Stars: ✭ 42 (-14.29%)
Mutual labels:  environment-variables
cra-envs
⚙️ Bundle env var in CRA at launch time!
Stars: ✭ 45 (-8.16%)
Mutual labels:  environment-variables
rune
tool to query for tokens and passwords for use as environment variables
Stars: ✭ 13 (-73.47%)
Mutual labels:  environment-variables
JsonSwiftson
A JSON parser with concise API written in Swift.
Stars: ✭ 14 (-71.43%)
Mutual labels:  json-parser
ajson
Yet another json parser serializer for ABAP
Stars: ✭ 29 (-40.82%)
Mutual labels:  json-parser
checkdotenv
Verify environment variables presence for Node JS.
Stars: ✭ 12 (-75.51%)
Mutual labels:  environment-variables
util
封装了一些Java常用的功能
Stars: ✭ 19 (-61.22%)
Mutual labels:  json-parser
slack-notifier
Command line utility to send messages with attachments to Slack channels via Incoming Webhooks
Stars: ✭ 61 (+24.49%)
Mutual labels:  environment-variables
DBEnvironmentConfiguration
Easily switch between iOS development environments/ configurations
Stars: ✭ 18 (-63.27%)
Mutual labels:  environment-variables
dart environment config
Environment specific config generator for Dart and Flutter applications during CI/CD builds
Stars: ✭ 87 (+77.55%)
Mutual labels:  environment-variables
mikrotik-json-parser
JSON parser library for RouterOS
Stars: ✭ 41 (-16.33%)
Mutual labels:  json-parser
backup-suite
Backup database, static files and config to AWS S3 with Cronjob
Stars: ✭ 32 (-34.69%)
Mutual labels:  environment-variables

HOCON (Human-Optimized Config Object Notation)

Go Report Card codecov Build Status GoDoc Mentioned in Awesome Go

Configuration library for working with the Lightbend's HOCON format. HOCON is a human-friendly JSON superset

Features of HOCON

  • Comments, with # or //
  • Allow omitting the {} around a root object
  • Allow = as a synonym for :
  • Allow omitting the = or : before a { so foo { a : 42 }
  • Allow omitting commas as long as there's a newline
  • Allow trailing commas after last element in objects and arrays
  • Allow unquoted strings for keys and values
  • Unquoted keys can use dot-notation for nested objects, foo.bar=42 means foo { bar : 42 }
  • Duplicate keys are allowed; later values override earlier, except for object-valued keys where the two objects are merged recursively
  • include feature merges root object in another file into current object, so foo { include "bar.json" } merges keys in bar.json into the object foo
  • substitutions foo : ${a.b} sets key foo to the same value as the b field in the a object
  • substitutions concatenate into unquoted strings, foo : the quick ${colors.fox} jumped
  • substitutions fall back to environment variables if they don't resolve in the config itself, so ${HOME} would work as you expect.
  • substitutions normally cause an error if unresolved, but there is a syntax ${?a.b} to permit them to be missing.
  • += syntax to append elements to arrays, path += "/bin"
  • multi-line strings with triple quotes as in Python or Scala

see the documentation for more details about the HOCON https://github.com/lightbend/config/blob/master/HOCON.md

Installation

go get -u github.com/gurkankaymak/hocon

Usage

package main

import (
    "fmt"
    "log"
    "github.com/gurkankaymak/hocon"
)

func main() {
    hoconString := `
    booleans {
      trueVal: true
      trueValAgain: ${booleans.trueVal}
      trueWithYes: yes
      falseWithNo: no
    }
    // this is a comment
    #  this is also a comment
    numbers {
      intVal: 3
      floatVal: 1.0
    }
    strings {
      a: "a"
      b: "b"
      c: "c"
    }
    arrays {
      empty: []
      ofInt: [1, 2, 3]
      ofString: [${strings.a}, ${strings.b}, ${strings.c}]
      ofDuration: [1 second, 2h, 3 days]
    }
    durations {
      second: 1s
      halfSecond: 0.5 second
      minutes: 5 minutes
      hours: 2hours
      day: 1d
    }
    objects {
      valueObject {
        mandatoryValue: "mandatoryValue"
        arrayValue: ${arrays.ofInt}
        nullValue: null
      }
    }`

    conf, err := hocon.ParseResource(hoconString)
    if err != nil {
        log.Fatal("error while parsing configuration: ", err)
    }
    objectValue := conf.GetObject("objects.valueObject")
    arrayValue := conf.GetArray("arrays.ofInt")
    stringValue := conf.GetString("strings.a")
    intValue := conf.GetInt("numbers.intVal")
    floatValue := conf.GetFloat64("numbers.floatVal")
    durationValue := conf.GetDuration("durations.second")
    fmt.Println("objectValue:", objectValue) // {mandatoryValue:mandatoryValue, arrayValue:[1,2,3], nullValue:null}
    fmt.Println("arrayValue:", arrayValue) // [1,2,3]
    fmt.Println("stringValue:", stringValue) // a
    fmt.Println("intValue:", intValue) // 3
    fmt.Println("floatValue:", floatValue) // 1.0
    fmt.Println("durationValue:", durationValue) // 1s
    fmt.Println("all configuration:", conf)
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].