-
Notifications
You must be signed in to change notification settings - Fork 0
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
qinhan
committed
Jan 14, 2020
1 parent
3ac9278
commit 7cf9ecc
Showing
8 changed files
with
136 additions
and
5 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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package consul | ||
|
||
import ( | ||
consulAPI "github.com/hashicorp/consul/api" | ||
"github.com/mitchellh/consulstructure" | ||
) | ||
|
||
type ConsulConfig struct { | ||
Consul *consulAPI.Config | ||
Prefix string | ||
UpdateChan chan interface{} | ||
ErrChan chan error | ||
decoder *consulstructure.Decoder | ||
} | ||
|
||
func (c *ConsulConfig) ParseConfig(cfg interface{}) { | ||
c.decoder = &consulstructure.Decoder{ | ||
Consul: consulAPI.DefaultConfig(), | ||
Target: cfg, | ||
Prefix: c.Prefix, | ||
UpdateCh: c.UpdateChan, | ||
ErrCh: c.ErrChan, | ||
} | ||
|
||
c.decoder.Run() | ||
} | ||
|
||
func (c *ConsulConfig) Close() { | ||
c.decoder.Close() | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package consul_test | ||
|
||
//import ( | ||
// "testing" | ||
// | ||
// . "helmsman/source/consul" | ||
//) | ||
// | ||
//type Config struct { | ||
// Addr string `consul:"addr"` | ||
// Path string `consul:"data_path"` | ||
//} | ||
// | ||
//func TestConsulConfig_ParseConfig(t *testing.T) { | ||
// updateChan := make(chan interface{}, 100) | ||
// errChan := make(chan error, 100) | ||
// | ||
// cc := ConsulConfig{ | ||
// Prefix: "/", | ||
// UpdateChan: updateChan, | ||
// ErrChan: errChan, | ||
// } | ||
// | ||
// go cc.ParseConfig(&Config{}) | ||
// defer cc.Close() | ||
// | ||
// select { | ||
// case c := <-updateChan: | ||
// t.Log(c) | ||
// case err := <-errChan: | ||
// t.Error(err) | ||
// } | ||
//} |
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,12 +1,11 @@ | ||
package env | ||
|
||
import ( | ||
"helmsman" | ||
"github.com/caarlos0/env" | ||
) | ||
|
||
type EnvConfig struct{} | ||
|
||
func (e *EnvConfig) ParseConfig(parser config.Parser, cfg interface{}) error { | ||
func (e *EnvConfig) ParseConfig(cfg interface{}) error { | ||
return env.Parse(cfg) | ||
} |
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