horizon

module
v1.13.3 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2025 License: MIT

README

horizon

GoDoc

horizon is a Go library that provides enhanced marshaling and unmarshaling capabilities between HCL (HashiCorp Configuration Language) and Go structures. It specifically addresses limitations in the standard HCL library regarding interface types and complex map structures.

It also includes utilities for converting between HCL, JSON, and YAML formats.

Features

  • Enhanced HCL Support:
    • Interface Types: Dynamic resolution of interface fields at runtime.
    • Complex Maps: Support for map[string]*Struct and map[[2]string]*Struct.
    • Slices of Interfaces: Handle []interface{} seamlessly.
    • HCL Labels: Map keys can be used as HCL labels.
  • Format Conversion: Convert data between HCL, JSON, and YAML.

Installation

go get github.com/genelet/horizon

Documentation

For detailed documentation and tutorials, please refer to DOCUMENT.md.

Usage

Library Usage (dethcl)

The dethcl package provides Marshal and Unmarshal functions similar to encoding/json.

package main

import (
    "fmt"
    "github.com/genelet/horizon/dethcl"
)

type Config struct {
    Name    string   `hcl:"name"`
    Enabled bool     `hcl:"enabled,optional"`
}

func main() {
    // Unmarshal HCL
    hclData := []byte(`
        name = "example"
        enabled = true
    `)
    var cfg Config
    err := dethcl.Unmarshal(hclData, &cfg)
    if err != nil {
        panic(err)
    }
    fmt.Printf("Config: %+v\n", cfg)

    // Marshal to HCL
    data, err := dethcl.Marshal(&cfg)
    if err != nil {
        panic(err)
    }
    fmt.Println(string(data))
}
Command Line Tool (fmtconvert)

The project includes a command-line tool fmtconvert to convert between formats.

Build:

go build -o fmtconvert cmd/fmtconvert/main.go

Usage:

./fmtconvert -from json -to hcl input.json

Supported formats: json, yaml, hcl.

License

See LICENSE file.

Directories

Path Synopsis
cmd
fmtconvert command
Package dethcl implements marshaling and unmarshaling between HCL (HashiCorp Configuration Language) and Go structures.
Package dethcl implements marshaling and unmarshaling between HCL (HashiCorp Configuration Language) and Go structures.
internal
ipaddr
Package ipaddr is a fork of a subset of the Go standard "net" package which retains parsing behaviors from Go 1.16 or earlier.
Package ipaddr is a fork of a subset of the Go standard "net" package which retains parsing behaviors from Go 1.16 or earlier.
lang/types
Package types contains non-standard cty types used only within Terraform.
Package types contains non-standard cty types used only within Terraform.

Jump to

Keyboard shortcuts

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