forked from grahamnscp/workflow-web
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webapp.go
79 lines (62 loc) · 2.31 KB
/
webapp.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"log"
"net/http"
"os"
"strconv"
"time"
"github.com/gorilla/mux"
_ "net/http/pprof"
"webapp/handlers"
"webapp/transferclient"
)
var CheckTransferTaskQueueTimer = os.Getenv("CHECK_TRANSFER_TASKQUEUE_TIMER")
// Main
func main() {
router := mux.NewRouter()
router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
router.HandleFunc("/", handlers.Home)
router.HandleFunc("/home", handlers.Home)
// accounts database handlers
router.HandleFunc("/accounts", handlers.ListAccounts)
router.HandleFunc("/showaccount", handlers.ShowAccount)
router.HandleFunc("/newaccount", handlers.NewAccount)
router.HandleFunc("/deleteaccount", handlers.DeleteAccount)
router.HandleFunc("/bankstatus", handlers.BankStatus)
router.HandleFunc("/openbank", handlers.OpenBank)
router.HandleFunc("/closebank", handlers.CloseBank)
// moneytransfer database handlers
router.HandleFunc("/transfers", handlers.ListTransfers)
router.HandleFunc("/showtransfer", handlers.ShowTransfer)
router.HandleFunc("/newtransfer", handlers.NewTransfer)
router.HandleFunc("/resettransfer", handlers.ResetTransfer)
router.HandleFunc("/queryworkflow", handlers.QueryTransferWorkflow)
// standing order payment handlers
router.HandleFunc("/listsorders", handlers.ListSOrders)
router.HandleFunc("/newsorder", handlers.NewSOrder)
router.HandleFunc("/amendsorder", handlers.AmendSOrder)
router.HandleFunc("/cancelsorder", handlers.CancelSOrder)
// schedule handlers
router.HandleFunc("/newschedule", handlers.NewSchedule)
router.HandleFunc("/schedules", handlers.ListSchedules)
router.HandleFunc("/showschedule", handlers.ShowSchedule)
router.HandleFunc("/updateschedule", handlers.UpdateSchedule)
router.HandleFunc("/deleteschedule", handlers.DeleteSchedule)
// Start periodic background transfer table task
queryDelay, err := strconv.ParseUint(CheckTransferTaskQueueTimer, 10, 64)
if err != nil {
queryDelay = 20
}
go transferclient.ExecuteCheckTransferTaskCronJob(queryDelay)
// pprof thread /debug/pprof
go http.ListenAndServe("localhost:6060", nil)
// Serve
log.Print("Serve Http on 8085")
srv := &http.Server{
Handler: router,
Addr: ":8085",
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}
log.Fatal(srv.ListenAndServe())
}