generated from cheqd/.github
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
94 lines (80 loc) · 2.49 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"github.com/cheqd/did-resolver/services"
didDocServices "github.com/cheqd/did-resolver/services/diddoc"
resourceServices "github.com/cheqd/did-resolver/services/resource"
"github.com/cheqd/did-resolver/types"
"github.com/cheqd/did-resolver/utils"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/rs/zerolog/log"
echoSwagger "github.com/swaggo/echo-swagger"
// Import generated Swagger docs
_ "github.com/cheqd/did-resolver/docs"
)
func serve() {
// Get Config
config := types.GetConfig()
// Setup logger
types.SetupLogger(config)
// Services
ledgerService := services.NewLedgerService()
didService := services.NewDIDDocService(types.DID_METHOD, ledgerService)
resourceService := services.NewResourceService(types.DID_METHOD, ledgerService)
for _, network := range config.Networks {
log.Info().Msgf("Registering network: %s.", network.Namespace)
err := ledgerService.RegisterLedger(types.DID_METHOD, network)
if err != nil {
panic(err)
}
}
// Echo instance
e := echo.New()
e.HTTPErrorHandler = services.CustomHTTPErrorHandler
// Middleware
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
cc := services.ResolverContext{
Context: c,
LedgerService: ledgerService,
DidDocService: didService,
ResourceService: resourceService,
}
return next(cc)
}
})
// Client sends the Accept-Encoding header and
// server should respond with the Content-Encoding header
// Decompress only if gzip in headers
e.Use(middleware.Decompress())
// Compress only if gzip in headers
e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
// If gzip not in Accept-Encoding header, do not compress
Skipper: utils.GzipSkipper,
}))
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.GET(types.SWAGGER_PATH, echoSwagger.WrapHandler)
didDocServices.SetRoutes(e)
resourceServices.SetRoutes(e)
e.Debug = true
log.Info().Msg("Starting listener")
log.Fatal().Err(e.Start(config.ResolverListener))
}
// @title DID Resolver for cheqd DID method
// @version v3.0
// @description Universal Resolver driver for cheqd DID method
// @contact.name Cheqd Foundation Limited
// @contact.url https://cheqd.io
// @license.name Apache 2.0
// @license.url https://github.com/cheqd/did-resolver/blob/main/LICENSE
// @host resolver.cheqd.net
// @BasePath /1.0/identifiers
// @schemes https http
func main() {
err := types.PrintConfig()
if err != nil {
panic(err)
}
serve()
}