-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (36 loc) · 881 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
package main
import (
"database/sql"
"html/template"
"log"
"net/http"
"./controller"
"./model"
_ "github.com/mattn/go-sqlite3"
)
func main() {
http.Handle("/img/", http.FileServer(http.Dir("public")))
http.Handle("/js/", http.FileServer(http.Dir("public")))
http.Handle("/css/", http.FileServer(http.Dir("public")))
http.Handle("/vendor/", http.FileServer(http.Dir("public")))
controller.Startup(populateTemplates())
db := connectDB()
defer db.Close()
model.SetDB(db)
log.Fatal(http.ListenAndServe(":3000", nil))
}
func populateTemplates() *template.Template {
result := template.New("index.html")
template.Must(result.ParseGlob("./views/*.html"))
return result
}
func connectDB() *sql.DB {
db, err := sql.Open("sqlite3", "./database.db")
if err != nil {
log.Println(err)
return nil
}
log.Println("Connected to DB")
model.SetDB(db)
return db
}