mirror of https://github.com/1Panel-dev/1Panel
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.
37 lines
681 B
37 lines
681 B
1 year ago
|
package ini_conf
|
||
|
|
||
|
import "gopkg.in/ini.v1"
|
||
|
|
||
|
func GetIniValue(filePath, Group, Key string) (string, error) {
|
||
|
cfg, err := ini.Load(filePath)
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
service, err := cfg.GetSection(Group)
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
startKey, err := service.GetKey(Key)
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
return startKey.Value(), nil
|
||
|
}
|
||
|
|
||
|
func SetIniValue(filePath, Group, Key, value string) error {
|
||
|
cfg, err := ini.Load(filePath)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
service, err := cfg.GetSection(Group)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
targetKey := service.Key(Key)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
targetKey.SetValue(value)
|
||
|
return cfg.SaveTo(filePath)
|
||
|
}
|