-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
360 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,51 @@ | ||
package etcd | ||
|
||
import ( | ||
"encoding/json" | ||
"sync" | ||
"time" | ||
|
||
"github.com/hlf513/go-micro-pkg/config" | ||
) | ||
|
||
type Etcd struct { | ||
// etcd 定义配置项 | ||
type etcd struct { | ||
Host []string | ||
Timeout time.Duration | ||
} | ||
|
||
// etcd 初始化 | ||
var etcd = &Etcd{} | ||
// conf 定义更新配置 | ||
type conf struct { | ||
Etcd *etcd | ||
} | ||
|
||
var ( | ||
etcdConf = &conf{} | ||
s sync.RWMutex | ||
) | ||
|
||
// GetConf 读取配置 | ||
func GetConf() *etcd { | ||
s.RLock() | ||
defer s.RUnlock() | ||
|
||
// GetEtcdConf 读取配置 | ||
func GetEtcdConf() (*Etcd, error) { | ||
if err := config.GetConfigurator().Get([]string{"etcd"}, etcd); err != nil { | ||
return nil, err | ||
return etcdConf.Etcd | ||
} | ||
|
||
// SetConf 更新配置 | ||
func SetConf(c []byte) error { | ||
s.Lock() | ||
defer s.Unlock() | ||
|
||
if c == nil { | ||
if err := config.GetConfigurator().Get([]string{"etcd"}, &etcdConf.Etcd); err != nil { | ||
return err | ||
} | ||
} else { | ||
if err := json.Unmarshal(c, etcdConf); err != nil { | ||
return err | ||
} | ||
} | ||
return etcd, nil | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,50 @@ | ||
package jaeger | ||
|
||
import "github.com/hlf513/go-micro-pkg/config" | ||
import ( | ||
"encoding/json" | ||
"sync" | ||
|
||
type Jaeger struct { | ||
"github.com/hlf513/go-micro-pkg/config" | ||
) | ||
|
||
// jaeger 定义配置项 | ||
type jaeger struct { | ||
Name string `json:"name"` | ||
Address string `json:"address"` | ||
} | ||
|
||
// j 初始化 | ||
var j = &Jaeger{} | ||
// conf 定义更新配置 | ||
type conf struct { | ||
Jaeger *jaeger | ||
} | ||
|
||
var ( | ||
jaegerConf = &conf{} | ||
s sync.RWMutex | ||
) | ||
|
||
// GetConf 读取配置 | ||
func GetConf() *jaeger { | ||
s.RLock() | ||
defer s.RUnlock() | ||
|
||
return jaegerConf.Jaeger | ||
} | ||
|
||
// SetConf 更新配置 | ||
func SetConf(c []byte) error { | ||
s.Lock() | ||
defer s.Unlock() | ||
|
||
// GetJaegerConf 读取配置 | ||
func GetJaegerConf() (*Jaeger, error) { | ||
if err := config.GetConfigurator().Get([]string{"jaeger"}, j); err != nil { | ||
return nil, err | ||
if c == nil { | ||
if err := config.GetConfigurator().Get([]string{"jaeger"}, &jaegerConf.Jaeger); err != nil { | ||
return err | ||
} | ||
} else { | ||
if err := json.Unmarshal(c, jaegerConf); err != nil { | ||
return err | ||
} | ||
} | ||
return j, nil | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.