gitea源码

getter.go 934B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package config
  4. import (
  5. "context"
  6. "sync"
  7. )
  8. var getterMu sync.RWMutex
  9. type CfgSecKeyGetter interface {
  10. GetValue(sec, key string) (v string, has bool)
  11. }
  12. var cfgSecKeyGetterInternal CfgSecKeyGetter
  13. func SetCfgSecKeyGetter(p CfgSecKeyGetter) {
  14. getterMu.Lock()
  15. cfgSecKeyGetterInternal = p
  16. getterMu.Unlock()
  17. }
  18. func GetCfgSecKeyGetter() CfgSecKeyGetter {
  19. getterMu.RLock()
  20. defer getterMu.RUnlock()
  21. return cfgSecKeyGetterInternal
  22. }
  23. type DynKeyGetter interface {
  24. GetValue(ctx context.Context, key string) (v string, has bool)
  25. GetRevision(ctx context.Context) int
  26. InvalidateCache()
  27. }
  28. var dynKeyGetterInternal DynKeyGetter
  29. func SetDynGetter(p DynKeyGetter) {
  30. getterMu.Lock()
  31. dynKeyGetterInternal = p
  32. getterMu.Unlock()
  33. }
  34. func GetDynGetter() DynKeyGetter {
  35. getterMu.RLock()
  36. defer getterMu.RUnlock()
  37. return dynKeyGetterInternal
  38. }