File tree Expand file tree Collapse file tree 4 files changed +35
-8
lines changed Expand file tree Collapse file tree 4 files changed +35
-8
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,13 @@ import (
1010// DataSourceApollo defines apollo scheme
1111const 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" )
Original file line number Diff line number Diff line change @@ -12,7 +12,13 @@ import (
1212// DataSourceEtcd defines etcd scheme
1313const 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" )
Original file line number Diff line number Diff line change @@ -8,7 +8,13 @@ import (
88// DataSourceFile defines file scheme
99const 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" )
Original file line number Diff line number Diff line change @@ -23,16 +23,25 @@ var (
2323// DataSourceCreatorFunc represents a dataSource creator function
2424type DataSourceCreatorFunc func () xcfg.DataSource
2525
26+ type DataSource interface {
27+ Register () (string , func () xcfg.DataSource )
28+ }
29+
2630func 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 ..
You can’t perform that action at this time.
0 commit comments