feature/etcd #5
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user