Use db client factory in seeder.

This commit is contained in:
Sascha L. Teichmann
2022-02-27 21:17:43 +01:00
parent 34d01762f0
commit 4f7fedf0b9
3 changed files with 35 additions and 2 deletions

33
common/clientfactory.go Normal file
View File

@ -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)
}
}