etcdc.go 602 B

123456789101112131415161718192021222324252627
  1. package comp
  2. import (
  3. "fmt"
  4. "git.wanbits.io/joe/franklin/protos"
  5. "git.wanbits.io/joe/kettle/etcd"
  6. "git.wanbits.io/joe/kettle/utl"
  7. "time"
  8. )
  9. var (
  10. GEtcdc *etcd.EtcdClient
  11. )
  12. func ConnectEtcd(c *protos.ConfConf) (*etcd.EtcdClient, error) {
  13. GEtcdc, err := etcd.New(c.Addrs, c.Username, c.Password, time.Duration(c.Timeout)*time.Second)
  14. return GEtcdc, err
  15. }
  16. func RegisterSelf(path string, c *protos.AppConf, val string) {
  17. fullpath := fmt.Sprintf("%s/%v", path, c.Id)
  18. leaseId, err := GEtcdc.PutWithLife(fullpath, val, 2)
  19. utl.ErrPanic(err)
  20. err = GEtcdc.KeepAlive(leaseId)
  21. utl.ErrPanic(err)
  22. }