package postgres import ( _ "github.com/lib/pq" "bytes" "database/sql" "text/template" "tacitus" ) const connStr = `user={{.User}} dbname={{.Name}} sslmode={{.SslMode}}` type Client struct { Name string User string SslMode string tradeService TradeService db *sql.DB } func NewClient() *Client { c := Client{} c.tradeService.client = &c c.SslMode = "disable" return &c } func (c *Client) Open() error { buf := bytes.Buffer{} tmpl, _ := template.New("conn").Parse(connStr) tmpl.Execute(&buf, c) db, err := sql.Open("postgres", buf.String()) if err != nil { return err } if err = db.Ping(); err != nil { return err } c.db = db return nil } func (c *Client) TradeService() tacitus.TradeService { return &c.tradeService }