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

..03-May-2022-

assert/H15-May-2018-

.gitignoreH A D15-May-201863

.travis.ymlH A D15-May-2018114

CHANGELOG.mdH A D15-May-20187.8 KiB

LICENSEH A D15-May-20181.3 KiB

README.mdH A D15-May-20184.3 KiB

benchmark_test.goH A D15-May-2018555

decode.goH A D15-May-20188.4 KiB

decode_test.goH A D15-May-20186.4 KiB

doc.goH A D15-May-20185 KiB

example_test.goH A D15-May-20182 KiB

integrate.goH A D15-May-2018781

integrate_test.goH A D15-May-20181.8 KiB

lex.goH A D15-May-20188.9 KiB

load.goH A D15-May-20189.2 KiB

load_test.goH A D15-May-20186.4 KiB

parser.goH A D15-May-20181.9 KiB

properties.goH A D15-May-201822.3 KiB

properties_test.goH A D15-May-201830.2 KiB

rangecheck.goH A D15-May-2018838

README.md

1[![](https://img.shields.io/github/tag/magiconair/properties.svg?style=flat-square&label=release)](https://github.com/magiconair/properties/releases)
2[![Travis CI Status](https://img.shields.io/travis/magiconair/properties.svg?branch=master&style=flat-square&label=travis)](https://travis-ci.org/magiconair/properties)
3[![Codeship CI Status](https://img.shields.io/codeship/16aaf660-f615-0135-b8f0-7e33b70920c0/master.svg?label=codeship&style=flat-square)](https://app.codeship.com/projects/274177")
4[![License](https://img.shields.io/badge/License-BSD%202--Clause-orange.svg?style=flat-square)](https://raw.githubusercontent.com/magiconair/properties/master/LICENSE)
5[![GoDoc](http://img.shields.io/badge/godoc-reference-5272B4.svg?style=flat-square)](http://godoc.org/github.com/magiconair/properties)
6
7# Overview
8
9#### Please run `git pull --tags` to update the tags. See [below](#updated-git-tags) why.
10
11properties is a Go library for reading and writing properties files.
12
13It supports reading from multiple files or URLs and Spring style recursive
14property expansion of expressions like `${key}` to their corresponding value.
15Value expressions can refer to other keys like in `${key}` or to environment
16variables like in `${USER}`.  Filenames can also contain environment variables
17like in `/home/${USER}/myapp.properties`.
18
19Properties can be decoded into structs, maps, arrays and values through
20struct tags.
21
22Comments and the order of keys are preserved. Comments can be modified
23and can be written to the output.
24
25The properties library supports both ISO-8859-1 and UTF-8 encoded data.
26
27Starting from version 1.3.0 the behavior of the MustXXX() functions is
28configurable by providing a custom `ErrorHandler` function. The default has
29changed from `panic` to `log.Fatal` but this is configurable and custom
30error handling functions can be provided. See the package documentation for
31details.
32
33Read 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)
34
35## Getting Started
36
37```go
38import (
39	"flag"
40	"github.com/magiconair/properties"
41)
42
43func main() {
44	// init from a file
45	p := properties.MustLoadFile("${HOME}/config.properties", properties.UTF8)
46
47	// or multiple files
48	p = properties.MustLoadFiles([]string{
49			"${HOME}/config.properties",
50			"${HOME}/config-${USER}.properties",
51		}, properties.UTF8, true)
52
53	// or from a map
54	p = properties.LoadMap(map[string]string{"key": "value", "abc": "def"})
55
56	// or from a string
57	p = properties.MustLoadString("key=value\nabc=def")
58
59	// or from a URL
60	p = properties.MustLoadURL("http://host/path")
61
62	// or from multiple URLs
63	p = properties.MustLoadURL([]string{
64			"http://host/config",
65			"http://host/config-${USER}",
66		}, true)
67
68	// or from flags
69	p.MustFlag(flag.CommandLine)
70
71	// get values through getters
72	host := p.MustGetString("host")
73	port := p.GetInt("port", 8080)
74
75	// or through Decode
76	type Config struct {
77		Host    string        `properties:"host"`
78		Port    int           `properties:"port,default=9000"`
79		Accept  []string      `properties:"accept,default=image/png;image;gif"`
80		Timeout time.Duration `properties:"timeout,default=5s"`
81	}
82	var cfg Config
83	if err := p.Decode(&cfg); err != nil {
84		log.Fatal(err)
85	}
86}
87
88```
89
90## Installation and Upgrade
91
92```
93$ go get -u github.com/magiconair/properties
94```
95
96## License
97
982 clause BSD license. See [LICENSE](https://github.com/magiconair/properties/blob/master/LICENSE) file for details.
99
100## ToDo
101
102* Dump contents with passwords and secrets obscured
103
104## Updated Git tags
105
106#### 13 Feb 2018
107
108I realized that all of the git tags I had pushed before v1.7.5 were lightweight tags
109and I've only recently learned that this doesn't play well with `git describe` ��
110
111I have replaced all lightweight tags with signed tags using this script which should
112retain the commit date, name and email address. Please run `git pull --tags` to update them.
113
114Worst case you have to reclone the repo.
115
116```shell
117#!/bin/bash
118tag=$1
119echo "Updating $tag"
120date=$(git show ${tag}^0 --format=%aD | head -1)
121email=$(git show ${tag}^0 --format=%aE | head -1)
122name=$(git show ${tag}^0 --format=%aN | head -1)
123GIT_COMMITTER_DATE="$date" GIT_COMMITTER_NAME="$name" GIT_COMMITTER_EMAIL="$email" git tag -s -f ${tag} ${tag}^0 -m ${tag}
124```
125
126I apologize for the inconvenience.
127
128Frank
129
130