The fluent builder for constructing an IconManager with multiple providers, attribute defaults, aliases, and fallbacks.
Overview
Config is a fluent builder for constructing an IconManager. Chain configuration methods and call Build to produce a fully configured manager.
For guides on the features configured through the builder, see Aliases & Fallbacks and Attribute Management.
Types
Config
type Config struct { // unexported fields}Functions
NewConfig
func NewConfig() *ConfigCreates an empty Config ready for method chaining.
Methods
All methods return *Config for chaining unless noted otherwise.
Provider registration
AddProvider
func (c *Config) AddProvider(prefix string, provider Provider) *ConfigRegisters a pre-built provider under prefix. Immediate: the provider is used as-is during Build.
AddDirectory
func (c *Config) AddDirectory(prefix, dir string) *ConfigRegisters a DirectoryProvider for dir under prefix. Deferred: the provider is constructed during Build. Returns an error from Build if the directory is invalid.
AddJsonCollection
func (c *Config) AddJsonCollection(prefix, path string) *ConfigRegisters a JsonCollectionProvider for the JSON file at path under prefix. Deferred: the file is read during Build. Returns an error from Build if the file cannot be read.
AddIconifySet
func (c *Config) AddIconifySet(prefix string) *ConfigRegisters an IconifyProvider under prefix. Deferred: the provider is constructed during Build.
AddHybridSet
func (c *Config) AddHybridSet(prefix, dir string) *ConfigRegisters a ChainProvider combining a DirectoryProvider (for dir) and an IconifyProvider, both under prefix. The directory is checked first. Deferred: both providers are constructed during Build. Returns an error from Build if the directory is invalid.
DiscoverJsonSets
func (c *Config) DiscoverJsonSets(dir string) *ConfigScans dir for *.json files and registers each as a JsonCollectionProvider using the filename (without extension) as the prefix. Files are sorted alphabetically. Silently skips the call if the glob fails. Deferred.
Attribute configuration
DefaultPrefix
func (c *Config) DefaultPrefix(prefix string) *ConfigSets the prefix used when Get receives a bare name with no colon.
DefaultAttributes
func (c *Config) DefaultAttributes(attrs map[string]string) *ConfigSets attributes applied globally to every icon at layer 2 (after the icon's own attributes). Calling this method multiple times is additive: later calls merge into earlier ones.
PrefixAttributes
func (c *Config) PrefixAttributes(prefix string, attrs map[string]string) *ConfigSets attributes applied to all icons from prefix at layer 3. Calling multiple times for the same prefix is additive.
PrefixSuffix
func (c *Config) PrefixSuffix(prefix, suffix string, attrs map[string]string) *ConfigSets attributes applied at layer 4 to icons under prefix whose name ends with "-{suffix}". Pass an empty suffix as a catch-all for icons under that prefix that match no other suffix.
Resolution configuration
Alias
func (c *Config) Alias(alias, target string) *ConfigMaps alias to target. When Get(alias) is called, the target name is substituted before resolution.
FallbackIcon
func (c *Config) FallbackIcon(name string) *ConfigSets the global fallback icon name returned when a requested icon is not found.
FallbackIconForPrefix
func (c *Config) FallbackIconForPrefix(prefix, name string) *ConfigSets a fallback icon used only when an icon from prefix is not found. Checked before the global fallback.
IgnoreNotFound
func (c *Config) IgnoreNotFound() *ConfigConfigures the built manager to return an empty *Icon (no error) instead of ErrIconNotFound or ErrProviderNotFound.
Terminal
Build
func (c *Config) Build() (*IconManager, error)Constructs and returns an IconManager from the accumulated configuration. Initializes all deferred providers and returns an error if any provider fails to load. The IconRenderer is built from the configured default, prefix, and suffix attributes.
Deferred vs. immediate
| Method | Construction |
|---|---|
AddProvider |
Immediate: provider passed as-is. |
AddDirectory |
Deferred: NewDirectoryProvider called during Build. |
AddJsonCollection |
Deferred: NewJsonCollectionProvider called during Build. |
AddIconifySet |
Deferred: NewIconifyProvider called during Build. |
AddHybridSet |
Deferred: NewDirectoryProvider + NewIconifyProvider + NewChainProvider during Build. |
DiscoverJsonSets |
Deferred: glob runs immediately, but providers constructed during Build. |
Example
import ( swarmicons "github.com/frostybee/go-swarm-icons" "github.com/frostybee/go-swarm-icons/lucide")manager, err := swarmicons.NewConfig(). AddProvider("lucide", lucide.Provider()). AddDirectory("custom", "./icons"). AddIconifySet("mdi"). DefaultPrefix("lucide"). DefaultAttributes(map[string]string{ "fill": "none", "stroke": "currentColor", "stroke-width": "2", }). PrefixAttributes("mdi", map[string]string{ "fill": "currentColor", }). Alias("check", "lucide:check-circle"). FallbackIcon("lucide:help-circle"). IgnoreNotFound(). Build()See also
- Providers API reference: constructor signatures and methods for each provider type
- Installation: which modules to install for each provider type