Files
herolib/aiprompts/herolib_core/core_globals.md
2025-10-12 12:30:19 +03:00

832 B

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.


module docsite

import incubaid.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()!
}