• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

assert/H21-Mar-2017-147110

.gitignoreH A D21-Mar-201763 76

.travis.ymlH A D21-Mar-201787 98

CHANGELOG.mdH A D21-Mar-20176.2 KiB9758

LICENSEH A D21-Mar-20171.3 KiB2620

README.mdH A D21-Mar-20172.9 KiB10175

benchmark_test.goH A D21-Mar-2017555 2517

decode.goH A D21-Mar-20178.4 KiB290174

decode_test.goH A D21-Mar-20176.4 KiB300285

doc.goH A D21-Mar-20175 KiB1571

example_test.goH A D21-Mar-20172 KiB9452

integrate.goH A D21-Mar-2017781 3520

integrate_test.goH A D21-Mar-20171.8 KiB7754

lex.goH A D21-Mar-20178.9 KiB409284

load.goH A D21-Mar-20177.4 KiB242160

load_test.goH A D21-Mar-20176.1 KiB232186

parser.goH A D21-Mar-20171.9 KiB9678

properties.goH A D21-Mar-201721.8 KiB809528

properties_test.goH A D21-Mar-201728.6 KiB935733

rangecheck.goH A D21-Mar-2017838 3218

README.md

1Overview [![Build Status](https://travis-ci.org/magiconair/properties.svg?branch=master)](https://travis-ci.org/magiconair/properties)
2========
3
4#### Current version: 1.7.2
5
6properties is a Go library for reading and writing properties files.
7
8It supports reading from multiple files or URLs and Spring style recursive
9property expansion of expressions like `${key}` to their corresponding value.
10Value expressions can refer to other keys like in `${key}` or to environment
11variables like in `${USER}`.  Filenames can also contain environment variables
12like in `/home/${USER}/myapp.properties`.
13
14Properties can be decoded into structs, maps, arrays and values through
15struct tags.
16
17Comments and the order of keys are preserved. Comments can be modified
18and can be written to the output.
19
20The properties library supports both ISO-8859-1 and UTF-8 encoded data.
21
22Starting from version 1.3.0 the behavior of the MustXXX() functions is
23configurable by providing a custom `ErrorHandler` function. The default has
24changed from `panic` to `log.Fatal` but this is configurable and custom
25error handling functions can be provided. See the package documentation for
26details.
27
28Read 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)
29
30Getting Started
31---------------
32
33```go
34import (
35	"flag"
36	"github.com/magiconair/properties"
37)
38
39func main() {
40	// init from a file
41	p := properties.MustLoadFile("${HOME}/config.properties", properties.UTF8)
42
43	// or multiple files
44	p = properties.MustLoadFiles([]string{
45			"${HOME}/config.properties",
46			"${HOME}/config-${USER}.properties",
47		}, properties.UTF8, true)
48
49	// or from a map
50	p = properties.LoadMap(map[string]string{"key": "value", "abc": "def"})
51
52	// or from a string
53	p = properties.MustLoadString("key=value\nabc=def")
54
55	// or from a URL
56	p = properties.MustLoadURL("http://host/path")
57
58	// or from multiple URLs
59	p = properties.MustLoadURL([]string{
60			"http://host/config",
61			"http://host/config-${USER}",
62		}, true)
63
64	// or from flags
65	p.MustFlag(flag.CommandLine)
66
67	// get values through getters
68	host := p.MustGetString("host")
69	port := p.GetInt("port", 8080)
70
71	// or through Decode
72	type Config struct {
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"`
77	}
78	var cfg Config
79	if err := p.Decode(&cfg); err != nil {
80		log.Fatal(err)
81	}
82}
83
84```
85
86Installation and Upgrade
87------------------------
88
89```
90$ go get -u github.com/magiconair/properties
91```
92
93License
94-------
95
962 clause BSD license. See [LICENSE](https://github.com/magiconair/properties/blob/master/LICENSE) file for details.
97
98ToDo
99----
100* Dump contents with passwords and secrets obscured
101