Categorygithub.com/go-aah/forge
modulepackage
0.8.0
Repository: https://github.com/go-aah/forge.git
Documentation: pkg.go.dev

# README

forge

Build Status codecov GoDoc License

Forge is a configuration syntax and parser forked for aah framework.

Installation

require github.com/go-aah/forge v0.8.0

Example

You can see example usage in the example folder.

# example.cfg

# Global directives
global = "global value";

# Pull in the "PATH" environment variable
path_env = $PATH;

# Primary section
primary {
  string = "primary string value";
  single = 'single quotes are allowed too';

  # Semicolons are optional
  integer = 500
  float = 80.80
  boolean = true
  negative = FALSE
  nothing = NULL

  list = [50.5, true, false, "hello", 'world'];

  # Include external files
  include "./include*.cfg";
  # Primary-sub section
  sub {
      key = "primary sub key value";
  }
}

# Secondary section
secondary {
  another = "secondary another value";
  global_reference = global;
  primary_sub_key = primary.sub.key;
  another_again = .another;  # References secondary.another
  _under = 50;
}
package main

import (
	"fmt"
	"json"

	"github.com/go-aah/forge"
)

func main() {
	// Parse a `SectionValue` from `example.cfg`
	settings, err := forge.ParseFile("example.cfg")
	if err != nil {
		panic(err)
	}

	// Get a single value
	if settings.Exists("global") {
		// Get `global` casted as a string
		value, _ := settings.GetString("global")
		fmt.Printf("global = \"%s\"\r\n", value)
	}

	// Get a nested value
	value, err := settings.Resolve("primary.included_setting")
	fmt.Printf("primary.included_setting = \"%s\"\r\n", value.GetValue())

	// You can also traverse down the sections manually
	primary, err := settings.GetSection("primary")
	strVal, err := primary.GetString("included_setting")
	fmt.Printf("primary.included_setting = \"%s\"\r\n", strVal)

	// Convert settings to a map
	settingsMap := settings.ToMap()
	fmt.Printf("global = \"%s\"\r\n", settingsMap["global"])

	// Convert settings to JSON
	jsonBytes, err := settings.ToJSON()
	fmt.Printf("\r\n\r\n%s\r\n", string(jsonBytes))
}

Issues/Requests?

Please feel free to open a github issue for any issues you have or any feature requests.

# Packages

No description provided by the author
No description provided by the author

# Functions

NewBoolean will create and initialize a new Boolean type primative value.
NewFileParser will create and initialize a new Parser from a provided from a filename string.
NewFloat will create and initialize a new Float type primative value.
NewInteger will create and initialize a new Integer type primative value.
NewList will create and initialize a new List value.
NewNull will create and initialize a new Null type primative value.
NewParser will create and initialize a new Parser from a provided io.Reader.
NewPrimative will create a new empty Primative and call UpdateValue with the provided value.
NewReference will create and initialize a new Reference value.
NewScanner creates and initializes a new *Scanner from an io.Readerx.
NewSection will create and initialize a new Section.
NewString will create and initialize a new String type primative value.
ParseBytes takes a []byte representation of the config file, parses it and responds with `*Section` and potentially an `error` if it cannot properly parse the config.
ParseFile takes a string filename for the config file, parses it and responds with `*Section` and potentially an `error` if it cannot properly parse the configf.
ParseReader takes an `io.Reader` representation of the config file, parses it and responds with `*Section` and potentially an `error` if it cannot properly parse the config.
ParseString takes a string representation of the config file, parses it and responds with `*Section` and potentially an `error` if it cannot properly parse the config.
RegisterFS method to register new file system into forge.

# Constants

BOOLEAN ValueType.
FLOAT ValueType.
INTEGER ValueType.
LIST ValueType.
NULL ValueType.
REFERENCE ValueType.
SECTION ValueType.
STRING ValueType.
UNKNOWN ValueType.

# Variables

ErrNotExists represents a nonexistent value error.
Version represent current release version of forge.

# Structs

List struct used for holding data neede for Reference data type.
Parser is a struct to hold data necessary for parsing a config from a scanner.
Primative struct for holding data about primative values.
Reference struct used for holding data neede for Reference data type.
Scanner struct used to hold data necessary for parsing tokens from the input reader.
Section struct holds a map of values.

# Interfaces

FileSystem interface to expand configuration file parsing possiblities.
Value is the base interface for Primative and Section data types.

# Type aliases

NativeFS type defines methods for native file system.
ValueType is an int type for representing the types of values forge can handle.