-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat:error returning connection in provider method #212
Conversation
Can you also update the instances in https://github.com/knadh/koanf/blob/master/examples/complex-etcd/main.go? |
This instance has been modified |
feat:error returning connection in provider method feat: modify etcd provider example
I think it's best if we pass this etcd config also to the provider config. Otherwise, we're rendering many etcd config options inaccessible.
|
type Etcd struct {
client *clientv3.Client
cfg Config
} The configuration information is already stored in this structure // /providers/etcd/etcd.go
func (e *Etcd) getConf(){
eps := e.cfg.Endpoints
dt := e.cfg.DialTimeout
fmt.Println(eps)
fmt.Println(dt)
} |
|
Maybe, can also consider embedding diff --git a/providers/etcd/etcd.go b/providers/etcd/etcd.go
index c75da16..db6f3b9 100644
--- a/providers/etcd/etcd.go
+++ b/providers/etcd/etcd.go
@@ -3,18 +3,11 @@ package etcd
import (
"context"
"errors"
- "time"
clientv3 "go.etcd.io/etcd/client/v3"
)
type Config struct {
- // etcd endpoints
- Endpoints []string
-
- // timeout
- DialTimeout time.Duration
-
// prefix request option
Prefix bool
@@ -26,6 +19,8 @@ type Config struct {
// key, key with prefix, etc.
Key string
+
+ clientv3.Config
}
// Etcd implements the etcd config provider.
@@ -36,12 +31,7 @@ type Etcd struct {
// Provider returns a provider that takes etcd config.
func Provider(cfg Config) *Etcd {
- eCfg := clientv3.Config{
- Endpoints: cfg.Endpoints,
- DialTimeout: cfg.DialTimeout,
- }
-
- c, err := clientv3.New(eCfg)
+ c, err := clientv3.New(cfg.Config)
if err != nil {
return nil
} |
Sorry, I didn't understand your meaning before. I have made modifications |
#210
As @jxsl13 says here, it is necessary to return error in the Provider method. this allows the caller to know the reason for the connection failure