| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package config
- import (
- "fmt"
- "git.ikuban.com/server/kratos-utils/v2/config"
- kconfig "github.com/go-kratos/kratos/v2/config"
- clientv3 "go.etcd.io/etcd/client/v3"
- )
- var _ config.Source = (*EtcdSource)(nil)
- type EtcdSource struct {
- Format config.Format
- Client *clientv3.Client
- Namespace string
- Name string
- }
- func (s *EtcdSource) NewSource() (kconfig.Source, error) {
- source, err := New(s.Client, WithPath(fmt.Sprintf("/%s/config/%s", s.Namespace, s.Name)))
- if err != nil {
- return nil, err
- }
- return source, nil
- }
- func (s *EtcdSource) Validate() bool {
- if !s.Format.Validate() {
- return false
- }
- if s.Client == nil {
- return false
- }
- if s.Namespace == "" {
- return false
- }
- if s.Name == "" {
- return false
- }
- return true
- }
- func (s *EtcdSource) String() string {
- return fmt.Sprintf("etcd source format:%v, namespace:%v, name:%v", s.Format, s.Namespace, s.Name)
- }
|