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
- Variables
- type Config
- func (c *Config) GetBoolean(path string) (bool, error)
- func (c *Config) GetBytes(path string) (int64, error)
- func (c *Config) GetConfig(path string) (*Config, error)
- func (c *Config) GetDouble(path string) (float64, error)
- func (c *Config) GetDuration(path string) (time.Duration, error)
- func (c *Config) GetInt(path string) (int64, error)
- func (c *Config) GetList(path string) ([]*ConfigValue, error)
- func (c *Config) GetString(path string) (string, error)
- func (c *Config) GetValue(path string) (*ConfigValue, error)
- func (c *Config) GetValuePath(segments ...string) (*ConfigValue, error)
- func (c *Config) HasPath(path string) bool
- func (c *Config) HasPathSegments(segments ...string) bool
- func (c *Config) Render(opts ConfigRenderOptions) string
- func (c *Config) Root() *ConfigValue
- func (c *Config) WithFallback(fallback *Config) *Config
- type ConfigRenderOptions
- type ConfigValue
- type ConfigValueType
- type FileReader
Constants ¶
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 ¶
var ConfigFactory factory
ConfigFactory is the entry object mirroring Ruby's Hocon::ConfigFactory.
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 (*Config) GetBoolean ¶
GetBoolean mirrors Config#get_boolean.
func (*Config) GetConfig ¶
GetConfig mirrors Config#get_config: the object at path as a nested Config.
func (*Config) GetDuration ¶
GetDuration mirrors Config#get_duration.
func (*Config) GetList ¶
func (c *Config) GetList(path string) ([]*ConfigValue, error)
GetList mirrors Config#get_list.
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) HasPathSegments ¶
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 ¶
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 ¶
func (o ConfigRenderOptions) SetJSON(b bool) ConfigRenderOptions
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 ¶
FileReader loads the text of a file for [ConfigFactory.ParseFile]. It is an injectable seam so tests need not touch disk.