54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package Managers
|
|
|
|
import (
|
|
"AnP/Models"
|
|
"AnP/Utils"
|
|
)
|
|
|
|
type ApplicationsManager struct {
|
|
anp Models.AnPModel
|
|
applications map[string]Models.ApplicationModel
|
|
}
|
|
|
|
func NewApplicationsManager(anp Models.AnPModel) ApplicationsManager {
|
|
|
|
var module ApplicationsManager = ApplicationsManager{
|
|
anp: anp,
|
|
applications: map[string]Models.ApplicationModel{},
|
|
}
|
|
|
|
for _, key := range []string{
|
|
"default_applications_files", "applications_files",
|
|
"default_applications", "applications",
|
|
} {
|
|
module.Add(anp.Settings.Get(key, nil, nil), true)
|
|
}
|
|
|
|
return module
|
|
}
|
|
|
|
func (_self *ApplicationsManager) Add(inputs any, overwrite bool) {
|
|
_self.anp.Request.LoadJSON(inputs, func(response any) {
|
|
for key, data := range Utils.Get[map[string]any](inputs, nil) {
|
|
_, exists := _self.applications[key]
|
|
if overwrite || !exists {
|
|
_self.applications[key] = Models.NewApplicationModel(_self.anp, NewRoutesManager(_self.anp, data), data)
|
|
}
|
|
}
|
|
}, true)
|
|
}
|
|
|
|
func (_self ApplicationsManager) Go(domain string, method string, url string) map[string]any {
|
|
|
|
var response map[string]any = GetDefaultHTTPResponse()
|
|
var done bool
|
|
|
|
for _, application := range _self.applications {
|
|
if response, done = application.Routes.Go(domain, method, url, application.GetAttributes()); done {
|
|
break
|
|
}
|
|
}
|
|
|
|
return response
|
|
}
|