gitea源码

gloabl_lock.go 963B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2024 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package setting
  4. import (
  5. "code.gitea.io/gitea/modules/log"
  6. "code.gitea.io/gitea/modules/nosql"
  7. )
  8. // GlobalLock represents configuration of global lock
  9. var GlobalLock = struct {
  10. ServiceType string
  11. ServiceConnStr string
  12. }{
  13. ServiceType: "memory",
  14. }
  15. func loadGlobalLockFrom(rootCfg ConfigProvider) {
  16. sec := rootCfg.Section("global_lock")
  17. GlobalLock.ServiceType = sec.Key("SERVICE_TYPE").MustString("memory")
  18. switch GlobalLock.ServiceType {
  19. case "memory":
  20. case "redis":
  21. connStr := sec.Key("SERVICE_CONN_STR").String()
  22. if connStr == "" {
  23. log.Fatal("SERVICE_CONN_STR is empty for redis")
  24. }
  25. u := nosql.ToRedisURI(connStr)
  26. if u == nil {
  27. log.Fatal("SERVICE_CONN_STR %s is not a valid redis connection string", connStr)
  28. }
  29. GlobalLock.ServiceConnStr = connStr
  30. default:
  31. log.Fatal("Unknown sync lock service type: %s", GlobalLock.ServiceType)
  32. }
  33. }