Fix golint complaints.
diff --git a/doc.go b/doc.go index d0e6bd3..69cf2e8 100644 --- a/doc.go +++ b/doc.go
@@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// properties provides functions for reading and writing +// Package properties provides functions for reading and writing // ISO-8859-1 and UTF-8 encoded .properties files and has // support for recursive property expansion. //
diff --git a/lex.go b/lex.go index 1d6b532..1ae7a45 100644 --- a/lex.go +++ b/lex.go
@@ -319,7 +319,7 @@ return l.scanUnicodeLiteral() case isEOF(r): - return fmt.Errorf("Premature EOF") + return fmt.Errorf("premature EOF") // silently drop the escape character and append the rune as is default: @@ -335,7 +335,7 @@ for i := 0; i < 4; i++ { d[i] = l.next() if d[i] == eof || !strings.ContainsRune("0123456789abcdefABCDEF", d[i]) { - return fmt.Errorf("Invalid unicode literal") + return fmt.Errorf("invalid unicode literal") } }
diff --git a/load.go b/load.go index 7afd436..431d462 100644 --- a/load.go +++ b/load.go
@@ -10,10 +10,14 @@ "os" ) +// Encoding specifies encoding of the input data. type Encoding uint const ( + // UTF8 interprets the input data as UTF-8. UTF8 Encoding = 1 << iota + + // ISO_8859_1 interprets the input data as ISO-8859-1. ISO_8859_1 ) @@ -114,7 +118,7 @@ } return string(runes) default: - ErrorHandler(fmt.Errorf("Unsupported encoding %v", enc)) + ErrorHandler(fmt.Errorf("unsupported encoding %v", enc)) } panic("ErrorHandler should exit") }
diff --git a/properties.go b/properties.go index e9aca7a..b6e0d59 100644 --- a/properties.go +++ b/properties.go
@@ -26,7 +26,7 @@ // ErrorHandler is the function which handles failures of the MustXXX() // functions. The default is LogFatalHandler. -var ErrorHandler ErrorHandlerFunc = LogFatalHandler +var ErrorHandler = LogFatalHandler // LogFatalHandler handles the error by logging a fatal error and exiting. func LogFatalHandler(err error) { @@ -40,6 +40,8 @@ // ----------------------------------------------------------------------------- +// A Properties contains the key/value pairs from the properties input. +// All values are stored in unexpanded form and are expanded at runtime type Properties struct { // Pre-/Postfix for property expansion. Prefix string @@ -212,7 +214,7 @@ return v } -// GetFloat64 parses the expanded value as a float64 if the key exists. +// MustGetFloat64 parses the expanded value as a float64 if the key exists. // If key does not exist or the value cannot be parsed the function panics. func (p *Properties) MustGetFloat64(key string) float64 { v, err := p.getFloat64(key) @@ -567,7 +569,7 @@ keyStart := start + len(prefix) keyLen := strings.Index(s[keyStart:], postfix) if keyLen == -1 { - return "", fmt.Errorf("Malformed expression") + return "", fmt.Errorf("malformed expression") } end := keyStart + keyLen + len(postfix) - 1 @@ -576,7 +578,7 @@ // fmt.Printf("s:%q pp:%q start:%d end:%d keyStart:%d keyLen:%d key:%q\n", s, prefix + "..." + postfix, start, end, keyStart, keyLen, key) if _, ok := keys[key]; ok { - return "", fmt.Errorf("Circular reference") + return "", fmt.Errorf("circular reference") } val, ok := values[key] @@ -598,7 +600,7 @@ case ISO_8859_1: return encodeIso(s, special) default: - panic(fmt.Sprintf("Unsupported encoding %v", enc)) + panic(fmt.Sprintf("unsupported encoding %v", enc)) } }
diff --git a/properties_test.go b/properties_test.go index fda5b15..fee9de8 100644 --- a/properties_test.go +++ b/properties_test.go
@@ -136,19 +136,19 @@ input, msg string }{ // unicode literals - {"key\\u1 = value", "Invalid unicode literal"}, - {"key\\u12 = value", "Invalid unicode literal"}, - {"key\\u123 = value", "Invalid unicode literal"}, - {"key\\u123g = value", "Invalid unicode literal"}, - {"key\\u123", "Invalid unicode literal"}, + {"key\\u1 = value", "invalid unicode literal"}, + {"key\\u12 = value", "invalid unicode literal"}, + {"key\\u123 = value", "invalid unicode literal"}, + {"key\\u123g = value", "invalid unicode literal"}, + {"key\\u123", "invalid unicode literal"}, // circular references - {"key=${key}", "Circular reference"}, - {"key1=${key2}\nkey2=${key1}", "Circular reference"}, + {"key=${key}", "circular reference"}, + {"key1=${key2}\nkey2=${key1}", "circular reference"}, // malformed expressions - {"key=${ke", "Malformed expression"}, - {"key=valu${ke", "Malformed expression"}, + {"key=${ke", "malformed expression"}, + {"key=valu${ke", "malformed expression"}, } // ---------------------------------------------------------------------------- @@ -395,19 +395,19 @@ // TestBasic tests basic single key/value combinations with all possible // whitespace, delimiter and newline permutations. -func (l *TestSuite) TestBasic(c *C) { +func (s *TestSuite) TestBasic(c *C) { testWhitespaceAndDelimiterCombinations(c, "key", "") testWhitespaceAndDelimiterCombinations(c, "key", "value") testWhitespaceAndDelimiterCombinations(c, "key", "value ") } -func (l *TestSuite) TestComplex(c *C) { +func (s *TestSuite) TestComplex(c *C) { for _, test := range complexTests { testKeyValue(c, test[0], test[1:]...) } } -func (l *TestSuite) TestErrors(c *C) { +func (s *TestSuite) TestErrors(c *C) { for _, test := range errorTests { _, err := Load([]byte(test.input), ISO_8859_1) c.Assert(err, NotNil) @@ -415,7 +415,7 @@ } } -func (l *TestSuite) TestMustGet(c *C) { +func (s *TestSuite) TestMustGet(c *C) { input := "key = value\nkey2 = ghi" p, err := parse(input) c.Assert(err, IsNil) @@ -423,7 +423,7 @@ c.Assert(func() { p.MustGet("invalid") }, PanicMatches, "unknown property: invalid") } -func (l *TestSuite) TestGetBool(c *C) { +func (s *TestSuite) TestGetBool(c *C) { for _, test := range boolTests { p, err := parse(test.input) c.Assert(err, IsNil) @@ -432,7 +432,7 @@ } } -func (l *TestSuite) TestMustGetBool(c *C) { +func (s *TestSuite) TestMustGetBool(c *C) { input := "key = true\nkey2 = ghi" p, err := parse(input) c.Assert(err, IsNil) @@ -440,7 +440,7 @@ c.Assert(func() { p.MustGetBool("invalid") }, PanicMatches, "unknown property: invalid") } -func (l *TestSuite) TestGetDuration(c *C) { +func (s *TestSuite) TestGetDuration(c *C) { for _, test := range durationTests { p, err := parse(test.input) c.Assert(err, IsNil) @@ -449,7 +449,7 @@ } } -func (l *TestSuite) TestMustGetDuration(c *C) { +func (s *TestSuite) TestMustGetDuration(c *C) { input := "key = 123\nkey2 = ghi" p, err := parse(input) c.Assert(err, IsNil) @@ -458,7 +458,7 @@ c.Assert(func() { p.MustGetDuration("invalid") }, PanicMatches, "unknown property: invalid") } -func (l *TestSuite) TestGetFloat64(c *C) { +func (s *TestSuite) TestGetFloat64(c *C) { for _, test := range floatTests { p, err := parse(test.input) c.Assert(err, IsNil) @@ -467,7 +467,7 @@ } } -func (l *TestSuite) TestMustGetFloat64(c *C) { +func (s *TestSuite) TestMustGetFloat64(c *C) { input := "key = 123\nkey2 = ghi" p, err := parse(input) c.Assert(err, IsNil) @@ -476,7 +476,7 @@ c.Assert(func() { p.MustGetFloat64("invalid") }, PanicMatches, "unknown property: invalid") } -func (l *TestSuite) TestGetInt(c *C) { +func (s *TestSuite) TestGetInt(c *C) { for _, test := range int64Tests { p, err := parse(test.input) c.Assert(err, IsNil) @@ -485,7 +485,7 @@ } } -func (l *TestSuite) TestMustGetInt(c *C) { +func (s *TestSuite) TestMustGetInt(c *C) { input := "key = 123\nkey2 = ghi" p, err := parse(input) c.Assert(err, IsNil) @@ -494,7 +494,7 @@ c.Assert(func() { p.MustGetInt("invalid") }, PanicMatches, "unknown property: invalid") } -func (l *TestSuite) TestGetInt64(c *C) { +func (s *TestSuite) TestGetInt64(c *C) { for _, test := range int64Tests { p, err := parse(test.input) c.Assert(err, IsNil) @@ -503,7 +503,7 @@ } } -func (l *TestSuite) TestMustGetInt64(c *C) { +func (s *TestSuite) TestMustGetInt64(c *C) { input := "key = 123\nkey2 = ghi" p, err := parse(input) c.Assert(err, IsNil) @@ -512,7 +512,7 @@ c.Assert(func() { p.MustGetInt64("invalid") }, PanicMatches, "unknown property: invalid") } -func (l *TestSuite) TestGetUint(c *C) { +func (s *TestSuite) TestGetUint(c *C) { for _, test := range uint64Tests { p, err := parse(test.input) c.Assert(err, IsNil) @@ -521,7 +521,7 @@ } } -func (l *TestSuite) TestMustGetUint(c *C) { +func (s *TestSuite) TestMustGetUint(c *C) { input := "key = 123\nkey2 = ghi" p, err := parse(input) c.Assert(err, IsNil) @@ -530,7 +530,7 @@ c.Assert(func() { p.MustGetUint64("invalid") }, PanicMatches, "unknown property: invalid") } -func (l *TestSuite) TestGetUint64(c *C) { +func (s *TestSuite) TestGetUint64(c *C) { for _, test := range uint64Tests { p, err := parse(test.input) c.Assert(err, IsNil) @@ -539,7 +539,7 @@ } } -func (l *TestSuite) TestMustGetUint64(c *C) { +func (s *TestSuite) TestMustGetUint64(c *C) { input := "key = 123\nkey2 = ghi" p, err := parse(input) c.Assert(err, IsNil) @@ -548,7 +548,7 @@ c.Assert(func() { p.MustGetUint64("invalid") }, PanicMatches, "unknown property: invalid") } -func (l *TestSuite) TestGetString(c *C) { +func (s *TestSuite) TestGetString(c *C) { for _, test := range stringTests { p, err := parse(test.input) c.Assert(err, IsNil) @@ -557,7 +557,7 @@ } } -func (l *TestSuite) TestMustGetString(c *C) { +func (s *TestSuite) TestMustGetString(c *C) { input := `key = value` p, err := parse(input) c.Assert(err, IsNil) @@ -565,7 +565,7 @@ c.Assert(func() { p.MustGetString("invalid") }, PanicMatches, "unknown property: invalid") } -func (l *TestSuite) TestComment(c *C) { +func (s *TestSuite) TestComment(c *C) { for _, test := range commentTests { p, err := parse(test.input) c.Assert(err, IsNil) @@ -599,7 +599,7 @@ } } -func (l *TestSuite) TestFilter(c *C) { +func (s *TestSuite) TestFilter(c *C) { for _, test := range filterTests { p, err := parse(test.input) c.Assert(err, IsNil) @@ -620,7 +620,7 @@ } } -func (l *TestSuite) TestFilterPrefix(c *C) { +func (s *TestSuite) TestFilterPrefix(c *C) { for _, test := range filterPrefixTests { p, err := parse(test.input) c.Assert(err, IsNil) @@ -637,7 +637,7 @@ } } -func (l *TestSuite) TestKeys(c *C) { +func (s *TestSuite) TestKeys(c *C) { for _, test := range keysTests { p, err := parse(test.input) c.Assert(err, IsNil) @@ -647,7 +647,7 @@ } } -func (l *TestSuite) TestSet(c *C) { +func (s *TestSuite) TestSet(c *C) { for _, test := range setTests { p, err := parse(test.input) c.Assert(err, IsNil) @@ -666,14 +666,14 @@ } } -func (l *TestSuite) TestMustSet(c *C) { +func (s *TestSuite) TestMustSet(c *C) { input := "key=${key}" p, err := parse(input) c.Assert(err, IsNil) - c.Assert(func() { p.MustSet("key", "${key}") }, PanicMatches, "Circular reference .*") + c.Assert(func() { p.MustSet("key", "${key}") }, PanicMatches, "circular reference .*") } -func (l *TestSuite) TestWrite(c *C) { +func (s *TestSuite) TestWrite(c *C) { for _, test := range writeTests { p, err := parse(test.input) @@ -692,7 +692,7 @@ } } -func (l *TestSuite) TestWriteComment(c *C) { +func (s *TestSuite) TestWriteComment(c *C) { for _, test := range writeCommentTests { p, err := parse(test.input) @@ -711,11 +711,11 @@ } } -func (l *TestSuite) TestCustomExpansionExpression(c *C) { +func (s *TestSuite) TestCustomExpansionExpression(c *C) { testKeyValuePrePostfix(c, "*[", "]*", "key=value\nkey2=*[key]*", "key", "value", "key2", "value") } -func (l *TestSuite) TestPanicOn32BitIntOverflow(c *C) { +func (s *TestSuite) TestPanicOn32BitIntOverflow(c *C) { is32Bit = true var min, max int64 = math.MinInt32 - 1, math.MaxInt32 + 1 input := fmt.Sprintf("min=%d\nmax=%d", min, max) @@ -727,13 +727,13 @@ c.Assert(func() { p.MustGetInt("max") }, PanicMatches, ".* out of range") } -func (l *TestSuite) TestPanicOn32BitUintOverflow(c *C) { +func (s *TestSuite) TestPanicOn32BitUintOverflow(c *C) { is32Bit = true - var max uint64 = math.MaxUint32 + 1 + var max = math.MaxUint32 + 1 input := fmt.Sprintf("max=%d", max) p, err := parse(input) c.Assert(err, IsNil) - c.Assert(p.MustGetUint64("max"), Equals, max) + c.Assert(p.MustGetUint64("max"), Equals, uint64(max)) c.Assert(func() { p.MustGetUint("max") }, PanicMatches, ".* out of range") }