-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (36 loc) · 828 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
42
43
44
45
46
package main
import (
"database/sql"
"html/template"
"log"
"github.com/armadi1809/htm-x-chat/models"
_ "github.com/lib/pq"
)
type Config struct {
t *Template
chatRoom *room
userDb *models.UserDb
}
const dbSource = "postgresql://root:zizox18099@localhost:5432/Chat?sslmode=disable"
func main() {
db, err := openDb()
if err != nil {
log.Fatal("Can't Connect to the database")
}
app := &Config{
t: &Template{templates: template.Must(template.ParseGlob("templates/*.html"))},
chatRoom: NewRoom(),
userDb: &models.UserDb{DB: db},
}
e := app.routes()
go app.chatRoom.run()
log.Println("Spinning up the server...")
e.Logger.Fatal(e.Start(":3000"))
}
func openDb() (*sql.DB, error) {
db, err := sql.Open("postgres", dbSource)
if err != nil {
return nil, err
}
return db, nil
}