hconf

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

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

Go to latest
Published: Jun 14, 2018 License: MPL-2.0 Imports: 15 Imported by: 0

README

hconf: HCL library for configuration files

GoDoc Build Status

hconf extends the Hashicorp HCL library and is intended to be used as configuration file format.

Configuration file API

hconf is based around a configuration file with sections, and each section can have key/value pairs.

Given a configuration file like this:

section "autoupdate" {
  release_channel = "test"
}

And a Golang structure like this:

type Config struct {
	Autoupdate      Autoupdate      `hsection:"autoupdate"`
}

type Autoupdate struct {
	ReleaseChannel hconf.String `hconf:"release_channel"`
}

This could be parsed like this:

hc := hconf.New(&hconf.Config{})
config := &Config{}

err := hc.DecodeFile(config, "path/to/config.conf")

// config.Autoupdate.ReleaseChannel now contains "test"

Future Ideas

  • Adding conditional when support based on predicates or local command execution to allow a more flexiable configuration file. See predicate.go.

License

hconf is licensed under the Mozilla Public License version 2.0. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

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

func (*Bool) Duplicate

func (s *Bool) Duplicate() Bool

func (*Bool) IsSet

func (s *Bool) IsSet() bool

func (*Bool) SetSource

func (s *Bool) SetSource(p token.Pos)

func (*Bool) SetValue

func (s *Bool) SetValue(v bool)

func (*Bool) Source

func (s *Bool) Source() token.Pos

func (*Bool) Value

func (s *Bool) Value() bool

func (*Bool) ValueBool

func (s *Bool) ValueBool() bool

type Config

type Config struct {
}

type HC

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

func New

func New(c *Config) (*HC, error)

func (*HC) Decode

func (hc *HC) Decode(out interface{}, filename string, data []byte) error

func (*HC) DecodeFile

func (hc *HC) DecodeFile(out interface{}, filename string) error

Decode HC into an object

func (*HC) EditAndSave

func (hc *HC) EditAndSave(filename string, section string, key string, value interface{}) error

EditAndSave open's existing file, edits section/key value, saves back as a formatted HCL. (kitchen sink method)

func (*HC) Get

func (hc *HC) Get(input interface{}, section string, key string) (interface{}, token.Pos, error)

Get a specific value from a section/key pair

func (*HC) Set

func (hc *HC) Set(input interface{}, section string, key string, value interface{}) error

Set a specific value from a section/key pair

type Int64

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

func (*Int64) IsSet

func (s *Int64) IsSet() bool

func (*Int64) SetSource

func (s *Int64) SetSource(p token.Pos)

func (*Int64) SetValue

func (s *Int64) SetValue(v int64)

func (*Int64) Source

func (s *Int64) Source() token.Pos

func (*Int64) Value

func (s *Int64) Value() int64

func (*Int64) ValueInt64

func (s *Int64) ValueInt64() int64

type String

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

func (*String) Duplicate

func (s *String) Duplicate() String

func (*String) IsSet

func (s *String) IsSet() bool

func (*String) SetSource

func (s *String) SetSource(p token.Pos)

func (*String) SetValue

func (s *String) SetValue(v string)

func (*String) Source

func (s *String) Source() token.Pos

func (*String) Value

func (s *String) Value() string

func (*String) ValueString

func (s *String) ValueString() string

type StringSlice

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

func (*StringSlice) Duplicate

func (s *StringSlice) Duplicate() StringSlice

func (*StringSlice) IsSet

func (s *StringSlice) IsSet() bool

func (*StringSlice) SetSource

func (s *StringSlice) SetSource(p token.Pos)

func (*StringSlice) SetValue

func (s *StringSlice) SetValue(v []string)

func (*StringSlice) Source

func (s *StringSlice) Source() token.Pos

func (*StringSlice) Value

func (s *StringSlice) Value() []string

func (*StringSlice) ValueStringSlice

func (s *StringSlice) ValueStringSlice() []string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL