github.com/binbinly/pkg@v0.0.11-0.20240321014439-f4fbf666eb0f/lock/lock.go (about) 1 package lock 2 3 import ( 4 "context" 5 "time" 6 7 "github.com/google/uuid" 8 ) 9 10 const ( 11 _prefix = "lock:" 12 _ttl = 30 * time.Second 13 ) 14 15 // Lock define common func 16 type Lock interface { 17 Lock(ctx context.Context) (bool, error) 18 Unlock(ctx context.Context) (bool, error) 19 } 20 21 // genToken 生成token 22 func genToken() string { 23 u, _ := uuid.NewRandom() 24 return u.String() 25 }