diff --git a/cmd/mtseeder/main.go b/cmd/mtseeder/main.go index cee37dd..0cbb0f9 100644 --- a/cmd/mtseeder/main.go +++ b/cmd/mtseeder/main.go @@ -7,7 +7,6 @@ package main import ( "flag" "fmt" - "image/color" "log" "bitbucket.org/s_l_teichmann/mtsatellite/common" @@ -68,12 +67,7 @@ func main() { common.PrintVersionAndExit() } - var bg color.RGBA - var err error - if bg, err = common.ParseColor(bgColor); err != nil { - log.Printf("WARN: Cannot parse background color '%s': %s\n", bgColor, err) - bg = common.BackgroundColor - } + bg := common.ParseColorDefault(bgColor, common.BackgroundColor) if !skipBaseLevel { td := common.Clamp32f(float32(transparentDim/100.0), 0.0, 1.0) diff --git a/cmd/mttilemapper/main.go b/cmd/mttilemapper/main.go index 103739b..cf72ad1 100644 --- a/cmd/mttilemapper/main.go +++ b/cmd/mttilemapper/main.go @@ -8,7 +8,6 @@ import ( "flag" "fmt" "image" - "image/color" "log" "os" "runtime/pprof" @@ -65,12 +64,7 @@ func main() { common.PrintVersionAndExit() } - var bg color.RGBA - var err error - if bg, err = common.ParseColor(bgColor); err != nil { - log.Printf("WARN: Cannot parse background color '%s': %s\n", bgColor, err) - bg = common.BackgroundColor - } + bg := common.ParseColorDefault(bgColor, common.BackgroundColor) if cpuProfile != "" { f, err := os.Create(cpuProfile) @@ -82,6 +76,7 @@ func main() { } var colors *common.Colors + var err error if colors, err = common.ParseColors(colorsfile); err != nil { log.Fatalf("Cannot open color file: %s", err) } diff --git a/cmd/mtwebmapper/main.go b/cmd/mtwebmapper/main.go index 4cf3305..8276422 100644 --- a/cmd/mtwebmapper/main.go +++ b/cmd/mtwebmapper/main.go @@ -7,7 +7,6 @@ package main import ( "flag" "fmt" - "image/color" "log" "net" "net/http" @@ -83,12 +82,7 @@ func main() { common.PrintVersionAndExit() } - var bg color.RGBA - var err error - if bg, err = common.ParseColor(bgColor); err != nil { - log.Printf("WARN: Cannot parse background color '%s': %s\n", bgColor, err) - bg = common.BackgroundColor - } + bg := common.ParseColorDefault(bgColor, common.BackgroundColor) router := mux.NewRouter() diff --git a/common/colors.go b/common/colors.go index 22a4fd4..c9a6bdd 100644 --- a/common/colors.go +++ b/common/colors.go @@ -8,6 +8,7 @@ import ( "bufio" "fmt" "image/color" + "log" "os" "sort" "strconv" @@ -136,6 +137,15 @@ func ParseColor(col string) (color.RGBA, error) { A: 0xff}, nil } +func ParseColorDefault(col string, def color.RGBA) color.RGBA { + c, err := ParseColor(col) + if err != nil { + log.Printf("WARN: cannot parse color '%s': %s\n", col, err) + return def + } + return c +} + func ColorToHex(col color.RGBA) string { return fmt.Sprintf("#%02x%02x%02x", col.R, col.G, col.B) }