-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add lock warpper for resource change. #294
Conversation
common/context.go
Outdated
@@ -148,6 +149,8 @@ func PopulateFailedResponse(cc *Context, err error, abort bool) { | |||
|
|||
// HandlerFunc HandlerFunc | |||
type HandlerFunc func(c *Context) (interface{}, error) | |||
type LockFunc func(ctx context.Context, name string) (string, error) | |||
type UnlockFunc func(ctx context.Context, name, value string) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value 改成 version,好理解一些
func WrapperWithLock(lockFunc LockFunc, unlockFunc UnlockFunc) func(c *gin.Context) { | ||
return func(c *gin.Context) { | ||
cc := NewContext(c) | ||
ctx := context.Background() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不考虑给超时时间嘛?
plugin/lock.go
Outdated
|
||
// LockWithExpireTime lock the resource with expire time | ||
// PARAMS: | ||
// - name: the lock's name | ||
// - expireTime(seconds): the expire time of the lock, if acquired the lock | ||
// RETURNS: | ||
// error: if has error else nil | ||
LockWithExpireTime(name, value string, expireTime int64) error | ||
LockWithExpireTime(ctx context.Context, name string, expireTime int64) (string, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctx 来决定是否有超时时间,这俩接口留一个就行
Lock,一个接口
service/locker.go
Outdated
type LockerService interface { | ||
Lock(ctx context.Context, name string) (string, error) | ||
LockWithExpireTime(ctx context.Context, name string, expireTime int64) (string, error) | ||
Unlock(ctx context.Context, name, value string) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
Codecov Report
@@ Coverage Diff @@
## master #294 +/- ##
==========================================
- Coverage 66.46% 66.41% -0.05%
==========================================
Files 81 82 +1
Lines 5976 5982 +6
==========================================
+ Hits 3972 3973 +1
- Misses 1461 1465 +4
- Partials 543 544 +1
Continue to review full report at Codecov.
|
No description provided.