Skip to content

Commit a5e269c

Browse files
author
myxy99
committed
file
1 parent 9b95a90 commit a5e269c

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

datasource/apollo/register.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ import (
1010
// DataSourceApollo defines apollo scheme
1111
const DataSourceApollo = "apollo"
1212

13-
func Register() (string, func() xcfg.DataSource) {
13+
type apollo struct{}
14+
15+
func New() *apollo {
16+
return new(apollo)
17+
}
18+
19+
func (e apollo) Register() (string, func() xcfg.DataSource) {
1420
return DataSourceApollo, func() xcfg.DataSource {
1521
var (
1622
configAddr = xflag.String("xcfg")

datasource/etcdv3/register.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ import (
1212
// DataSourceEtcd defines etcd scheme
1313
const DataSourceEtcd = "etcd"
1414

15-
func Register() (string, func() xcfg.DataSource) {
15+
type etcd struct{}
16+
17+
func New() *etcd {
18+
return new(etcd)
19+
}
20+
21+
func (e etcd) Register() (string, func() xcfg.DataSource) {
1622
return DataSourceEtcd, func() xcfg.DataSource {
1723
var (
1824
configAddr = xflag.String("xcfg")

datasource/file/register.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import (
88
// DataSourceFile defines file scheme
99
const DataSourceFile = "file"
1010

11-
func Register() (string, func() xcfg.DataSource) {
11+
type file struct{}
12+
13+
func New() *file {
14+
return new(file)
15+
}
16+
17+
func (f file) Register() (string, func() xcfg.DataSource) {
1218
return DataSourceFile, func() xcfg.DataSource {
1319
var (
1420
configAddr = xflag.String("xcfg")

datasource/manager/manager.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,25 @@ var (
2323
// DataSourceCreatorFunc represents a dataSource creator function
2424
type DataSourceCreatorFunc func() xcfg.DataSource
2525

26+
type DataSource interface {
27+
Register() (string, func() xcfg.DataSource)
28+
}
29+
2630
func init() {
2731
registry = make(map[string]DataSourceCreatorFunc)
28-
Register(file.Register())
29-
Register(etcdv3.Register())
30-
Register(apollo.Register())
32+
Register(
33+
file.New(),
34+
etcdv3.New(),
35+
apollo.New(),
36+
)
3137
}
3238

3339
// Register registers a dataSource creator function to the registry
34-
func Register(scheme string, creator DataSourceCreatorFunc) {
35-
registry[scheme] = creator
40+
func Register(data ...DataSource) {
41+
for _, datum := range data {
42+
name, f := datum.Register()
43+
registry[name] = f
44+
}
3645
}
3746

3847
//NewDataSource ..

0 commit comments

Comments
 (0)