Documentation ¶
Overview ¶
Package goproperties implements read operations on .properties file.
.properties is a file extension for files mainly used in Java related technologies to store the configurable parameters of an application. They can also be used for storing strings for Internationalization and localization; these are known as Property Resource Bundles.
Each parameter is stored as a pair of strings, one storing the name of the parameter (called the key), and the other storing the value.
Each line in a .properties file normally stores a single property. Several formats are possible for each line, including key=value, key = value, key:value, and key value.
.properties files can use the number sign (#) or the exclamation mark (!) as the first non blank character in a line to denote that all text following it is a comment. The backwards slash is used to escape a character. An example of a properties file is provided below.
# You are reading the ".properties" entry. ! The exclamation mark can also mark text as comments. website = http://en.wikipedia.org/ language = English # The backslash below tells the application to continue reading # the value onto the next line. message = Welcome to \ Wikipedia! # Add spaces to the key key\ with\ spaces = This is the value that could be looked up with the \ key "key with spaces". # Empty lines are skipped # Unicode unicode=\u041f\u0440\u0438\u0432\u0435\u0442, \u0421\u043e\u0432\u0430! # Comment
In the example above, website would be a key, and its corresponding value would be http://en.wikipedia.org/. While the number sign and the exclamation mark marks text as comments, it has no effect when it is part of a property. Thus, the key message has the value Welcome to Wikipedia! and not Welcome to Wikipedia. Note also that all of the whitespace in front of Wikipedia! is excluded completely.
The encoding of a .properties file is ISO-8859-1, also known as Latin-1. All non-Latin-1 characters must be entered by using Unicode escape characters, e. g. \uHHHH where HHHH is a hexadecimal index of the character in the Unicode character set. This allows for using .properties files as resource bundles for localization. A non-Latin-1 text file can be converted to a correct .properties file by using the native2ascii tool that is shipped with the JDK or by using a tool, such as po2prop, that manages the transformation from a bilingual localization format into .properties escaping.
From Wikipedia, the free encyclopedia http://en.wikipedia.org/wiki/.properties
Index ¶
- Variables
- type Properties
- func (p Properties) Bool(key string, def bool) bool
- func (p Properties) Float(key string, def float64) float64
- func (p Properties) Int(key string, def int64) int64
- func (p Properties) Load(src io.Reader) error
- func (p Properties) String(key string, def string) string
- func (p Properties) Uint(key string, def uint64) uint64
Constants ¶
This section is empty.
Variables ¶
var ErrMalformedUtf8Encoding error = errors.New("malformed \\uxxxx encoding")
ErrMalformedUtf8Encoding means that it was not possible to convert \uXXXX string to utf8 rune.
Functions ¶
This section is empty.
Types ¶
type Properties ¶
func Load ¶
func Load(file string) (Properties, error)
Creates an instance of Properties and try to fill it with data from file. It's safe to ignore error as method always return pointer to the created instance and close any opened resources.
func (Properties) Bool ¶
func (p Properties) Bool(key string, def bool) bool
Uses strconv to convert key's value to bool. Returns def if conversion failed or key does not exist.
func (Properties) Float ¶
func (p Properties) Float(key string, def float64) float64
Uses strconv to convert key's value to float64. Returns def if conversion failed or key does not exist.
func (Properties) Int ¶
func (p Properties) Int(key string, def int64) int64
Uses strconv to convert key's value to int64 (base is 0). Returns def if conversion failed or key does not exist.
func (Properties) Load ¶
func (p Properties) Load(src io.Reader) error
Reads key value pairs from reader and returns map[string]string If source has key already defined then existed value replaced with new one