-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_routes.go
61 lines (45 loc) · 1.21 KB
/
server_routes.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 api
import (
_ "embed"
"net/http"
"github.com/DEXPRO-Solutions-GmbH/swaggerui"
"github.com/fabiante/persurl/webapp"
"github.com/gin-gonic/gin"
)
//go:embed openapi.yml
var openAPI []byte
func SetupRouting(r gin.IRouter, s *Server) {
if swaggerUI, err := swaggerui.NewHandler(openAPI, swaggerui.WithReplaceServerUrls()); err != nil {
panic(err)
} else {
swaggerUI.Register(r)
}
webapp.Register(r)
validDomain := validPathVar("domain", regexNamed)
validName := validPathVar("name", regexNamed)
// Resolve endpoints
{
resolve := r.Group("/r")
resolve.Use(validDomain, validName)
resolve.GET("/:domain/:name", s.Resolve)
}
// Admin endpoints
{
admin := r.Group("/a")
admin.Use(validDomain)
// Domain
admin.POST("/domains/:domain", s.CreateDomain)
// PURL
admin.PUT("/domains/:domain/purls/:name", validName, s.SavePURL)
}
// System endpoints
{
sys := r.Group("/s")
sys.GET("/health", func(ctx *gin.Context) {
// currently no dedicated health check exists.
// in the future this should be extended with actual checks which signal if the application is ready
// to receive requests or not.
ctx.JSON(http.StatusOK, "service is ready to receive requests")
})
}
}