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 "io"
|
||||||
import "os"
|
import "os"
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
import "sort"
|
||||||
import "bufio"
|
import "bufio"
|
||||||
import "strings"
|
import "strings"
|
||||||
import "strconv"
|
import "strconv"
|
||||||
@ -267,18 +268,27 @@ func (config *Config) Save (name string) (err error) {
|
|||||||
|
|
||||||
// SaveTo writes the configuration data to the specified io.Writer.
|
// SaveTo writes the configuration data to the specified io.Writer.
|
||||||
func (config *Config) SaveTo (writer io.Writer) (err error) {
|
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) {
|
switch value.(type) {
|
||||||
case string:
|
case string:
|
||||||
fmt.Fprintf(writer,"%s: %s\n", key, value.(string))
|
fmt.Fprintf(writer,"%s: %s\n", key, value.(string))
|
||||||
|
|
||||||
case color.RGBA:
|
case color.RGBA:
|
||||||
colorValue := value.(color.RGBA)
|
colorValue := value.(color.RGBA)
|
||||||
colorInt := uint64 (
|
colorInt :=
|
||||||
colorValue.R << 16 |
|
uint64(colorValue.R) << 16 |
|
||||||
colorValue.G << 8 |
|
uint64(colorValue.G) << 8 |
|
||||||
colorValue.B)
|
uint64(colorValue.B)
|
||||||
fmt.Fprintf(writer,"%s: #%x\n", key, colorInt)
|
fmt.Fprintf(writer,"%s: #%06x\n", key, colorInt)
|
||||||
|
|
||||||
case int:
|
case int:
|
||||||
fmt.Fprintf(writer,"%s: %d\n", key, value.(int))
|
fmt.Fprintf(writer,"%s: %d\n", key, value.(int))
|
||||||
|
Loading…
Reference in New Issue
Block a user