Fixed some bugs related to saving conf files
This commit is contained in:
parent
639e43cfa7
commit
73ae475a7d
@ -3,6 +3,7 @@ package config
|
||||
import "io"
|
||||
import "os"
|
||||
import "fmt"
|
||||
import "sort"
|
||||
import "bufio"
|
||||
import "strings"
|
||||
import "strconv"
|
||||
@ -267,18 +268,27 @@ func (config *Config) Save (name string) (err error) {
|
||||
|
||||
// SaveTo writes the configuration data to the specified io.Writer.
|
||||
func (config *Config) SaveTo (writer io.Writer) (err error) {
|
||||
for key, value := range config.Parameters {
|
||||
keys := make([]string, len(config.Parameters))
|
||||
index := 0
|
||||
for key, _ := range config.Parameters {
|
||||
keys[index] = key
|
||||
index ++
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
for _, key := range keys {
|
||||
value := config.Parameters[key]
|
||||
switch value.(type) {
|
||||
case string:
|
||||
fmt.Fprintf(writer,"%s: %s\n", key, value.(string))
|
||||
|
||||
case color.RGBA:
|
||||
colorValue := value.(color.RGBA)
|
||||
colorInt := uint64 (
|
||||
colorValue.R << 16 |
|
||||
colorValue.G << 8 |
|
||||
colorValue.B)
|
||||
fmt.Fprintf(writer,"%s: #%x\n", key, colorInt)
|
||||
colorInt :=
|
||||
uint64(colorValue.R) << 16 |
|
||||
uint64(colorValue.G) << 8 |
|
||||
uint64(colorValue.B)
|
||||
fmt.Fprintf(writer,"%s: #%06x\n", key, colorInt)
|
||||
|
||||
case int:
|
||||
fmt.Fprintf(writer,"%s: %d\n", key, value.(int))
|
||||
|
Loading…
Reference in New Issue
Block a user