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.
This package can be installed with the go get command:
go get github.com/zbroju/gprops
# 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
Remember to include gprops package in your application:
import "github.com/zbroju/gprops"
// 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.
// 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()
GNU General Public License.
Marcin 'Zbroju' Zbroiński