-
Notifications
You must be signed in to change notification settings - Fork 0
/
huautla.go
29 lines (23 loc) · 887 Bytes
/
huautla.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package huautla
import (
"fmt"
"github.com/jsmit257/huautla/internal/data"
"github.com/jsmit257/huautla/types"
log "github.com/sirupsen/logrus"
)
func New(cfg *types.Config, log *log.Entry) (types.DB, error) {
var cnxFmt = "host=%s port=%d user=%s password=%s dbname=huautla sslmode=%s"
var cnxInfo string
if host := cfg.PGHost; host == "" {
return nil, fmt.Errorf("postgres connection needs hostname attribute")
} else if user := cfg.PGUser; user == "" {
return nil, fmt.Errorf("postgres connection needs username attribute")
} else if pass := cfg.PGPass; pass == "" {
return nil, fmt.Errorf("postgres connection needs password attribute")
} else if port := cfg.PGPort; port == 0 {
return nil, fmt.Errorf("postgres connection needs port attribute")
} else {
cnxInfo = fmt.Sprintf(cnxFmt, host, port, user, pass, cfg.PGSSL)
}
return data.New(cnxInfo, log)
}