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.

cron.go 871B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package setting
  4. import "reflect"
  5. // GetCronSettings maps the cron subsection to the provided config
  6. func GetCronSettings(name string, config any) (any, error) {
  7. return getCronSettings(CfgProvider, name, config)
  8. }
  9. func getCronSettings(rootCfg ConfigProvider, name string, config any) (any, error) {
  10. if err := rootCfg.Section("cron." + name).MapTo(config); err != nil {
  11. return config, err
  12. }
  13. typ := reflect.TypeOf(config).Elem()
  14. val := reflect.ValueOf(config).Elem()
  15. for i := 0; i < typ.NumField(); i++ {
  16. field := val.Field(i)
  17. tpField := typ.Field(i)
  18. if tpField.Type.Kind() == reflect.Struct && tpField.Anonymous {
  19. if err := rootCfg.Section("cron." + name).MapTo(field.Addr().Interface()); err != nil {
  20. return config, err
  21. }
  22. }
  23. }
  24. return config, nil
  25. }