github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/setting/cron.go (about) 1 // Copyright 2023 The GitBundle Inc. All rights reserved. 2 // Copyright 2017 The Gitea Authors. All rights reserved. 3 // Use of this source code is governed by a MIT-style 4 // license that can be found in the LICENSE file. 5 6 package setting 7 8 import "reflect" 9 10 // GetCronSettings maps the cron subsection to the provided config 11 func GetCronSettings(name string, config interface{}) (interface{}, error) { 12 if err := Cfg.Section("cron." + name).MapTo(config); err != nil { 13 return config, err 14 } 15 16 typ := reflect.TypeOf(config).Elem() 17 val := reflect.ValueOf(config).Elem() 18 19 for i := 0; i < typ.NumField(); i++ { 20 field := val.Field(i) 21 tpField := typ.Field(i) 22 if tpField.Type.Kind() == reflect.Struct && tpField.Anonymous { 23 if err := Cfg.Section("cron." + name).MapTo(field.Addr().Interface()); err != nil { 24 return config, err 25 } 26 } 27 } 28 29 return config, nil 30 }