diff --git a/cmd/mtseeder/baselevel.go b/cmd/mtseeder/baselevel.go index 65250c6..96bf923 100644 --- a/cmd/mtseeder/baselevel.go +++ b/cmd/mtseeder/baselevel.go @@ -56,7 +56,7 @@ func createTiles( } func createBaseLevel( - dbcc dbClientCreator, + dbcc common.DBClientCreator, xMin, yMin, zMin, xMax, yMax, zMax int, transparent bool, transparentDim float32, colorsFile string, bg color.RGBA, outDir string, diff --git a/cmd/mtseeder/main.go b/cmd/mtseeder/main.go index 4b5edc2..7ba1fba 100644 --- a/cmd/mtseeder/main.go +++ b/cmd/mtseeder/main.go @@ -68,7 +68,7 @@ func main() { bg := common.ParseColorDefault(bgColor, common.BackgroundColor) - dbcc := createDBClientCreator(host, port) + dbcc := common.CreateDBClientCreator(host, port) if !skipBaseLevel { td := common.Clamp32f(float32(transparentDim/100.0), 0.0, 1.0) diff --git a/common/clientfactory.go b/common/clientfactory.go new file mode 100644 index 0000000..43a1e8f --- /dev/null +++ b/common/clientfactory.go @@ -0,0 +1,33 @@ +// Copyright 2022 by Sascha L. Teichmann +// Use of this source code is governed by the MIT license +// that can be found in the LICENSE file. + +package common + +import ( + "fmt" + "strings" +) + +type DBClientCreator func() (DBClient, error) + +func CreateDBClientCreator(host string, port int) DBClientCreator { + + var address string + if strings.ContainsRune(host, '/') { + address = host + } else { + address = fmt.Sprintf("%s:%d", host, port) + } + + var proto string + if strings.ContainsRune(address, '/') { + proto = "unix" + } else { + proto = "tcp" + } + + return func() (DBClient, error) { + return NewRedisClient(proto, address) + } +}