-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
34 lines (29 loc) · 945 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
package main
import (
"log"
"net/http"
"github.com/gorilla/mux"
_ "github.com/jinzhu/gorm/dialects/sqlite"
_ "github.com/mattn/go-sqlite3"
)
func main() {
log.Println("Starting application")
log.Println("Creating table")
check := checkIfTableExist()
if check == false {
err := createTable()
if err != nil {
log.Fatal("Table does not exist but can not create one. Caused by:", err)
}
log.Println("Starting router")
} else {
log.Println("Table already exist. Starting router")
}
router := mux.NewRouter()
router.HandleFunc("/people", getAllHandler).Methods("GET")
router.HandleFunc("/people/{id}", getPersonByIDHandler).Methods("GET")
router.HandleFunc("/people/{id}", deletePersonByIDHandler).Methods("POST")
router.HandleFunc("/people", createNewPersonHandler).Methods("POST")
router.HandleFunc("/people/update/{id}", updatePersonByIDHandler).Methods("POST")
log.Fatal(http.ListenAndServe(":8000", router))
}