hocon

package module
v0.0.0-...-c5b9dda Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package hocon is a pure-Go (no cgo) adapter that presents the Ruby `hocon` gem's API surface over the parser engine github.com/go-hocon/hocon.

The go-hocon engine already implements HOCON semantics in full: the JSON superset grammar, object merging, array and value concatenation, ${...} substitutions with environment fallback, += self-append, include directives and duration / size unit suffixes. This package does not reimplement any of that; it wraps the engine and renames its surface to mirror the Ruby gem so a consumer such as go-embedded-ruby (rbgo) can expose a Ruby "Hocon" module:

  • Parse mirrors Hocon.parse(string);
  • ConfigFactory mirrors Hocon::ConfigFactory (parse_string / parse_file, the latter through an injectable FileReader seam);
  • Config mirrors Hocon::ConfigObject/Config: get_string, get_int, get_boolean, get_double, get_list, get_config, has_path?, with_fallback, root, get_duration and get_bytes;
  • ConfigValueFactory mirrors Hocon::ConfigValueFactory.from_any_ref and friends, converting native Go values into engine [ConfigValue]s;
  • ConfigRenderOptions mirrors Hocon::ConfigRenderOptions, driving Config.Render back to HOCON or JSON.

The package has no dependency on any Ruby runtime: the surface is Go-typed, and a Ruby binding layer marshals Ruby values onto these Go types.

Index

Constants

View Source
const (
	NullType    = gohocon.NullType
	BooleanType = gohocon.BooleanType
	NumberType  = gohocon.NumberType
	StringType  = gohocon.StringType
	ArrayType   = gohocon.ArrayType
	ObjectType  = gohocon.ObjectType
)

Value type constants, re-exported from the engine.

Variables

View Source
var ConfigFactory factory

ConfigFactory is the entry object mirroring Ruby's Hocon::ConfigFactory.

View Source
var ConfigValueFactory valueFactory

ConfigValueFactory is the entry object mirroring Hocon::ConfigValueFactory.

Functions

This section is empty.

Types

type Config

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

Config mirrors Ruby's Hocon::Config: a resolved configuration tree with typed, path-addressed accessors.

func Parse

func Parse(s string) (*Config, error)

Parse mirrors Ruby's Hocon.parse: it parses a HOCON string into a Config.

func (*Config) GetBoolean

func (c *Config) GetBoolean(path string) (bool, error)

GetBoolean mirrors Config#get_boolean.

func (*Config) GetBytes

func (c *Config) GetBytes(path string) (int64, error)

GetBytes mirrors Config#get_bytes.

func (*Config) GetConfig

func (c *Config) GetConfig(path string) (*Config, error)

GetConfig mirrors Config#get_config: the object at path as a nested Config.

func (*Config) GetDouble

func (c *Config) GetDouble(path string) (float64, error)

GetDouble mirrors Config#get_double.

func (*Config) GetDuration

func (c *Config) GetDuration(path string) (time.Duration, error)

GetDuration mirrors Config#get_duration.

func (*Config) GetInt

func (c *Config) GetInt(path string) (int64, error)

GetInt mirrors Config#get_int.

func (*Config) GetList

func (c *Config) GetList(path string) ([]*ConfigValue, error)

GetList mirrors Config#get_list.

func (*Config) GetString

func (c *Config) GetString(path string) (string, error)

GetString mirrors Config#get_string.

func (*Config) GetValue

func (c *Config) GetValue(path string) (*ConfigValue, error)

GetValue returns the raw ConfigValue at a dotted path. As in Ruby's hocon, each `.` starts a new object level; a key that contains a literal dot (written quoted, e.g. `"a.b" = 1`) is reached with Config.GetValuePath instead.

func (*Config) GetValuePath

func (c *Config) GetValuePath(segments ...string) (*ConfigValue, error)

GetValuePath returns the raw ConfigValue at a path given as explicit segments, bypassing dotted-path parsing. This mirrors accessing a literal-dot key in Ruby's hocon by quoting the segment: for `"a.b" = 1`, GetValuePath("a.b") returns 1 whereas GetValue("a.b") looks for nested a.b.

func (*Config) HasPath

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

HasPath mirrors Config#has_path?.

func (*Config) HasPathSegments

func (c *Config) HasPathSegments(segments ...string) bool

HasPathSegments mirrors Config#has_path? for an explicit, non-dotted path.

func (*Config) Render

func (c *Config) Render(opts ConfigRenderOptions) string

Render serialises the config using the given options (mirrors config.root.render(options)).

func (*Config) Root

func (c *Config) Root() *ConfigValue

Root mirrors Config#root: the root object value.

func (*Config) WithFallback

func (c *Config) WithFallback(fallback *Config) *Config

WithFallback mirrors Config#with_fallback: values missing from c are filled from fallback (objects deep-merge, c winning).

type ConfigRenderOptions

type ConfigRenderOptions struct {
	// JSON renders strict JSON instead of HOCON.
	JSON bool
	// Indent is the per-level indent (empty means the engine default).
	Indent string
}

ConfigRenderOptions mirrors Hocon::ConfigRenderOptions.

func DefaultRenderOptions

func DefaultRenderOptions() ConfigRenderOptions

DefaultRenderOptions returns the default (HOCON) render options.

func (ConfigRenderOptions) SetIndent

func (o ConfigRenderOptions) SetIndent(indent string) ConfigRenderOptions

SetIndent returns a copy with the indent set.

func (ConfigRenderOptions) SetJSON

SetJSON returns a copy with JSON toggled (mirrors set_json).

type ConfigValue

type ConfigValue = gohocon.ConfigValue

ConfigValue is a single HOCON value, re-exported from the engine so callers depend on a single import.

type ConfigValueType

type ConfigValueType = gohocon.ConfigValueType

ConfigValueType classifies a ConfigValue, re-exported from the engine.

type FileReader

type FileReader func(path string) (string, error)

FileReader loads the text of a file for [ConfigFactory.ParseFile]. It is an injectable seam so tests need not touch disk.

Jump to

Keyboard shortcuts

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