1 Overview [![Build Status](https://travis-ci.org/magiconair/properties.svg?branch=master)](https://travis-ci.org/magiconair/properties)
4 #### Current version: 1.7.3
6 properties is a Go library for reading and writing properties files.
8 It supports reading from multiple files or URLs and Spring style recursive
9 property expansion of expressions like `${key}` to their corresponding value.
10 Value expressions can refer to other keys like in `${key}` or to environment
11 variables like in `${USER}`. Filenames can also contain environment variables
12 like in `/home/${USER}/myapp.properties`.
14 Properties can be decoded into structs, maps, arrays and values through
17 Comments and the order of keys are preserved. Comments can be modified
18 and can be written to the output.
20 The properties library supports both ISO-8859-1 and UTF-8 encoded data.
22 Starting from version 1.3.0 the behavior of the MustXXX() functions is
23 configurable by providing a custom `ErrorHandler` function. The default has
24 changed from `panic` to `log.Fatal` but this is configurable and custom
25 error handling functions can be provided. See the package documentation for
28 Read the full documentation on [GoDoc](https://godoc.org/github.com/magiconair/properties) [![GoDoc](https://godoc.org/github.com/magiconair/properties?status.png)](https://godoc.org/github.com/magiconair/properties)
36 "github.com/magiconair/properties"
41 p := properties.MustLoadFile("${HOME}/config.properties", properties.UTF8)
44 p = properties.MustLoadFiles([]string{
45 "${HOME}/config.properties",
46 "${HOME}/config-${USER}.properties",
47 }, properties.UTF8, true)
50 p = properties.LoadMap(map[string]string{"key": "value", "abc": "def"})
53 p = properties.MustLoadString("key=value\nabc=def")
56 p = properties.MustLoadURL("http://host/path")
58 // or from multiple URLs
59 p = properties.MustLoadURL([]string{
61 "http://host/config-${USER}",
65 p.MustFlag(flag.CommandLine)
67 // get values through getters
68 host := p.MustGetString("host")
69 port := p.GetInt("port", 8080)
73 Host string `properties:"host"`
74 Port int `properties:"port,default=9000"`
75 Accept []string `properties:"accept,default=image/png;image;gif"`
76 Timeout time.Duration `properties:"timeout,default=5s"`
79 if err := p.Decode(&cfg); err != nil {
86 Installation and Upgrade
87 ------------------------
90 $ go get -u github.com/magiconair/properties
96 2 clause BSD license. See [LICENSE](https://github.com/magiconair/properties/blob/master/LICENSE) file for details.
100 * Dump contents with passwords and secrets obscured