1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 18:07:01 +00:00

add on-site documentation for the new 'apps' subpackage

This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-08-21 04:19:13 +03:00
parent cb80e43ff0
commit 02c85c27cc
4 changed files with 257 additions and 43 deletions

View File

@@ -8,11 +8,29 @@ import (
"github.com/kataras/iris/v12/context"
)
// Get returns an existing Iris Application based on its "appName".
// Applications of the same program
// are registered automatically.
func Get(appName string) *iris.Application {
if app, ok := context.GetApplication(appName); ok {
// Get returns an Iris Application based on its "appName".
// It returns nil when no application was found with the given exact name.
//
// If "appName" parameter is missing then it returns the last registered one.
// When no application is registered yet then it creates a new on-fly
// with a "Default" name and returns that instead.
// The "Default" one can be used across multiple Go packages
// of the same Program too.
//
// Applications of the same program are registered automatically.
//
// To check if at least one application is registered or not
// use the `GetAll` function instead.
func Get(appName ...string) *iris.Application {
if len(appName) == 0 || appName[0] == "" {
if app := context.LastApplication(); app != nil {
return app.(*iris.Application)
}
return iris.New().SetName("Default")
}
if app, ok := context.GetApplication(appName[0]); ok {
return app.(*iris.Application)
}
@@ -30,25 +48,3 @@ func GetAll() []*iris.Application {
return apps
}
// Configure applies one or more configurator to the
// applications with the given "appNames".
//
// See `ConfigureAll` too.
func Configure(appNames []string, configurators ...iris.Configurator) {
for _, appName := range appNames {
if app := Get(appName); app != nil {
app.Configure(configurators...)
}
}
}
// ConfigureAll applies one or more configurator to all
// registered applications so far.
//
// See `Configure` too.
func ConfigureAll(configurators ...iris.Configurator) {
for _, app := range context.GetApplications() {
app.(*iris.Application).Configure(configurators...)
}
}