This repository has been archived by the owner on May 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
doc.go
78 lines (75 loc) · 2.89 KB
/
doc.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Package configo provides flexible configurtion for go applications
// from any number of 'sources', each of which implement the Source interface
// also provided by this package.
//
// Sources provided in this package:
//
// - JSONSource (key/value pairs in JSON content)
// - EnvironmentSource (key/value pairs from the environment)
// - CLISource (key/value pairs via command line flags)
// - DefaultSource (key/value pairs manually configured by the application)
// - ConditionalSource (filters key/value retrieval based on a condition)
//
// These basic sources have been composed into additional sources, made
// available via the following constructor methods:
//
// - FromDefaultCLIConfigFileSource()
// - FromCLIConfigFileSource(path string)
// - etc...
//
// Any of these sources may be provided to a Reader which is then used to
// retrieve configuration values based on keys contained in the sources.
//
// The reader can fetch values of various types:
//
// func (*Reader) Strings(key string) []string
// func (*Reader) String(key string) string
// func (*Reader) Ints(key string) []int
// func (*Reader) Int(key string) int
// func (*Reader) Bool(key string) bool
// func (*Reader) URLs(key string) []net.url.URL
// func (*Reader) URL(key string) net.url.URL
//
// For each of the types returned above there are different ways to handle
// the scenario when a key is not found. I'll illustrate this with the
// applicable Int functions (but similar methods are implemented for each
// returned type):
//
// // returns zero value if key not found or values are malformed.
// func (*Reader) Int(key string) int
//
// // returns the value or the specified default if the key is not found.
// func (*Reader) IntDefault(key string, Default int) int
//
// // returns 0 and an error if key not found or values are malformed.
// func (*Reader) IntError(key string) (int, error)
//
// // returns the value or panics if the key is not found or the values are malformed.
// func (*Reader) IntPanic(key string) int
//
// // returns the value or calls log.Fatal() if the key is not found or the values are malformed.
// func (*Reader) IntFatal(key string) int
//
// Here's a full example:
//
// reader := configo.NewReader(
// configo.FromDefaultCLIConfigFileSource(),
// configo.FromCLI(
// configo.Flag("s3-storage-address", "The address of the s3 bucket"),
// ),
// configo.FromOptionalJSONFile("config-prod.json"),
// )
// value := reader.URL("s3-storage-address")
package configo
import "os"
// A few useful Date/Time stamp formats:
const (
DateFormat = "2006-01-02"
TimeFormat = "15:04:05"
DateTimeFormat = DateFormat + " " + TimeFormat
)
// Hostname returns os.Hostname (ignoring any error).
func Hostname() (hostname string) {
hostname, _ = os.Hostname()
return hostname
}