cfg

package module
Version: v0.0.0-...-6726b6d Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2017 License: MIT Imports: 6 Imported by: 0

README

Simple config file reader for Golang applications

Build Status GoDoc

Users often forget quotes, separators, braces and don't want to learn syntax of json, xml, yaml, toml, whateverML to create or edit config files.


Installation:

go get github.com/is73/cfg

Test:

go test github.com/is73/cfg

Features:

  • First word on line is a key name, can't contain white space
  • Sections can be emulated using key prefix
  • Key duplicity is not allowed
  • Any white space after first word, space or tab (even multiple), is a key value separator
  • Anything after separator except new line character is the value of the key
  • Values may contain white space characters
  • Lines without value are ignored
  • Empty lines are ignored

Config file example:

See also config.txt and main.go in example folder

# this is a comment line
# file contains intentional spaces and tabs
key1 value1
key2	value2
key3		value3 value3	value3
# next line is ignored, value is missing
keynoval
user.id 1
user.name john
user.surname doe
# next empty line is ignored

smtp_server		smtp.example.com
smtp_port 		25
smtp_user		info@example.com
smtp_password		harDtoGueSs

Documentation

Overview

Package cfg provides function(s) to read specific key/value configuration file format similar to .INI files for Go applications

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Read

func Read(fileName, keyPrefix string) (map[string]string, error)

Read reads config file and returns its contents as Go map, a.k.a associative array of keys and values. Use keyPrefix to emulate sections. fileName is mandatory. keyPrefix is optional.

Types

This section is empty.

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto