(toMerge waveobj.MetaMapType)
| 843 | } |
| 844 | |
| 845 | func SetBaseConfigValue(toMerge waveobj.MetaMapType) error { |
| 846 | m, cerrs := ReadWaveHomeConfigFile(SettingsFile) |
| 847 | if len(cerrs) > 0 { |
| 848 | return fmt.Errorf("error reading config file: %v", cerrs[0]) |
| 849 | } |
| 850 | if m == nil { |
| 851 | m = make(waveobj.MetaMapType) |
| 852 | } |
| 853 | for configKey, val := range toMerge { |
| 854 | ctype := getConfigKeyType(configKey) |
| 855 | if ctype == nil { |
| 856 | return fmt.Errorf("invalid config key: %s", configKey) |
| 857 | } |
| 858 | if val == nil { |
| 859 | delete(m, configKey) |
| 860 | } else { |
| 861 | rtype := reflect.TypeOf(val) |
| 862 | if rtype == reflect.TypeOf(dummyNumber) { |
| 863 | convertedVal, err := convertJsonNumber(val.(json.Number), ctype) |
| 864 | if err != nil { |
| 865 | return fmt.Errorf("cannot convert %s: %v", configKey, err) |
| 866 | } |
| 867 | val = convertedVal |
| 868 | rtype = reflect.TypeOf(val) |
| 869 | } |
| 870 | if rtype != ctype { |
| 871 | if ctype == reflect.PointerTo(rtype) { |
| 872 | m[configKey] = &val |
| 873 | } else { |
| 874 | return fmt.Errorf("invalid value type for %s: %T", configKey, val) |
| 875 | } |
| 876 | } |
| 877 | m[configKey] = val |
| 878 | } |
| 879 | } |
| 880 | return WriteWaveHomeConfigFile(SettingsFile, m) |
| 881 | } |
| 882 | |
| 883 | func SetConnectionsConfigValue(connName string, toMerge waveobj.MetaMapType) error { |
| 884 | m, cerrs := ReadWaveHomeConfigFile(ConnectionsFile) |
no test coverage detected