-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
51 lines (42 loc) · 1.05 KB
/
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
48
49
50
51
package main
import (
"net/http"
"os"
"github.com/go-chi/chi/v5"
"github.com/goremit/money-transfer/api/handlers"
"github.com/goremit/money-transfer/db"
"github.com/sirupsen/logrus"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
func main() {
log := logrus.New()
log.SetFormatter(&logrus.JSONFormatter{})
log.SetOutput(os.Stdout)
if err := run(log); err != nil {
log.Fatalf("%s\n", err)
os.Exit(1)
}
}
func run(*logrus.Logger) error {
orm, err := gorm.Open(mysql.Open(""), &gorm.Config{})
if err != nil {
return err
}
// repos
trxRepo := db.NewTransactionsRepo(orm)
// handlers
customers := handlers.NewCustomers(trxRepo)
r := chi.NewRouter()
r.Route("customers", func(r chi.Router) {
r.Route("transactions", func(r chi.Router) {
r.Post("/", customers.HandleCreateTransaction)
r.Route("{id}", func(r chi.Router) {
r.Get("/", customers.HandleShowTransaction)
r.Post("/fund", customers.HandleFundTransaction)
r.Delete("/", customers.HandleCancelTransaction)
})
})
})
return http.ListenAndServe("127.0.0.1:9090", r)
}