-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
47 lines (39 loc) · 1.2 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
package main
import (
_ "ZeroPassBackend/docs"
zeroPassRouter "ZeroPassBackend/router"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/swaggo/files"
"github.com/swaggo/gin-swagger"
"log"
)
func init() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
}
// @title User API documentation
// @version 1.0.0
// @host localhost:5000
// @BasePath /user
func main() {
router := gin.Default()
// Add CORS middleware
config := cors.DefaultConfig()
config.AllowOrigins = []string{"*"} // 允许所有来源
config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE"}
config.AllowHeaders = []string{"Origin", "Content-Type", "Accept"}
router.Use(cors.New(config))
// Set up Swagger middleware
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
// Your other routes and handlers
router.POST("/upload/:address", zeroPassRouter.UploadHandler)
router.GET("/members", zeroPassRouter.GetAllMembersHandler)
router.GET("/members/:address", zeroPassRouter.GetMember)
router.PUT("/members/:address", zeroPassRouter.UpdateMember)
router.POST("/verify", zeroPassRouter.VerifyHandler)
_ = router.Run(":8080")
}