-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (31 loc) · 818 Bytes
/
main.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
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"database/sql"
"fmt"
"github.com/AsgerNoer/talks/write-less-code/internal/database"
"github.com/AsgerNoer/talks/write-less-code/internal/httpserver"
"github.com/rs/zerolog/log"
)
const dbDialect string = "postgres"
func main() {
connStr := fmt.Sprintf("host=%s user=%s password=%s dbname=%s sslmode=%s",
"postgres",
"postgres",
"postgres",
"postgres",
"disable",
)
db, err := sql.Open(dbDialect, connStr)
if err != nil {
log.Fatal().Err(err).Msg("opening database")
}
defer db.Close()
store, err := database.New(dbDialect, db)
if err != nil {
log.Fatal().Err(err).Msg("establishing database connection")
}
server := httpserver.NewServer(store)
if err := server.Start("0.0.0.0:3000"); err != nil {
log.Fatal().Err(err).Msg("starting service failed")
}
}