forked from creamdog/gonfig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgonfig.go
37 lines (31 loc) · 1.02 KB
/
gonfig.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
Package gonfig implements methods for reading config files encoded in json using path expressions and default fallback values
*/
package gonfig
import (
"fmt"
"reflect"
)
type Gonfig interface {
Get(key string, defaultValue interface{}) (interface{}, error)
GetString(key string, defaultValue interface{}) (string, error)
GetInt(key string, defaultValue interface{}) (int, error)
GetFloat(key string, defaultValue interface{}) (float64, error)
GetBool(key string, defaultValue interface{}) (bool, error)
GetAs(key string, target interface{}) error
GetArray(key string, target []interface{}) error
}
type KeyNotFoundError struct {
key string
}
func (err *KeyNotFoundError) Error() string {
return fmt.Sprintf("key not found, key: %s", err.key)
}
type UnexpectedValueTypeError struct {
key string
value interface{}
message string
}
func (err *UnexpectedValueTypeError) Error() string {
return fmt.Sprintf("%s, key: %s, value: %v (%s) %T", err.message, err.key, err.value, reflect.TypeOf(err.value).Name(), err.value)
}