aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/go-ini
diff options
context:
space:
mode:
authorAlex Pilon <apilon@hashicorp.com>2019-02-22 18:24:37 -0500
committerAlex Pilon <apilon@hashicorp.com>2019-02-22 18:24:37 -0500
commit15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (patch)
tree255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/go-ini
parent07971ca38143c5faf951d152fba370ddcbe26ad5 (diff)
downloadterraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.gz
terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.zst
terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.zip
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
Updated via: go get github.com/hashicorp/terraform@sdk-v0.11-with-go-modules and go mod tidy
Diffstat (limited to 'vendor/github.com/go-ini')
-rw-r--r--vendor/github.com/go-ini/ini/.travis.yml13
-rw-r--r--vendor/github.com/go-ini/ini/README.md8
-rw-r--r--vendor/github.com/go-ini/ini/README_ZH.md6
-rw-r--r--vendor/github.com/go-ini/ini/ini.go54
-rw-r--r--vendor/github.com/go-ini/ini/key.go104
-rw-r--r--vendor/github.com/go-ini/ini/parser.go14
-rw-r--r--vendor/github.com/go-ini/ini/section.go25
-rw-r--r--vendor/github.com/go-ini/ini/struct.go37
8 files changed, 196 insertions, 65 deletions
diff --git a/vendor/github.com/go-ini/ini/.travis.yml b/vendor/github.com/go-ini/ini/.travis.yml
index 0064ba1..65c872b 100644
--- a/vendor/github.com/go-ini/ini/.travis.yml
+++ b/vendor/github.com/go-ini/ini/.travis.yml
@@ -1,14 +1,15 @@
1sudo: false 1sudo: false
2language: go 2language: go
3
4go: 3go:
5 - 1.4 4 - 1.4.x
6 - 1.5 5 - 1.5.x
7 - 1.6 6 - 1.6.x
8 - tip 7 - 1.7.x
8 - master
9 9
10script: 10script:
11 - go get -v github.com/smartystreets/goconvey 11 - go get golang.org/x/tools/cmd/cover
12 - go get github.com/smartystreets/goconvey
12 - go test -v -cover -race 13 - go test -v -cover -race
13 14
14notifications: 15notifications:
diff --git a/vendor/github.com/go-ini/ini/README.md b/vendor/github.com/go-ini/ini/README.md
index 22a4234..8594742 100644
--- a/vendor/github.com/go-ini/ini/README.md
+++ b/vendor/github.com/go-ini/ini/README.md
@@ -1,4 +1,4 @@
1INI [![Build Status](https://travis-ci.org/go-ini/ini.svg?branch=master)](https://travis-ci.org/go-ini/ini) 1INI [![Build Status](https://travis-ci.org/go-ini/ini.svg?branch=master)](https://travis-ci.org/go-ini/ini) [![Sourcegraph](https://sourcegraph.com/github.com/go-ini/ini/-/badge.svg)](https://sourcegraph.com/github.com/go-ini/ini?badge)
2=== 2===
3 3
4![](https://avatars0.githubusercontent.com/u/10216035?v=3&s=200) 4![](https://avatars0.githubusercontent.com/u/10216035?v=3&s=200)
@@ -106,6 +106,12 @@ cfg, err := LoadSources(LoadOptions{AllowBooleanKeys: true}, "my.cnf"))
106 106
107The value of those keys are always `true`, and when you save to a file, it will keep in the same foramt as you read. 107The value of those keys are always `true`, and when you save to a file, it will keep in the same foramt as you read.
108 108
109To generate such keys in your program, you could use `NewBooleanKey`:
110
111```go
112key, err := sec.NewBooleanKey("skip-host-cache")
113```
114
109#### Comment 115#### Comment
110 116
111Take care that following format will be treated as comment: 117Take care that following format will be treated as comment:
diff --git a/vendor/github.com/go-ini/ini/README_ZH.md b/vendor/github.com/go-ini/ini/README_ZH.md
index 3b4fb66..163432d 100644
--- a/vendor/github.com/go-ini/ini/README_ZH.md
+++ b/vendor/github.com/go-ini/ini/README_ZH.md
@@ -99,6 +99,12 @@ cfg, err := LoadSources(LoadOptions{AllowBooleanKeys: true}, "my.cnf"))
99 99
100这些键的值永远为 `true`,且在保存到文件时也只会输出键名。 100这些键的值永远为 `true`,且在保存到文件时也只会输出键名。
101 101
102如果您想要通过程序来生成此类键,则可以使用 `NewBooleanKey`:
103
104```go
105key, err := sec.NewBooleanKey("skip-host-cache")
106```
107
102#### 关于注释 108#### 关于注释
103 109
104下述几种情况的内容将被视为注释: 110下述几种情况的内容将被视为注释:
diff --git a/vendor/github.com/go-ini/ini/ini.go b/vendor/github.com/go-ini/ini/ini.go
index 77e0dbd..68d73aa 100644
--- a/vendor/github.com/go-ini/ini/ini.go
+++ b/vendor/github.com/go-ini/ini/ini.go
@@ -37,7 +37,7 @@ const (
37 37
38 // Maximum allowed depth when recursively substituing variable names. 38 // Maximum allowed depth when recursively substituing variable names.
39 _DEPTH_VALUES = 99 39 _DEPTH_VALUES = 99
40 _VERSION = "1.23.1" 40 _VERSION = "1.25.4"
41) 41)
42 42
43// Version returns current package version literal. 43// Version returns current package version literal.
@@ -176,6 +176,8 @@ type LoadOptions struct {
176 // AllowBooleanKeys indicates whether to allow boolean type keys or treat as value is missing. 176 // AllowBooleanKeys indicates whether to allow boolean type keys or treat as value is missing.
177 // This type of keys are mostly used in my.cnf. 177 // This type of keys are mostly used in my.cnf.
178 AllowBooleanKeys bool 178 AllowBooleanKeys bool
179 // AllowShadows indicates whether to keep track of keys with same name under same section.
180 AllowShadows bool
179 // Some INI formats allow group blocks that store a block of raw content that doesn't otherwise 181 // Some INI formats allow group blocks that store a block of raw content that doesn't otherwise
180 // conform to key/value pairs. Specify the names of those blocks here. 182 // conform to key/value pairs. Specify the names of those blocks here.
181 UnparseableSections []string 183 UnparseableSections []string
@@ -219,6 +221,12 @@ func InsensitiveLoad(source interface{}, others ...interface{}) (*File, error) {
219 return LoadSources(LoadOptions{Insensitive: true}, source, others...) 221 return LoadSources(LoadOptions{Insensitive: true}, source, others...)
220} 222}
221 223
224// InsensitiveLoad has exactly same functionality as Load function
225// except it allows have shadow keys.
226func ShadowLoad(source interface{}, others ...interface{}) (*File, error) {
227 return LoadSources(LoadOptions{AllowShadows: true}, source, others...)
228}
229
222// Empty returns an empty file object. 230// Empty returns an empty file object.
223func Empty() *File { 231func Empty() *File {
224 // Ignore error here, we sure our data is good. 232 // Ignore error here, we sure our data is good.
@@ -441,6 +449,7 @@ func (f *File) WriteToIndent(w io.Writer, indent string) (n int64, err error) {
441 } 449 }
442 alignSpaces := bytes.Repeat([]byte(" "), alignLength) 450 alignSpaces := bytes.Repeat([]byte(" "), alignLength)
443 451
452 KEY_LIST:
444 for _, kname := range sec.keyList { 453 for _, kname := range sec.keyList {
445 key := sec.Key(kname) 454 key := sec.Key(kname)
446 if len(key.Comment) > 0 { 455 if len(key.Comment) > 0 {
@@ -467,28 +476,33 @@ func (f *File) WriteToIndent(w io.Writer, indent string) (n int64, err error) {
467 case strings.Contains(kname, "`"): 476 case strings.Contains(kname, "`"):
468 kname = `"""` + kname + `"""` 477 kname = `"""` + kname + `"""`
469 } 478 }
470 if _, err = buf.WriteString(kname); err != nil {
471 return 0, err
472 }
473 479
474 if key.isBooleanType { 480 for _, val := range key.ValueWithShadows() {
475 continue 481 if _, err = buf.WriteString(kname); err != nil {
476 } 482 return 0, err
483 }
477 484
478 // Write out alignment spaces before "=" sign 485 if key.isBooleanType {
479 if PrettyFormat { 486 if kname != sec.keyList[len(sec.keyList)-1] {
480 buf.Write(alignSpaces[:alignLength-len(kname)]) 487 buf.WriteString(LineBreak)
481 } 488 }
489 continue KEY_LIST
490 }
482 491
483 val := key.value 492 // Write out alignment spaces before "=" sign
484 // In case key value contains "\n", "`", "\"", "#" or ";" 493 if PrettyFormat {
485 if strings.ContainsAny(val, "\n`") { 494 buf.Write(alignSpaces[:alignLength-len(kname)])
486 val = `"""` + val + `"""` 495 }
487 } else if strings.ContainsAny(val, "#;") { 496
488 val = "`" + val + "`" 497 // In case key value contains "\n", "`", "\"", "#" or ";"
489 } 498 if strings.ContainsAny(val, "\n`") {
490 if _, err = buf.WriteString(equalSign + val + LineBreak); err != nil { 499 val = `"""` + val + `"""`
491 return 0, err 500 } else if strings.ContainsAny(val, "#;") {
501 val = "`" + val + "`"
502 }
503 if _, err = buf.WriteString(equalSign + val + LineBreak); err != nil {
504 return 0, err
505 }
492 } 506 }
493 } 507 }
494 508
diff --git a/vendor/github.com/go-ini/ini/key.go b/vendor/github.com/go-ini/ini/key.go
index 9738c55..852696f 100644
--- a/vendor/github.com/go-ini/ini/key.go
+++ b/vendor/github.com/go-ini/ini/key.go
@@ -15,6 +15,7 @@
15package ini 15package ini
16 16
17import ( 17import (
18 "errors"
18 "fmt" 19 "fmt"
19 "strconv" 20 "strconv"
20 "strings" 21 "strings"
@@ -29,9 +30,42 @@ type Key struct {
29 isAutoIncrement bool 30 isAutoIncrement bool
30 isBooleanType bool 31 isBooleanType bool
31 32
33 isShadow bool
34 shadows []*Key
35
32 Comment string 36 Comment string
33} 37}
34 38
39// newKey simply return a key object with given values.
40func newKey(s *Section, name, val string) *Key {
41 return &Key{
42 s: s,
43 name: name,
44 value: val,
45 }
46}
47
48func (k *Key) addShadow(val string) error {
49 if k.isShadow {
50 return errors.New("cannot add shadow to another shadow key")
51 } else if k.isAutoIncrement || k.isBooleanType {
52 return errors.New("cannot add shadow to auto-increment or boolean key")
53 }
54
55 shadow := newKey(k.s, k.name, val)
56 shadow.isShadow = true
57 k.shadows = append(k.shadows, shadow)
58 return nil
59}
60
61// AddShadow adds a new shadow key to itself.
62func (k *Key) AddShadow(val string) error {
63 if !k.s.f.options.AllowShadows {
64 return errors.New("shadow key is not allowed")
65 }
66 return k.addShadow(val)
67}
68
35// ValueMapper represents a mapping function for values, e.g. os.ExpandEnv 69// ValueMapper represents a mapping function for values, e.g. os.ExpandEnv
36type ValueMapper func(string) string 70type ValueMapper func(string) string
37 71
@@ -45,16 +79,29 @@ func (k *Key) Value() string {
45 return k.value 79 return k.value
46} 80}
47 81
48// String returns string representation of value. 82// ValueWithShadows returns raw values of key and its shadows if any.
49func (k *Key) String() string { 83func (k *Key) ValueWithShadows() []string {
50 val := k.value 84 if len(k.shadows) == 0 {
85 return []string{k.value}
86 }
87 vals := make([]string, len(k.shadows)+1)
88 vals[0] = k.value
89 for i := range k.shadows {
90 vals[i+1] = k.shadows[i].value
91 }
92 return vals
93}
94
95// transformValue takes a raw value and transforms to its final string.
96func (k *Key) transformValue(val string) string {
51 if k.s.f.ValueMapper != nil { 97 if k.s.f.ValueMapper != nil {
52 val = k.s.f.ValueMapper(val) 98 val = k.s.f.ValueMapper(val)
53 } 99 }
54 if strings.Index(val, "%") == -1 { 100
101 // Fail-fast if no indicate char found for recursive value
102 if !strings.Contains(val, "%") {
55 return val 103 return val
56 } 104 }
57
58 for i := 0; i < _DEPTH_VALUES; i++ { 105 for i := 0; i < _DEPTH_VALUES; i++ {
59 vr := varPattern.FindString(val) 106 vr := varPattern.FindString(val)
60 if len(vr) == 0 { 107 if len(vr) == 0 {
@@ -78,6 +125,11 @@ func (k *Key) String() string {
78 return val 125 return val
79} 126}
80 127
128// String returns string representation of value.
129func (k *Key) String() string {
130 return k.transformValue(k.value)
131}
132
81// Validate accepts a validate function which can 133// Validate accepts a validate function which can
82// return modifed result as key value. 134// return modifed result as key value.
83func (k *Key) Validate(fn func(string) string) string { 135func (k *Key) Validate(fn func(string) string) string {
@@ -394,11 +446,31 @@ func (k *Key) Strings(delim string) []string {
394 446
395 vals := strings.Split(str, delim) 447 vals := strings.Split(str, delim)
396 for i := range vals { 448 for i := range vals {
449 // vals[i] = k.transformValue(strings.TrimSpace(vals[i]))
397 vals[i] = strings.TrimSpace(vals[i]) 450 vals[i] = strings.TrimSpace(vals[i])
398 } 451 }
399 return vals 452 return vals
400} 453}
401 454
455// StringsWithShadows returns list of string divided by given delimiter.
456// Shadows will also be appended if any.
457func (k *Key) StringsWithShadows(delim string) []string {
458 vals := k.ValueWithShadows()
459 results := make([]string, 0, len(vals)*2)
460 for i := range vals {
461 if len(vals) == 0 {
462 continue
463 }
464
465 results = append(results, strings.Split(vals[i], delim)...)
466 }
467
468 for i := range results {
469 results[i] = k.transformValue(strings.TrimSpace(results[i]))
470 }
471 return results
472}
473
402// Float64s returns list of float64 divided by given delimiter. Any invalid input will be treated as zero value. 474// Float64s returns list of float64 divided by given delimiter. Any invalid input will be treated as zero value.
403func (k *Key) Float64s(delim string) []float64 { 475func (k *Key) Float64s(delim string) []float64 {
404 vals, _ := k.getFloat64s(delim, true, false) 476 vals, _ := k.getFloat64s(delim, true, false)
@@ -407,13 +479,13 @@ func (k *Key) Float64s(delim string) []float64 {
407 479
408// Ints returns list of int divided by given delimiter. Any invalid input will be treated as zero value. 480// Ints returns list of int divided by given delimiter. Any invalid input will be treated as zero value.
409func (k *Key) Ints(delim string) []int { 481func (k *Key) Ints(delim string) []int {
410 vals, _ := k.getInts(delim, true, false) 482 vals, _ := k.parseInts(k.Strings(delim), true, false)
411 return vals 483 return vals
412} 484}
413 485
414// Int64s returns list of int64 divided by given delimiter. Any invalid input will be treated as zero value. 486// Int64s returns list of int64 divided by given delimiter. Any invalid input will be treated as zero value.
415func (k *Key) Int64s(delim string) []int64 { 487func (k *Key) Int64s(delim string) []int64 {
416 vals, _ := k.getInt64s(delim, true, false) 488 vals, _ := k.parseInt64s(k.Strings(delim), true, false)
417 return vals 489 return vals
418} 490}
419 491
@@ -452,14 +524,14 @@ func (k *Key) ValidFloat64s(delim string) []float64 {
452// ValidInts returns list of int divided by given delimiter. If some value is not integer, then it will 524// ValidInts returns list of int divided by given delimiter. If some value is not integer, then it will
453// not be included to result list. 525// not be included to result list.
454func (k *Key) ValidInts(delim string) []int { 526func (k *Key) ValidInts(delim string) []int {
455 vals, _ := k.getInts(delim, false, false) 527 vals, _ := k.parseInts(k.Strings(delim), false, false)
456 return vals 528 return vals
457} 529}
458 530
459// ValidInt64s returns list of int64 divided by given delimiter. If some value is not 64-bit integer, 531// ValidInt64s returns list of int64 divided by given delimiter. If some value is not 64-bit integer,
460// then it will not be included to result list. 532// then it will not be included to result list.
461func (k *Key) ValidInt64s(delim string) []int64 { 533func (k *Key) ValidInt64s(delim string) []int64 {
462 vals, _ := k.getInt64s(delim, false, false) 534 vals, _ := k.parseInt64s(k.Strings(delim), false, false)
463 return vals 535 return vals
464} 536}
465 537
@@ -495,12 +567,12 @@ func (k *Key) StrictFloat64s(delim string) ([]float64, error) {
495 567
496// StrictInts returns list of int divided by given delimiter or error on first invalid input. 568// StrictInts returns list of int divided by given delimiter or error on first invalid input.
497func (k *Key) StrictInts(delim string) ([]int, error) { 569func (k *Key) StrictInts(delim string) ([]int, error) {
498 return k.getInts(delim, false, true) 570 return k.parseInts(k.Strings(delim), false, true)
499} 571}
500 572
501// StrictInt64s returns list of int64 divided by given delimiter or error on first invalid input. 573// StrictInt64s returns list of int64 divided by given delimiter or error on first invalid input.
502func (k *Key) StrictInt64s(delim string) ([]int64, error) { 574func (k *Key) StrictInt64s(delim string) ([]int64, error) {
503 return k.getInt64s(delim, false, true) 575 return k.parseInt64s(k.Strings(delim), false, true)
504} 576}
505 577
506// StrictUints returns list of uint divided by given delimiter or error on first invalid input. 578// StrictUints returns list of uint divided by given delimiter or error on first invalid input.
@@ -541,9 +613,8 @@ func (k *Key) getFloat64s(delim string, addInvalid, returnOnInvalid bool) ([]flo
541 return vals, nil 613 return vals, nil
542} 614}
543 615
544// getInts returns list of int divided by given delimiter. 616// parseInts transforms strings to ints.
545func (k *Key) getInts(delim string, addInvalid, returnOnInvalid bool) ([]int, error) { 617func (k *Key) parseInts(strs []string, addInvalid, returnOnInvalid bool) ([]int, error) {
546 strs := k.Strings(delim)
547 vals := make([]int, 0, len(strs)) 618 vals := make([]int, 0, len(strs))
548 for _, str := range strs { 619 for _, str := range strs {
549 val, err := strconv.Atoi(str) 620 val, err := strconv.Atoi(str)
@@ -557,9 +628,8 @@ func (k *Key) getInts(delim string, addInvalid, returnOnInvalid bool) ([]int, er
557 return vals, nil 628 return vals, nil
558} 629}
559 630
560// getInt64s returns list of int64 divided by given delimiter. 631// parseInt64s transforms strings to int64s.
561func (k *Key) getInt64s(delim string, addInvalid, returnOnInvalid bool) ([]int64, error) { 632func (k *Key) parseInt64s(strs []string, addInvalid, returnOnInvalid bool) ([]int64, error) {
562 strs := k.Strings(delim)
563 vals := make([]int64, 0, len(strs)) 633 vals := make([]int64, 0, len(strs))
564 for _, str := range strs { 634 for _, str := range strs {
565 val, err := strconv.ParseInt(str, 10, 64) 635 val, err := strconv.ParseInt(str, 10, 64)
diff --git a/vendor/github.com/go-ini/ini/parser.go b/vendor/github.com/go-ini/ini/parser.go
index b0aabe3..673ef80 100644
--- a/vendor/github.com/go-ini/ini/parser.go
+++ b/vendor/github.com/go-ini/ini/parser.go
@@ -318,11 +318,14 @@ func (f *File) parse(reader io.Reader) (err error) {
318 if err != nil { 318 if err != nil {
319 // Treat as boolean key when desired, and whole line is key name. 319 // Treat as boolean key when desired, and whole line is key name.
320 if IsErrDelimiterNotFound(err) && f.options.AllowBooleanKeys { 320 if IsErrDelimiterNotFound(err) && f.options.AllowBooleanKeys {
321 key, err := section.NewKey(string(line), "true") 321 kname, err := p.readValue(line, f.options.IgnoreContinuation)
322 if err != nil {
323 return err
324 }
325 key, err := section.NewBooleanKey(kname)
322 if err != nil { 326 if err != nil {
323 return err 327 return err
324 } 328 }
325 key.isBooleanType = true
326 key.Comment = strings.TrimSpace(p.comment.String()) 329 key.Comment = strings.TrimSpace(p.comment.String())
327 p.comment.Reset() 330 p.comment.Reset()
328 continue 331 continue
@@ -338,17 +341,16 @@ func (f *File) parse(reader io.Reader) (err error) {
338 p.count++ 341 p.count++
339 } 342 }
340 343
341 key, err := section.NewKey(kname, "") 344 value, err := p.readValue(line[offset:], f.options.IgnoreContinuation)
342 if err != nil { 345 if err != nil {
343 return err 346 return err
344 } 347 }
345 key.isAutoIncrement = isAutoIncr
346 348
347 value, err := p.readValue(line[offset:], f.options.IgnoreContinuation) 349 key, err := section.NewKey(kname, value)
348 if err != nil { 350 if err != nil {
349 return err 351 return err
350 } 352 }
351 key.SetValue(value) 353 key.isAutoIncrement = isAutoIncr
352 key.Comment = strings.TrimSpace(p.comment.String()) 354 key.Comment = strings.TrimSpace(p.comment.String())
353 p.comment.Reset() 355 p.comment.Reset()
354 } 356 }
diff --git a/vendor/github.com/go-ini/ini/section.go b/vendor/github.com/go-ini/ini/section.go
index 45d2f3b..c9fa27e 100644
--- a/vendor/github.com/go-ini/ini/section.go
+++ b/vendor/github.com/go-ini/ini/section.go
@@ -68,20 +68,33 @@ func (s *Section) NewKey(name, val string) (*Key, error) {
68 } 68 }
69 69
70 if inSlice(name, s.keyList) { 70 if inSlice(name, s.keyList) {
71 s.keys[name].value = val 71 if s.f.options.AllowShadows {
72 if err := s.keys[name].addShadow(val); err != nil {
73 return nil, err
74 }
75 } else {
76 s.keys[name].value = val
77 }
72 return s.keys[name], nil 78 return s.keys[name], nil
73 } 79 }
74 80
75 s.keyList = append(s.keyList, name) 81 s.keyList = append(s.keyList, name)
76 s.keys[name] = &Key{ 82 s.keys[name] = newKey(s, name, val)
77 s: s,
78 name: name,
79 value: val,
80 }
81 s.keysHash[name] = val 83 s.keysHash[name] = val
82 return s.keys[name], nil 84 return s.keys[name], nil
83} 85}
84 86
87// NewBooleanKey creates a new boolean type key to given section.
88func (s *Section) NewBooleanKey(name string) (*Key, error) {
89 key, err := s.NewKey(name, "true")
90 if err != nil {
91 return nil, err
92 }
93
94 key.isBooleanType = true
95 return key, nil
96}
97
85// GetKey returns key in section by given name. 98// GetKey returns key in section by given name.
86func (s *Section) GetKey(name string) (*Key, error) { 99func (s *Section) GetKey(name string) (*Key, error) {
87 // FIXME: change to section level lock? 100 // FIXME: change to section level lock?
diff --git a/vendor/github.com/go-ini/ini/struct.go b/vendor/github.com/go-ini/ini/struct.go
index 5ef38d8..509c682 100644
--- a/vendor/github.com/go-ini/ini/struct.go
+++ b/vendor/github.com/go-ini/ini/struct.go
@@ -78,8 +78,14 @@ func parseDelim(actual string) string {
78var reflectTime = reflect.TypeOf(time.Now()).Kind() 78var reflectTime = reflect.TypeOf(time.Now()).Kind()
79 79
80// setSliceWithProperType sets proper values to slice based on its type. 80// setSliceWithProperType sets proper values to slice based on its type.
81func setSliceWithProperType(key *Key, field reflect.Value, delim string) error { 81func setSliceWithProperType(key *Key, field reflect.Value, delim string, allowShadow bool) error {
82 strs := key.Strings(delim) 82 var strs []string
83 if allowShadow {
84 strs = key.StringsWithShadows(delim)
85 } else {
86 strs = key.Strings(delim)
87 }
88
83 numVals := len(strs) 89 numVals := len(strs)
84 if numVals == 0 { 90 if numVals == 0 {
85 return nil 91 return nil
@@ -92,9 +98,9 @@ func setSliceWithProperType(key *Key, field reflect.Value, delim string) error {
92 case reflect.String: 98 case reflect.String:
93 vals = strs 99 vals = strs
94 case reflect.Int: 100 case reflect.Int:
95 vals = key.Ints(delim) 101 vals, _ = key.parseInts(strs, true, false)
96 case reflect.Int64: 102 case reflect.Int64:
97 vals = key.Int64s(delim) 103 vals, _ = key.parseInt64s(strs, true, false)
98 case reflect.Uint: 104 case reflect.Uint:
99 vals = key.Uints(delim) 105 vals = key.Uints(delim)
100 case reflect.Uint64: 106 case reflect.Uint64:
@@ -133,7 +139,7 @@ func setSliceWithProperType(key *Key, field reflect.Value, delim string) error {
133// setWithProperType sets proper value to field based on its type, 139// setWithProperType sets proper value to field based on its type,
134// but it does not return error for failing parsing, 140// but it does not return error for failing parsing,
135// because we want to use default value that is already assigned to strcut. 141// because we want to use default value that is already assigned to strcut.
136func setWithProperType(t reflect.Type, key *Key, field reflect.Value, delim string) error { 142func setWithProperType(t reflect.Type, key *Key, field reflect.Value, delim string, allowShadow bool) error {
137 switch t.Kind() { 143 switch t.Kind() {
138 case reflect.String: 144 case reflect.String:
139 if len(key.String()) == 0 { 145 if len(key.String()) == 0 {
@@ -187,13 +193,25 @@ func setWithProperType(t reflect.Type, key *Key, field reflect.Value, delim stri
187 } 193 }
188 field.Set(reflect.ValueOf(timeVal)) 194 field.Set(reflect.ValueOf(timeVal))
189 case reflect.Slice: 195 case reflect.Slice:
190 return setSliceWithProperType(key, field, delim) 196 return setSliceWithProperType(key, field, delim, allowShadow)
191 default: 197 default:
192 return fmt.Errorf("unsupported type '%s'", t) 198 return fmt.Errorf("unsupported type '%s'", t)
193 } 199 }
194 return nil 200 return nil
195} 201}
196 202
203func parseTagOptions(tag string) (rawName string, omitEmpty bool, allowShadow bool) {
204 opts := strings.SplitN(tag, ",", 3)
205 rawName = opts[0]
206 if len(opts) > 1 {
207 omitEmpty = opts[1] == "omitempty"
208 }
209 if len(opts) > 2 {
210 allowShadow = opts[2] == "allowshadow"
211 }
212 return rawName, omitEmpty, allowShadow
213}
214
197func (s *Section) mapTo(val reflect.Value) error { 215func (s *Section) mapTo(val reflect.Value) error {
198 if val.Kind() == reflect.Ptr { 216 if val.Kind() == reflect.Ptr {
199 val = val.Elem() 217 val = val.Elem()
@@ -209,8 +227,8 @@ func (s *Section) mapTo(val reflect.Value) error {
209 continue 227 continue
210 } 228 }
211 229
212 opts := strings.SplitN(tag, ",", 2) // strip off possible omitempty 230 rawName, _, allowShadow := parseTagOptions(tag)
213 fieldName := s.parseFieldName(tpField.Name, opts[0]) 231 fieldName := s.parseFieldName(tpField.Name, rawName)
214 if len(fieldName) == 0 || !field.CanSet() { 232 if len(fieldName) == 0 || !field.CanSet() {
215 continue 233 continue
216 } 234 }
@@ -231,7 +249,8 @@ func (s *Section) mapTo(val reflect.Value) error {
231 } 249 }
232 250
233 if key, err := s.GetKey(fieldName); err == nil { 251 if key, err := s.GetKey(fieldName); err == nil {
234 if err = setWithProperType(tpField.Type, key, field, parseDelim(tpField.Tag.Get("delim"))); err != nil { 252 delim := parseDelim(tpField.Tag.Get("delim"))
253 if err = setWithProperType(tpField.Type, key, field, delim, allowShadow); err != nil {
235 return fmt.Errorf("error mapping field(%s): %v", fieldName, err) 254 return fmt.Errorf("error mapping field(%s): %v", fieldName, err)
236 } 255 }
237 } 256 }