2018-05-08 10:31:51 +00:00
|
|
|
package datastore
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
type Config struct {
|
2018-05-08 14:21:22 +00:00
|
|
|
Driver string `default:"sqlite3"`
|
2018-05-08 10:31:51 +00:00
|
|
|
Host string `default:""`
|
|
|
|
User string `default:""`
|
|
|
|
Password string `default:""`
|
2018-05-08 10:45:24 +00:00
|
|
|
Name string `default:"fathom.db"`
|
2018-05-08 10:31:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) DSN() string {
|
|
|
|
var dsn string
|
|
|
|
|
|
|
|
switch c.Driver {
|
|
|
|
case "postgres":
|
|
|
|
dsn = fmt.Sprintf("host=%s user=%s password=%s dbname=%s", c.Host, c.User, c.Password, c.Name)
|
|
|
|
case "mysql":
|
|
|
|
dsn = fmt.Sprintf("%s:%s@%s/%s?parseTime=true&loc=Local", c.User, c.Password, c.Host, c.Name)
|
2018-05-08 14:21:22 +00:00
|
|
|
case "sqlite3":
|
|
|
|
dsn = c.Name + "?_loc=auto"
|
2018-05-08 10:31:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return dsn
|
|
|
|
}
|