-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
51 lines (43 loc) · 1.29 KB
/
Copy pathmain.go
File metadata and controls
51 lines (43 loc) · 1.29 KB
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 (
"github.com/delta003/x402-dev-facilitator/core"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"log"
"os"
)
func main() {
// Load environment variables from .env file
if err := godotenv.Load(); err != nil {
log.Println("No .env file found, using system environment variables")
}
// Get configuration from environment
rpcURL := os.Getenv("RPC_URL")
if rpcURL == "" {
log.Fatal("RPC_URL environment variable not set")
}
privateKey := os.Getenv("FACILITATOR_WALLET_PRIVATE_KEY")
if privateKey == "" {
log.Fatal("FACILITATOR_WALLET_PRIVATE_KEY environment variable not set")
}
// Create facilitator instance
facilitator, err := core.NewFacilitatorFromHex(privateKey, rpcURL)
if err != nil {
log.Fatalf("Failed to create facilitator: %v", err)
}
// Create Gin router
r := gin.Default()
// Add detailed logging middleware
r.Use(core.DetailedLoggingMiddleware())
r.Use(gin.Recovery())
// Configure routes
r.POST("/verify", facilitator.VerifyPaymentHandler)
// This is an extension to the x402 protocol. See core/extensions.go for details.
r.POST("/verify-receipt", facilitator.VerifyReceiptHandler)
r.POST("/settle", facilitator.SettlePaymentHandler)
r.GET("/health", facilitator.HealthHandler)
err = r.Run(":4020")
if err != nil {
log.Fatal(err)
}
}