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