MCPcopy Create free account
hub / github.com/aptly-dev/aptly / Router

Function Router

api/router.go:51–245  ·  view source on GitHub ↗

Router returns prebuilt with routes http.Handler

(c *ctx.AptlyContext)

Source from the content-addressed store, hash-verified

49
50// Router returns prebuilt with routes http.Handler
51func Router(c *ctx.AptlyContext) http.Handler {
52 if aptly.EnableDebug {
53 gin.SetMode(gin.DebugMode)
54 } else {
55 gin.SetMode(gin.ReleaseMode)
56 }
57
58 router := gin.New()
59 context = c
60
61 router.UseRawPath = true
62
63 if c.Config().LogFormat == "json" {
64 gin.DefaultWriter = utils.LogWriter{Logger: log.Logger}
65 router.Use(JSONLogger())
66 } else {
67 router.Use(gin.Logger())
68 }
69
70 router.Use(gin.Recovery(), gin.ErrorLogger())
71
72 if c.Config().EnableSwaggerEndpoint {
73 router.GET("docs.html", func(c *gin.Context) {
74 c.Data(http.StatusOK, "text/html; charset=utf-8", docs.DocsHTML)
75 })
76 router.Use(redirectSwagger)
77 url := ginSwagger.URL("/docs/doc.json")
78 router.GET("/docs/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url))
79 }
80
81 if c.Config().EnableMetricsEndpoint {
82 MetricsCollectorRegistrar.Register(router)
83 }
84
85 if c.Config().ServeInAPIMode {
86 router.GET("/repos/", reposListInAPIMode(c.Config().FileSystemPublishRoots))
87 router.GET("/repos/:storage/*pkgPath", reposServeInAPIMode)
88 }
89
90 api := router.Group("/api")
91 if context.Flags().Lookup("no-lock").Value.Get().(bool) {
92 // We use a goroutine to count the number of
93 // concurrent requests. When no more requests are
94 // running, we close the database to free the lock.
95 dbRequests = make(chan dbRequest)
96
97 go acquireDatabase()
98
99 api.Use(func(c *gin.Context) {
100 var err error
101
102 errCh := make(chan error)
103 dbRequests <- dbRequest{acquiredb, errCh}
104
105 err = <-errCh
106 if err != nil {
107 AbortWithJSONError(c, 500, err)
108 return

Callers 4

aptlyAPIServeFunction · 0.92
setupContextMethod · 0.85
SetUpTestMethod · 0.85
SetUpSuiteMethod · 0.85

Calls 11

JSONLoggerFunction · 0.85
reposListInAPIModeFunction · 0.85
acquireDatabaseFunction · 0.85
AbortWithJSONErrorFunction · 0.85
apiMetricsGetFunction · 0.85
apiReadyFunction · 0.85
ConfigMethod · 0.80
URLMethod · 0.80
RegisterMethod · 0.80
FlagsMethod · 0.80
GetMethod · 0.65

Tested by 3

setupContextMethod · 0.68
SetUpTestMethod · 0.68
SetUpSuiteMethod · 0.68