hcler

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2019 License: MIT Imports: 5 Imported by: 0

README

hcler

Encode arbitrary Go types to Hashicorp's HCL format.

GitHub release GoDoc Build Status Coverage Status

Usage

Common types

hcler.Encode() can be used with most common types.

Custom types

In order to support custom types, hcler provides the hcler.Encoder interface, similar to json.Marshaler & co. The interface only requires the EncodeHCL() (string, error) method.

Benchmark

goos: linux
goarch: amd64
pkg: github.com/creack/hcler
BenchmarkMapStringKeyEncoder/hcl_map-32                  1000000              1856 ns/op             334 B/op         14 allocs/op
BenchmarkMapStringKeyEncoder/map_str_iface-32            1000000              1883 ns/op             333 B/op         14 allocs/op
BenchmarkMapInterfaceEncoder/hcl_i_map-32                 300000              4259 ns/op            1346 B/op         20 allocs/op
BenchmarkMapInterfaceEncoder/map_iface_iface-32           300000              4561 ns/op            1346 B/op         20 allocs/op
BenchmarkDiscarded/map_str_slice_prealloc-32              500000              3654 ns/op             512 B/op         24 allocs/op
BenchmarkDiscarded/map_str_slice_noprealloc-32            500000              3759 ns/op             528 B/op         25 allocs/op
PASS
ok      github.com/creack/hcler 10.349s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(v interface{}) (string, error)

Encode implements the hcl.Encoder interface.

Types

type Encoder

type Encoder interface {
	EncodeHCL() (string, error)
}

Encoder is the interface implemented by types that can marshal themselves into valid HCL.

type IMap

type IMap map[interface{}]interface{}

IMap .

func (IMap) EncodeHCL

func (m IMap) EncodeHCL() (string, error)

EncodeHCL implements the hcl.Encoder interface. Stringifies the keys and defers to hcl.Map for encoding.

func (IMap) Map

func (m IMap) Map() (Map, error)

Map converts an hcl.IMap to a hcl.Map.

type List

type List []interface{}

List .

func (List) EncodeHCL

func (l List) EncodeHCL() (string, error)

EncodeHCL implements the hcl.Encoder interface. nolint: gosec

type Map

type Map map[string]interface{}

Map .

func (Map) EncodeHCL

func (m Map) EncodeHCL() (string, error)

EncodeHCL implements the hcl.Encoder interface. nolint: gosec

Jump to

Keyboard shortcuts

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