configuration

package module
Version: v0.0.0-...-a002c03 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2020 License: Apache-2.0 Imports: 6 Imported by: 18

README

HOCON (Human-Optimized Config Object Notation)

GoDoc HOCON Docs.

Currently, some features are not implemented, the API might be a little changed in the future.

example.go

package main

import (
  "fmt"
  "github.com/go-akka/configuration"
)

var configText = `
####################################
# Typesafe HOCON                   #
####################################

config {
  # Comment
  version = "0.0.1"
  one-second = 1s
  one-day = 1day
  array = ["one", "two", "three"] #comment
  bar = "bar"
  foo = foo.${config.bar} 
  number = 1
  object {
    a = "a"
    b = "b"
    c = {
            d = ${config.object.a} //comment
        }
    }
}
// fallback
config.object.a="newA"
config.object.c.f="valueF"

// self reference
self-ref=1
self-ref=[${self-ref}][2]

// byte size
byte-size=10MiB

// system envs
home:${HOME}

plus-equal=foo
plus-equal+=bar

plus-equal-array=[foo]
plus-equal-array+=[bar, ${HOME}]
`

func main() {
  conf := configuration.ParseString(configText)

  fmt.Println("config.one-second:", conf.GetTimeDuration("config.one-second"))
  fmt.Println("config.one-day:", conf.GetTimeDuration("config.one-day"))
  fmt.Println("config.array:", conf.GetStringList("config.array"))
  fmt.Println("config.bar:", conf.GetString("config.bar"))
  fmt.Println("config.foo:", conf.GetString("config.foo"))
  fmt.Println("config.number:", conf.GetInt64("config.number"))
  fmt.Println("config.object.a:", conf.GetString("config.object.a"))
  fmt.Println("config.object.c.d:", conf.GetString("config.object.c.d"))
  fmt.Println("config.object.c.f:", conf.GetString("config.object.c.f"))
  fmt.Println("self-ref:", conf.GetInt64List("self-ref"))
  fmt.Println("byte-size:", conf.GetByteSize("byte-size"))
  fmt.Println("home:", conf.GetString("home"))
  fmt.Println("default:", conf.GetString("none", "default-value"))
  fmt.Println("plus-equal:", conf.GetString("plus-equal"))
  fmt.Println("plus-equal-array:", conf.GetStringList("plus-equal-array"))
}

> go run example.go
config.one-second: 1s
config.one-day: 24h0m0s
config.array: [one two three]
config.bar: bar
config.foo: foo.bar
config.number: 1
config.object.a: newA
config.object.c.d: a
config.object.c.f: valueF
self-ref: [1 2]
byte-size: 10485760
home: /Users/zeal
default: default-value
plus-equal: foobar
plus-equal-array: [foo bar /Users/zeal]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

func FromObject

func FromObject(obj interface{}) *Config

func LoadConfig

func LoadConfig(filename string) *Config

func NewConfigFromConfig

func NewConfigFromConfig(source, fallback *Config) *Config

func NewConfigFromRoot

func NewConfigFromRoot(root *hocon.HoconRoot) *Config

func ParseString

func ParseString(text string, includeCallback ...hocon.IncludeCallback) *Config

func (*Config) AddConfig

func (p *Config) AddConfig(textConfig string, fallbackConfig *Config) *Config

func (*Config) AddConfigWithTextFallback

func (p *Config) AddConfigWithTextFallback(config *Config, textFallback string) *Config

func (*Config) Copy

func (p *Config) Copy(fallback ...*Config) *Config

func (*Config) GetBoolean

func (p *Config) GetBoolean(path string, defaultVal ...bool) bool

func (*Config) GetBooleanList

func (p *Config) GetBooleanList(path string) []bool

func (*Config) GetByteList

func (p *Config) GetByteList(path string) []byte

func (*Config) GetByteSize

func (p *Config) GetByteSize(path string) *big.Int

func (*Config) GetConfig

func (p *Config) GetConfig(path string) *Config

func (*Config) GetFloat32

func (p *Config) GetFloat32(path string, defaultVal ...float32) float32

func (*Config) GetFloat32List

func (p *Config) GetFloat32List(path string) []float32

func (*Config) GetFloat64

func (p *Config) GetFloat64(path string, defaultVal ...float64) float64

func (*Config) GetFloat64List

func (p *Config) GetFloat64List(path string) []float64

func (*Config) GetInt32

func (p *Config) GetInt32(path string, defaultVal ...int32) int32

func (*Config) GetInt32List

func (p *Config) GetInt32List(path string) []int32

func (*Config) GetInt64

func (p *Config) GetInt64(path string, defaultVal ...int64) int64

func (*Config) GetInt64List

func (p *Config) GetInt64List(path string) []int64

func (*Config) GetNode

func (p *Config) GetNode(path string) *hocon.HoconValue

func (*Config) GetString

func (p *Config) GetString(path string, defaultVal ...string) string

func (*Config) GetStringList

func (p *Config) GetStringList(path string) []string

func (*Config) GetTimeDuration

func (p *Config) GetTimeDuration(path string, defaultVal ...time.Duration) time.Duration

func (*Config) GetTimeDurationInfiniteNotAllowed

func (p *Config) GetTimeDurationInfiniteNotAllowed(path string, defaultVal ...time.Duration) time.Duration

func (*Config) GetValue

func (p *Config) GetValue(path string) *hocon.HoconValue

func (*Config) HasPath

func (p *Config) HasPath(path string) bool

func (*Config) IsArray

func (p *Config) IsArray(path string) bool

func (*Config) IsEmpty

func (p *Config) IsEmpty() bool

func (*Config) IsObject

func (p *Config) IsObject(path string) bool

func (*Config) Root

func (p *Config) Root() *hocon.HoconValue

func (Config) String

func (p Config) String() string

func (*Config) WithFallback

func (p *Config) WithFallback(fallback *Config) *Config

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL