Esempio n. 1
0
// save general setting
//
//  in  : *SettingGeneralForm
//  out : nil
//
func (_ *SettingApi) SaveGeneral(v interface{}) *Res {
	form, ok := v.(*SettingGeneralForm)
	if !ok {
		return Fail(paramTypeError(new(SettingGeneralForm)))
	}
	mapData, err := struct2Map(form)
	if err != nil {
		return Fail(err)
	}

	for k, v := range mapData {
		if err = model.SaveSetting(strings.ToLower(k), fmt.Sprint(v), 0); err != nil {
			return Fail(err)
		}
	}
	return Success(nil)
}
Esempio n. 2
0
// save media setting
//
//  in  : *SettingMediaForm
//  out : nil
//
func (_ *SettingApi) SaveMedia(v interface{}) *Res {
	form, ok := v.(*SettingMediaForm)
	if !ok {
		return Fail(paramTypeError(form))
	}

	if form.NameFormat == "" {
		form.NameFormat = ":hash"
	}

	mapData, err := struct2Map(form)
	if err != nil {
		return Fail(err)
	}

	for k, v := range mapData {
		if err = model.SaveSetting("media_"+strings.ToLower(k), fmt.Sprint(v), 0); err != nil {
			return Fail(err)
		}
	}
	return Success(nil)
}