code.gitea.io/gitea@v1.19.3/modules/setting/config_provider.go (about) 1 // Copyright 2023 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package setting 5 6 import ( 7 "code.gitea.io/gitea/modules/log" 8 9 ini "gopkg.in/ini.v1" 10 ) 11 12 // ConfigProvider represents a config provider 13 type ConfigProvider interface { 14 Section(section string) *ini.Section 15 NewSection(name string) (*ini.Section, error) 16 GetSection(name string) (*ini.Section, error) 17 } 18 19 // a file is an implementation ConfigProvider and other implementations are possible, i.e. from docker, k8s, … 20 var _ ConfigProvider = &ini.File{} 21 22 func mustMapSetting(rootCfg ConfigProvider, sectionName string, setting interface{}) { 23 if err := rootCfg.Section(sectionName).MapTo(setting); err != nil { 24 log.Fatal("Failed to map %s settings: %v", sectionName, err) 25 } 26 } 27 28 func deprecatedSetting(rootCfg ConfigProvider, oldSection, oldKey, newSection, newKey, version string) { 29 if rootCfg.Section(oldSection).HasKey(oldKey) { 30 log.Error("Deprecated fallback `[%s]` `%s` present. Use `[%s]` `%s` instead. This fallback will be/has been removed in %s", oldSection, oldKey, newSection, newKey, version) 31 } 32 } 33 34 // deprecatedSettingDB add a hint that the configuration has been moved to database but still kept in app.ini 35 func deprecatedSettingDB(rootCfg ConfigProvider, oldSection, oldKey string) { 36 if rootCfg.Section(oldSection).HasKey(oldKey) { 37 log.Error("Deprecated `[%s]` `%s` present which has been copied to database table sys_setting", oldSection, oldKey) 38 } 39 }