feature/etcd #5

Merged
zhangdeman merged 5 commits from feature/etcd into master 2021-11-24 00:11:59 +08:00
Showing only changes of commit c21e16138d - Show all commits

View File

@ -24,13 +24,18 @@ func LeaseOnce(ctx context.Context, key string, val string, ttl int64) error {
if ttl <= 0 {
return errors.New("lease time must be more than 0")
}
if nil == ctx {
ctx = context.TODO()
ctx = context.Background()
}
var (
resp *clientv3.LeaseGrantResponse
err error
resp *clientv3.LeaseGrantResponse
err error
cancelFunc context.CancelFunc
)
ctx, cancelFunc = context.WithCancel(ctx)
defer cancelFunc()
// 创建一个5秒的租约
if resp, err = Client.Grant(ctx, ttl); err != nil {
return errors.New("lease grant error : " + err.Error())