forked from nonfx/codepipes-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
33 lines (27 loc) · 866 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
package main
import (
"go-sql-demo/database"
"go-sql-demo/handlers"
"log"
"net/http"
"github.com/gorilla/mux"
)
func main() {
database.ConnectDb()
// initialize router
r := setupRoutes()
handlers.SetupDemoAccount()
log.Println("Server listening on port 3000...!!")
log.Fatal(http.ListenAndServe(":3000", r))
}
func setupRoutes() *mux.Router {
r := mux.NewRouter()
r.HandleFunc("/", handlers.HomeHandler)
r.HandleFunc("/manage", handlers.FundHandler).Methods(http.MethodPost)
r.HandleFunc("/accounts", handlers.CreateAccountHandler).Methods(http.MethodPost)
r.HandleFunc("/accounts", handlers.ListAccountsHandler).Methods(http.MethodGet)
r.HandleFunc("/accounts/{id}", handlers.GetAccountHandler).Methods(http.MethodGet)
r.HandleFunc("/accounts/{id}", handlers.DeleteAccountHandler).Methods(http.MethodDelete)
http.Handle("/", r)
return r
}