Skip to content

Commit 82f6200

Browse files
committed
Add some documentation to packages
In go-gitea#21637 it was mentioned that the purpose of the API routes for the packages is unclear. This PR adds some documentation. Fix go-gitea#21637 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 9a70a12 commit 82f6200

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

routers/api/packages/api.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ func reqPackageAccess(accessMode perm.AccessMode) func(ctx *context.Context) {
4040
}
4141
}
4242

43-
func Routes(ctx gocontext.Context) *web.Route {
43+
// CommonRoutes provide endpoints for most package managers (excepting docker HUB - see below)
44+
// These are mounted on `/api/packages` (not `/api/v1/packages`)
45+
func CommonRoutes(ctx gocontext.Context) *web.Route {
4446
r := web.NewRoute()
4547

4648
r.Use(context.PackageContexter(ctx))
@@ -301,7 +303,9 @@ func Routes(ctx gocontext.Context) *web.Route {
301303
return r
302304
}
303305

304-
func ContainerRoutes(ctx gocontext.Context) *web.Route {
306+
// DockerContainerRoutes provides endpoints that match the Docker HUB API in order for facilitate downloading packages a docker packages
307+
// These have to be mounted on `/v2/...` due to compatibility with the Docker HUB API
308+
func DockerContainerRoutes(ctx gocontext.Context) *web.Route {
305309
r := web.NewRoute()
306310

307311
r.Use(context.PackageContexter(ctx))

routers/api/v1/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,7 @@ func Routes(ctx gocontext.Context) *web.Route {
10731073
}, repoAssignment())
10741074
})
10751075

1076+
// NOTE: these are Gitea package management API - see packages.CommonRoutes and packages.DockerContainerRoutes for endpoints to see implementations of package manager APIs
10761077
m.Group("/packages/{username}", func() {
10771078
m.Group("/{type}/{name}/{version}", func() {
10781079
m.Get("", packages.GetPackage)

routers/init.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,15 @@ func NormalRoutes(ctx context.Context) *web.Route {
185185
r.Mount("/", web_routers.Routes(ctx))
186186
r.Mount("/api/v1", apiv1.Routes(ctx))
187187
r.Mount("/api/internal", private.Routes())
188+
188189
if setting.Packages.Enabled {
189-
r.Mount("/api/packages", packages_router.Routes(ctx))
190-
r.Mount("/v2", packages_router.ContainerRoutes(ctx))
190+
// Add endpoints to match common package manager APIs
191+
192+
// This implements package support for most package managers
193+
r.Mount("/api/packages", packages_router.CommonRoutes(ctx))
194+
195+
// This implements Docker HUB API (Note this is not preceded by /api but is instead /v2)
196+
r.Mount("/v2", packages_router.DockerContainerRoutes(ctx))
191197
}
192198
return r
193199
}

0 commit comments

Comments
 (0)