forked from bolerap/famcost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (43 loc) · 931 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
47
package main
import (
"database/sql"
"log"
"net/http"
"os"
_ "github.com/mattn/go-sqlite3"
)
var (
db *sql.DB
err error
authenticated = false
)
func main() {
db, err = sql.Open("sqlite3", "db.sqlite3")
if err != nil {
panic(err)
}
defer db.Close()
// test connection
err = db.Ping()
if err != nil {
panic(err)
}
//os.Setenv("PORT", "8898")
port := os.Getenv("PORT")
if port == "" {
log.Fatal("$PORT must be set")
}
// route
http.HandleFunc("/", indexHandler)
http.HandleFunc("/login", loginHandler)
http.HandleFunc("/logout", logoutHandler)
http.HandleFunc("/register", registerHandler)
http.HandleFunc("/list", listHandler)
http.HandleFunc("/create", createHandler)
http.HandleFunc("/update", updateHandler)
http.HandleFunc("/delete", deleteHandler)
http.Handle("/statics/",
http.StripPrefix("/statics/", http.FileServer(http.Dir("./statics"))),
)
http.ListenAndServe(":"+port, nil)
}