finish the global lock init

This commit is contained in:
Lunny Xiao 2024-08-26 10:26:24 -07:00
parent 35daeceb04
commit fe9efa90f8
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A

View File

@ -6,14 +6,22 @@ package globallock
import (
"context"
"sync"
"code.gitea.io/gitea/modules/setting"
)
var (
defaultLocker Locker
initOnce sync.Once
initFunc = func() {
// TODO: read the setting and initialize the default locker.
// Before implementing this, don't use it.
switch setting.GlobalLock.ServiceType {
case "redis":
defaultLocker = NewRedisLocker(setting.GlobalLock.ServiceConnStr)
case "memory":
fallthrough
default:
defaultLocker = NewMemoryLocker()
}
} // define initFunc as a variable to make it possible to change it in tests
)