You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

config.go 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package setting
  4. import (
  5. "sync"
  6. "code.gitea.io/gitea/modules/log"
  7. "code.gitea.io/gitea/modules/setting/config"
  8. )
  9. type PictureStruct struct {
  10. DisableGravatar *config.Value[bool]
  11. EnableFederatedAvatar *config.Value[bool]
  12. }
  13. type ConfigStruct struct {
  14. Picture *PictureStruct
  15. }
  16. var (
  17. defaultConfig *ConfigStruct
  18. defaultConfigOnce sync.Once
  19. )
  20. func initDefaultConfig() {
  21. config.SetCfgSecKeyGetter(&cfgSecKeyGetter{})
  22. defaultConfig = &ConfigStruct{
  23. Picture: &PictureStruct{
  24. DisableGravatar: config.Bool(false, config.CfgSecKey{Sec: "picture", Key: "DISABLE_GRAVATAR"}, "picture.disable_gravatar"),
  25. EnableFederatedAvatar: config.Bool(false, config.CfgSecKey{Sec: "picture", Key: "ENABLE_FEDERATED_AVATAR"}, "picture.enable_federated_avatar"),
  26. },
  27. }
  28. }
  29. func Config() *ConfigStruct {
  30. defaultConfigOnce.Do(initDefaultConfig)
  31. return defaultConfig
  32. }
  33. type cfgSecKeyGetter struct{}
  34. func (c cfgSecKeyGetter) GetValue(sec, key string) (v string, has bool) {
  35. cfgSec, err := CfgProvider.GetSection(sec)
  36. if err != nil {
  37. log.Error("Unable to get config section: %q", sec)
  38. return "", false
  39. }
  40. cfgKey := ConfigSectionKey(cfgSec, key)
  41. if cfgKey == nil {
  42. return "", false
  43. }
  44. return cfgKey.Value(), true
  45. }