fathom/pkg/datastore/config.go

27 lines
582 B
Go
Raw Normal View History

2018-05-08 10:31:51 +00:00
package datastore
import "fmt"
type Config struct {
Driver string `default:"sqlite3"`
2018-05-08 10:31:51 +00:00
Host string `default:""`
User string `default:""`
Password string `default:""`
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)
case "sqlite3":
dsn = c.Name + "?_loc=auto"
2018-05-08 10:31:51 +00:00
}
return dsn
}