mirror of
https://github.com/wahyd4/badger.git
synced 2026-08-09 05:15:58 +10:00
38 lines
755 B
Go
38 lines
755 B
Go
package config
|
|
|
|
import "fmt"
|
|
|
|
type Config struct {
|
|
Host string
|
|
Port string
|
|
DBName string
|
|
Username string
|
|
Password string
|
|
}
|
|
|
|
func (config *Config) GetConnectionString() string {
|
|
connectionString := "sslmode=disable"
|
|
|
|
if config.Username != "" {
|
|
connectionString = connectionString + " user=" + config.Username
|
|
}
|
|
|
|
if config.Password != "" {
|
|
connectionString = connectionString + " password=" + config.Password
|
|
}
|
|
|
|
if config.Host != "" {
|
|
connectionString = connectionString + " host=" + config.Host
|
|
}
|
|
|
|
if config.Port != "" {
|
|
connectionString = fmt.Sprintf("%s port=%s", connectionString, config.Port)
|
|
}
|
|
|
|
if config.DBName != "" {
|
|
connectionString = connectionString + " dbname=" + config.DBName
|
|
}
|
|
|
|
return connectionString
|
|
}
|