Skip to content

Commit

Permalink
track generic mounted packages, explicitly mark packages generic
Browse files Browse the repository at this point in the history
  • Loading branch information
krustowski committed Aug 1, 2024
1 parent f468f69 commit e218f97
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

APP_NAME=swis-api
APP_ROOT=/opt/${APP_NAME}
APP_VERSION=5.16.5
APP_VERSION=5.16.6


#
Expand Down
2 changes: 1 addition & 1 deletion cmd/swis-api/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @title swis-api (swapi) v5
// @version 5.16.5
// @version 5.16.6
// @description sakalWeb Information System v5 RESTful API documentation
// @termsOfService http://swagger.io/terms/

Expand Down
3 changes: 2 additions & 1 deletion pkg/alvax/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ var Package *core.Package = &core.Package{
Cache: []**core.Cache{
&Cache,
},
Routes: Routes,
Routes: Routes,
Generic: true,
}

// GetConfigs function dumps the alvax cache contents.
Expand Down
3 changes: 2 additions & 1 deletion pkg/backups/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ var Package *core.Package = &core.Package{
Cache: []**core.Cache{
&Cache,
},
Routes: Routes,
Routes: Routes,
Generic: true,
}

// @Summary Get all backed up services
Expand Down
3 changes: 2 additions & 1 deletion pkg/business/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ var Package *core.Package = &core.Package{
Cache: []**core.Cache{
&Cache,
},
Routes: Routes,
Routes: Routes,
Generic: true,
}

// @Summary Get all business entities
Expand Down
6 changes: 6 additions & 0 deletions pkg/core/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func MountMany(parentRouter *gin.Engine, systemCache **Cache, pkgs ...*Package)
}

var mountedPkgs []string
var genericPkgs []string

for _, pkg := range pkgs {
if pkg == nil {
Expand All @@ -23,11 +24,16 @@ func MountMany(parentRouter *gin.Engine, systemCache **Cache, pkgs ...*Package)

if mounted := MountPackage(parentRouter, pkg); mounted {
mountedPkgs = append(mountedPkgs, pkg.Name)

if pkg.Generic {
genericPkgs = append(genericPkgs, pkg.Name)
}
}
}

if systemCache != nil {
(*systemCache).Set("mounted", mountedPkgs)
(*systemCache).Set("generic", genericPkgs)
}
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/core/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
)

type Package struct {
Name string
Cache []**Cache
Routes func(r *gin.RouterGroup)
Name string
Cache []**Cache
Routes func(r *gin.RouterGroup)
Generic bool
}

func PrintAllRootItems(ctx *gin.Context, cache *Cache, pkgName string) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/links/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ var Package *core.Package = &core.Package{
Cache: []**core.Cache{
&Cache,
},
Routes: Routes,
Routes: Routes,
Generic: true,
}

// GetLinks returns JSON serialized list of links and their properties.
Expand Down
3 changes: 2 additions & 1 deletion pkg/roles/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ var Package *core.Package = &core.Package{
Cache: []**core.Cache{
&Cache,
},
Routes: Routes,
Routes: Routes,
Generic: true,
}

// GetRoles returns JSON serialized list of roles and their properties.
Expand Down
17 changes: 15 additions & 2 deletions pkg/system/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ var Package *core.Package = &core.Package{
Cache: []**core.Cache{
&Cache,
},
Routes: Routes,
Routes: Routes,
Generic: false,
}

func GetMountedPackages(ctx *gin.Context) {
func GetAllMountedPackages(ctx *gin.Context) {
items, _ := Cache.Get("mounted")

ctx.IndentedJSON(http.StatusOK, gin.H{
Expand All @@ -35,3 +36,15 @@ func GetMountedPackages(ctx *gin.Context) {
})
return
}

func GetGenericMountedPackages(ctx *gin.Context) {
items, _ := Cache.Get("generic")

ctx.IndentedJSON(http.StatusOK, gin.H{
"code": http.StatusOK,
"items": items,
"message": fmt.Sprintf("ok, listing generic package list"),
"package": pkgName,
})
return
}
6 changes: 4 additions & 2 deletions pkg/system/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

// system CRUD -- functions in controllers.go
func Routes(g *gin.RouterGroup) {
g.GET("/packages",
GetMountedPackages)
g.GET("/packages/mounted",
GetAllMountedPackages)
g.GET("/packages/generic",
GetGenericMountedPackages)
}
3 changes: 2 additions & 1 deletion pkg/users/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var Package *core.Package = &core.Package{
Cache: []**core.Cache{
&Cache,
},
Routes: Routes,
Routes: Routes,
Generic: true,
}

func FindUserByToken(token string) *User {
Expand Down

0 comments on commit e218f97

Please sign in to comment.