Skip to content

Commit 2959599

Browse files
ccoVeillesagikazarmark
authored andcommitted
doc: add documentation to all exported methods
1 parent 15fb405 commit 2959599

File tree

11 files changed

+164
-3
lines changed

11 files changed

+164
-3
lines changed

‎encoding.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type DecoderRegistry interface {
4949
Decoder(format string) (Decoder, error)
5050
}
5151

52-
// [CodecRegistry] combines [EncoderRegistry] and [DecoderRegistry] interfaces.
52+
// CodecRegistry combines [EncoderRegistry] and [DecoderRegistry] interfaces.
5353
type CodecRegistry interface {
5454
EncoderRegistry
5555
DecoderRegistry

‎internal/encoding/dotenv/codec.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const keyDelimiter = "_"
1515
// (commonly called as dotenv format).
1616
type Codec struct{}
1717

18+
// Encode encodes a map[string]any into a dotenv byte slice.
1819
func (Codec) Encode(v map[string]any) ([]byte, error) {
1920
flattened := map[string]any{}
2021

@@ -40,6 +41,7 @@ func (Codec) Encode(v map[string]any) ([]byte, error) {
4041
return buf.Bytes(), nil
4142
}
4243

44+
// Decode decodes a dotenv byte slice into a map[string]any.
4345
func (Codec) Decode(b []byte, v map[string]any) error {
4446
var buf bytes.Buffer
4547

‎internal/encoding/json/codec.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import (
77
// Codec implements the encoding.Encoder and encoding.Decoder interfaces for JSON encoding.
88
type Codec struct{}
99

10+
// Encode encodes a map[string]any into a JSON byte slice.
1011
func (Codec) Encode(v map[string]any) ([]byte, error) {
1112
// TODO: expose prefix and indent in the Codec as setting?
1213
return json.MarshalIndent(v, "", " ")
1314
}
1415

16+
// Decode decodes a JSON byte slice into a map[string]any.
1517
func (Codec) Decode(b []byte, v map[string]any) error {
1618
return json.Unmarshal(b, &v)
1719
}

‎internal/encoding/toml/codec.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import (
77
// Codec implements the encoding.Encoder and encoding.Decoder interfaces for TOML encoding.
88
type Codec struct{}
99

10+
// Encode encodes a map[string]any into a TOML byte slice.
1011
func (Codec) Encode(v map[string]any) ([]byte, error) {
1112
return toml.Marshal(v)
1213
}
1314

15+
// Decode decodes a TOML byte slice into a map[string]any.
1416
func (Codec) Decode(b []byte, v map[string]any) error {
1517
return toml.Unmarshal(b, &v)
1618
}

‎internal/encoding/yaml/codec.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import "go.yaml.in/yaml/v3"
55
// Codec implements the encoding.Encoder and encoding.Decoder interfaces for YAML encoding.
66
type Codec struct{}
77

8+
// Encode encodes a map[string]any into a YAML byte slice.
89
func (Codec) Encode(v map[string]any) ([]byte, error) {
910
return yaml.Marshal(v)
1011
}
1112

13+
// Decode decodes a YAML byte slice into a map[string]any.
1214
func (Codec) Decode(b []byte, v map[string]any) error {
1315
return yaml.Unmarshal(b, &v)
1416
}

‎internal/features/bind_struct.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
package features
44

5+
// BindStruct is a feature flag for enabling/disabling the config binding to structs.
56
const BindStruct = true

‎internal/features/bind_struct_default.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
package features
44

5+
// BindStruct is a feature flag for enabling/disabling the config binding to structs.
56
const BindStruct = false

‎internal/features/finder.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
package features
44

5+
// Finder is a feature flag for enabling/disabling the config finder.
56
const Finder = true

‎internal/features/finder_default.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
package features
44

5+
// Finder is a feature flag for enabling/disabling the config finder.
56
const Finder = false

‎remote.go‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type remoteConfigFactory interface {
2121
WatchChannel(rp RemoteProvider) (<-chan *RemoteResponse, chan bool)
2222
}
2323

24+
// RemoteResponse represents a response from a remote configuration provider.
2425
type RemoteResponse struct {
2526
Value []byte
2627
Error error
@@ -93,6 +94,14 @@ func AddRemoteProvider(provider, endpoint, path string) error {
9394
return v.AddRemoteProvider(provider, endpoint, path)
9495
}
9596

97+
// AddRemoteProvider adds a remote configuration source.
98+
// Remote Providers are searched in the order they are added.
99+
// provider is a string value: "etcd", "etcd3", "consul", "firestore" or "nats" are currently supported.
100+
// endpoint is the url. etcd requires http://ip:port, consul requires ip:port, nats requires nats://ip:port
101+
// path is the path in the k/v store to retrieve configuration
102+
// To retrieve a config file called myapp.json from /configs/myapp.json
103+
// you should set path to /configs and set config name (SetConfigName()) to
104+
// "myapp".
96105
func (v *Viper) AddRemoteProvider(provider, endpoint, path string) error {
97106
if !slices.Contains(SupportedRemoteProviders, provider) {
98107
return UnsupportedRemoteProviderError(provider)
@@ -126,6 +135,16 @@ func AddSecureRemoteProvider(provider, endpoint, path, secretkeyring string) err
126135
return v.AddSecureRemoteProvider(provider, endpoint, path, secretkeyring)
127136
}
128137

138+
// AddSecureRemoteProvider adds a remote configuration source.
139+
// Secure Remote Providers are searched in the order they are added.
140+
// provider is a string value: "etcd", "etcd3", "consul", "firestore" or "nats" are currently supported.
141+
// endpoint is the url. etcd requires http://ip:port consul requires ip:port
142+
// secretkeyring is the filepath to your openpgp secret keyring. e.g. /etc/secrets/myring.gpg
143+
// path is the path in the k/v store to retrieve configuration
144+
// To retrieve a config file called myapp.json from /configs/myapp.json
145+
// you should set path to /configs and set config name (SetConfigName()) to
146+
// "myapp".
147+
// Secure Remote Providers are implemented with github.com/sagikazarmark/crypt.
129148
func (v *Viper) AddSecureRemoteProvider(provider, endpoint, path, secretkeyring string) error {
130149
if !slices.Contains(SupportedRemoteProviders, provider) {
131150
return UnsupportedRemoteProviderError(provider)
@@ -159,15 +178,21 @@ func (v *Viper) providerPathExists(p *defaultRemoteProvider) bool {
159178
// and read it in the remote configuration registry.
160179
func ReadRemoteConfig() error { return v.ReadRemoteConfig() }
161180

181+
// ReadRemoteConfig attempts to get configuration from a remote source
182+
// and read it in the remote configuration registry.
162183
func (v *Viper) ReadRemoteConfig() error {
163184
return v.getKeyValueConfig()
164185
}
165186

187+
// WatchRemoteConfig updates configuration from available remote providers.
166188
func WatchRemoteConfig() error { return v.WatchRemoteConfig() }
189+
190+
// WatchRemoteConfig updates configuration from available remote providers.
167191
func (v *Viper) WatchRemoteConfig() error {
168192
return v.watchKeyValueConfig()
169193
}
170194

195+
// WatchRemoteConfigOnChannel updates configuration from available remote providers.
171196
func (v *Viper) WatchRemoteConfigOnChannel() error {
172197
return v.watchKeyValueConfigOnChannel()
173198
}

0 commit comments

Comments
 (0)