Skip to content

Commit

Permalink
improve pkg registration in main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
krustowski committed Jun 8, 2024
1 parent f9e645c commit b883392
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 51 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.1
APP_VERSION=5.16.2


#
Expand Down
63 changes: 13 additions & 50 deletions 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.1
// @version 5.16.2
// @description sakalWeb Information System v5 RESTful API documentation
// @termsOfService http://swagger.io/terms/

Expand Down Expand Up @@ -126,65 +126,28 @@ func main() {
// swis pkg registration
//

// alvax CRUD
alvax.Cache = &core.Cache{}
alvax.Routes(router.Group("/alvax"))

// backups CRUD
backups.Cache = &core.Cache{}
backups.Routes(router.Group("/backups"))

// business CRUD
business.Cache = &core.Cache{}
business.Routes(router.Group("/business"))

// depots CRUD
depots.Cache = &core.Cache{}
depots.Routes(router.Group("/depots"))

// dish CRUD
dish.Dispatcher = dish.NewDispatcher()
dish.CacheIncidents = &core.Cache{}
dish.CacheSockets = &core.Cache{}
dish.Routes(router.Group("/dish"))

// finance accounts CRUD
finance.CacheAccounts = &core.Cache{}
finance.CacheItems = &core.Cache{}
finance.Routes(router.Group("/finance"))

// infra CRUD
infra.CacheHosts = &core.Cache{}
infra.CacheNetworks = &core.Cache{}
infra.CacheDomains = &core.Cache{}
infra.Routes(router.Group("/infra"))

// links CRUD
links.Cache = &core.Cache{}
links.Routes(router.Group("/links"))

// news CRUD
news.Cache = &core.Cache{}
news.Routes(router.Group("/news"))

// projects and queue pkgis registration

core.MountPackage(router, alvax.Package)
core.MountPackage(router, backups.Package)
core.MountPackage(router, business.Package)
core.MountPackage(router, depots.Package)
core.MountPackage(router, dish.Package)
core.MountPackage(router, finance.Package)
core.MountPackage(router, infra.Package)
core.MountPackage(router, links.Package)
core.MountPackage(router, news.Package)
core.MountPackage(router, projects.Package)
core.MountPackage(router, queue.Package)
core.MountPackage(router, roles.Package)
core.MountPackage(router, users.Package)

// bulk registration and mounting of packages
/*core.RegisterAndMount(router,
projects.Package,
roles.Package,
)*/

// roles CRUD
roles.Cache = &core.Cache{}
roles.Routes(router.Group("/roles"))

// users CRUD
users.Cache = &core.Cache{}
users.Routes(router.Group("/users"))

// attach router to http.Server and start it, check for SERVER_PORT env variable
if os.Getenv("SERVER_PORT") == "" {
log.Fatal("SERVER_PORT environment variable not provided! refusing to start the server...")
Expand Down
8 changes: 8 additions & 0 deletions pkg/alvax/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ var (
pkgName string = "alvax"
)

var Package *core.Package = &core.Package{
Name: pkgName,
Cache: []**core.Cache{
&Cache,
},
Routes: Routes,
}

// GetConfigs function dumps the alvax cache contents.
// @Summary Get all alvax configs
// @Description get alvax config list
Expand Down
8 changes: 8 additions & 0 deletions pkg/backups/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ var (
pkgName string = "backups"
)

var Package *core.Package = &core.Package{
Name: pkgName,
Cache: []**core.Cache{
&Cache,
},
Routes: Routes,
}

// @Summary Get all backed up services
// @Description get backed up services
// @Tags backups
Expand Down
8 changes: 8 additions & 0 deletions pkg/business/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ var (
pkgName string = "business"
)

var Package *core.Package = &core.Package{
Name: pkgName,
Cache: []**core.Cache{
&Cache,
},
Routes: Routes,
}

// @Summary Get all business entities
// @Description get business entities list
// @Tags business
Expand Down
8 changes: 8 additions & 0 deletions pkg/depots/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ var (
pkgName string = "depots"
)

var Package *core.Package = &core.Package{
Name: pkgName,
Cache: []**core.Cache{
&Cache,
},
Routes: Routes,
}

// GetAllDepotItems GET method
//
// @Summary Get all depots and their users/owners
Expand Down
9 changes: 9 additions & 0 deletions pkg/dish/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ var (
pkgName string = "dish"
)

var Package *core.Package = &core.Package{
Name: pkgName,
Cache: []**core.Cache{
&CacheIncidents,
&CacheSockets,
},
Routes: Routes,
}

/*
sockets
Expand Down
9 changes: 9 additions & 0 deletions pkg/finance/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ var (
pkgName string = "finance"
)

var Package *core.Package = &core.Package{
Name: pkgName,
Cache: []**core.Cache{
&CacheAccounts,
&CacheItems,
},
Routes: Routes,
}

/*
accounts
Expand Down
10 changes: 10 additions & 0 deletions pkg/infra/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ var (
pkgName string = "infra"
)

var Package *core.Package = &core.Package{
Name: pkgName,
Cache: []**core.Cache{
&CacheDomains,
&CacheHosts,
&CacheNetworks,
},
Routes: Routes,
}

// @Summary Get whole infrastructure
// @Description get all infrastructure details
// @Tags infra
Expand Down
8 changes: 8 additions & 0 deletions pkg/links/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ var (
pkgName string = "links"
)

var Package *core.Package = &core.Package{
Name: pkgName,
Cache: []**core.Cache{
&Cache,
},
Routes: Routes,
}

// GetLinks returns JSON serialized list of links and their properties.
// @Summary Get all links
// @Description get links complete list
Expand Down
8 changes: 8 additions & 0 deletions pkg/news/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ var (
pkgName string = "news"
)

var Package *core.Package = &core.Package{
Name: pkgName,
Cache: []**core.Cache{
&Cache,
},
Routes: Routes,
}

// GetSources
// @Summary Get news source list
// @Description get all news sources
Expand Down
8 changes: 8 additions & 0 deletions pkg/roles/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ var (
pkgName string = "roles"
)

var Package *core.Package = &core.Package{
Name: pkgName,
Cache: []**core.Cache{
&Cache,
},
Routes: Routes,
}

// GetRoles returns JSON serialized list of roles and their properties.
// @Summary Get all roles
// @Description get roules complete list
Expand Down
8 changes: 8 additions & 0 deletions pkg/users/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ var (
pkgName string = "users"
)

var Package *core.Package = &core.Package{
Name: pkgName,
Cache: []**core.Cache{
&Cache,
},
Routes: Routes,
}

func FindUserByToken(token string) *User {
rawUsers, _ := Cache.GetAll()

Expand Down

0 comments on commit b883392

Please sign in to comment.