-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (49 loc) · 1.57 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
53
54
55
56
57
58
59
60
61
package main
import (
"2vid/handlers"
"2vid/logger"
"2vid/middleware"
"2vid/mysql"
"2vid/redis"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
_ "github.com/go-sql-driver/mysql"
)
func main() {
defer db_mysql.DB_mysql.Close()
defer db_redis.DB_redis.Close()
router := gin.New()
config := cors.DefaultConfig()
config.AllowOrigins = []string{"*"}
config.AddAllowHeaders("Origin")
config.AllowCredentials = true
// config.AllowAllOrigins = true
router.Use(cors.New(config))
// Global middleware
// Logger middleware will write the logs to gin.DefaultWriter even if you set with GIN_MODE=release.
// By default gin.DefaultWriter = os.Stdout
// router.Use(gin.Logger())
// Custom Logger middleware
router.Use(logger.Logger())
// Recovery middleware recovers from any panics and writes a 500 if there was one.
router.Use(gin.Recovery())
// Simple group: v1
v1 := router.Group("/api/v1", middleware.Authentication())
{
/*
// URL EXAMPLE /credentials?iss=did:idhub:0x1234567890&aud=did:idhub:0987654321&sub=test
v1.GET("/credentials", getCredential)
v1.POST("/credentials", createCredential)
v1.PUT("/credentials", updateCredential)
v1.DELETE("/credentials", deleteCredential)
// URL EXAMPLE /exceptions?iss=did:idhub:0x1234567890&aud=did:idhub:0987654321&sub=test
v1.GET("/exceptions", recoverCredential)
v1.POST("/exceptions", recoverCredential)
*/
v1.GET("/", handler.HandleCredential)
v1.POST("/", handler.HandleCredential)
v1.GET("", handler.HandleCredential)
v1.POST("", handler.HandleCredential)
}
router.Run(":8000")
}