Skip to content

zbroju/gprops

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 

Repository files navigation

gprops

Description

Package gprops implements simple properties object for applications written in golang, similar to the one known from java.

It can be used to store and load simple configuration data in a form of pairs:

key = value

Bear in mind that both key and value are strings. All lines beginning with # are omitted - assuming they are comments.

Installation

This package can be installed with the go get command:

go get github.com/zbroju/gprops

Documentation

Example of configuration file

# Example of configuration file made by gprops package

# Settings are written in a simple KEY = VALUE pairs:
DATA_FILE = /home/.examplerc
VERBOSE = 1

# All lines starting with '#' are skipped, assuming they are just comments

Usage

Remember to include gprops package in your application:

import "github.com/zbroju/gprops"

Load properties from file

// Open config file
file, _ := os.Open(".configFile")
defer file.Close()

// Try to load properties and read the data
properties := gprops.NewProps()
_ := properties.Load(file)

// Assuming the config file looks like the example above
file := properties.Get("DATA_FILE") // variable 'file' contains "/home/.examplerc" value.
verboseFlag := properties.Get("VERBOSE") // variable 'verboseFlag' contains "1" value.

Save properties to a file

// Prepare properties object
properties := gprops.NewProps()
properties.Set("DATA_FILE", "/home/.examplerc")
properties.Set("VERBOSE", "1")

// Create new file with properties
f, _ := os.Create(".configFile")

// Store properties in the file
properties.Store(f, "Example of configuration file made by gprops package")
f.Close()

License

GNU General Public License.

Author

Marcin 'Zbroju' Zbroiński

About

Package gprops impements simple properties object, similar to java one.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages