forked from gothinkster/realworld-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmain.go
More file actions
43 lines (32 loc) · 647 Bytes
/
main.go
File metadata and controls
43 lines (32 loc) · 647 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
package main
import (
"log"
"os"
"github.com/0xdod/go-realworld/postgres"
"github.com/0xdod/go-realworld/server"
_ "github.com/joho/godotenv/autoload"
)
type config struct {
port string
dbURI string
}
func main() {
cfg := envConfig()
db, err := postgres.Open(cfg.dbURI)
if err != nil {
log.Fatalf("cannot open database: %v", err)
}
srv := server.NewServer(db)
log.Fatal(srv.Run(cfg.port))
}
func envConfig() config {
port, ok := os.LookupEnv("PORT")
if !ok {
panic("PORT not provided")
}
dbURI, ok := os.LookupEnv("POSTGRESQL_URL")
if !ok {
panic("POSTGRESQL_URL not provided")
}
return config{port, dbURI}
}