-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (40 loc) · 1.59 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
52
package main
import (
"log"
"net/http"
"github.com/gorilla/mux"
"github.com/org-45/escrow-agent/internal/auth"
"github.com/org-45/escrow-agent/internal/db"
"github.com/org-45/escrow-agent/internal/escrow"
"github.com/org-45/escrow-agent/internal/fileupload"
"github.com/org-45/escrow-agent/internal/middleware"
"github.com/rs/cors"
)
func main() {
db.InitDB()
r := mux.NewRouter()
//public routes
r.HandleFunc("/login", auth.LoginHandler).Methods("POST")
r.HandleFunc("/signup", auth.SignupHandler).Methods("POST")
//protected routes
api := r.PathPrefix("/api").Subrouter()
api.Use(middleware.JWTAuthMiddleware)
api.HandleFunc("/escrow", escrow.CreateEscrowHandler).Methods("POST")
api.HandleFunc("/escrow/{id}/release", escrow.ReleaseFundsHandler).Methods("POST")
api.HandleFunc("/escrow/{id}/dispute", escrow.DisputeEscrowHandler).Methods("POST")
api.HandleFunc("/escrow/pending", escrow.GetAllPendingEscrowsHandler).Methods("GET")
api.HandleFunc("/escrow/disputed", escrow.GetAllDisputedEscrowsHandler).Methods("GET")
api.HandleFunc("/upload", fileupload.UploadHandler).Methods("POST")
api.HandleFunc("/customer", escrow.CreateCustomerHandler).Methods("POST")
// setup CORS
c := cors.New(cors.Options{
AllowedOrigins: []string{"http://localhost:3000"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowedHeaders: []string{"Content-Type", "Authorization"},
AllowCredentials: true,
})
// wrap the router with the CORS middleware
handler := c.Handler(r)
log.Println("Starting server on :8080")
log.Fatal(http.ListenAndServe(":8080", handler))
}