This commit is contained in:
2025-07-30 18:51:29 +02:00
parent 1cb6c486df
commit 14d8d5af8d
14 changed files with 203 additions and 241 deletions

View File

@@ -0,0 +1,44 @@
## how to remember clients, installers as a global
the following is a good pragmatic way to remember clients, installers as a global, use it as best practice.
```vmodule docsite
module docsite
import freeflowuniverse.herolib.core.texttools
__global (
siteconfigs map[string]&SiteConfig
)
@[params]
pub struct FactoryArgs {
pub mut:
name string = "default"
}
pub fn new(args FactoryArgs) !&SiteConfig {
name := texttools.name_fix(args.name)
siteconfigs[name] = &SiteConfig{
name: name
}
return get(name:name)!
}
pub fn get(args FactoryArgs) !&SiteConfig {
name := texttools.name_fix(args.name)
mut sc := siteconfigs[name] or {
return error('siteconfig with name "${name}" does not exist')
}
return sc
}
pub fn default() !&SiteConfig {
if siteconfigs.len == 0 {
return new(name:'default')!
}
return get()!
}
```