-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_init.go
More file actions
47 lines (42 loc) · 891 Bytes
/
db_init.go
File metadata and controls
47 lines (42 loc) · 891 Bytes
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"crypto/tls"
"io/ioutil"
"log"
"os"
"time"
"github.com/jackc/pgx"
)
var db *pgx.ConnPool
func init() {
poolCfg := pgx.ConnPoolConfig{MaxConnections: 9, AcquireTimeout: time.Second * 9}
poolCfg.ConnConfig = pgx.ConnConfig{
Host: config.Database.Host,
Port: uint16(config.Database.Port),
Database: config.Database.Name,
User: config.Database.User,
Password: config.Database.Password,
}
if config.Database.TLS {
poolCfg.ConnConfig.TLSConfig = &tls.Config{
ServerName: config.Database.Host,
}
}
var e error
db, e = pgx.NewConnPool(poolCfg)
if e != nil {
log.Println(e.Error())
os.Exit(1)
}
}
func store(name, raddr, app, bucket string) error {
b, e := ioutil.ReadFile("sql/queries/insert.sql")
if e != nil {
return e
}
_, e = db.Exec(string(b), name, raddr, app, bucket)
if e != nil {
return e
}
return nil
}