This guide walks through installing go-swarm-icons, setting up a manager with the embedded Lucide icon set, and rendering an SVG icon to HTML. At the end, the project will have a working icon pipeline that handles sanitization and accessibility attributes out of the box.
Install
This example needs the core library and the Lucide icon set:
go get github.com/frostybee/go-swarm-icons@latestgo get github.com/frostybee/go-swarm-icons/lucide@latestSee Installation for the Goldmark submodule, module details, and which modules a project actually needs.
Render an icon
swarmicons.Default() sets up a manager with one provider. The first argument is the prefix, and that prefix doubles as the default, so Get("home") works without writing Get("lucide:home").
package mainimport ( "fmt" swarmicons "github.com/frostybee/go-swarm-icons" "github.com/frostybee/go-swarm-icons/lucide")func main() { manager := swarmicons.Default("lucide", lucide.Provider()) icon, err := manager.Get("home") if err != nil { panic(err) } fmt.Println(icon.ToHTML())}Output:
<svg aria-hidden="true" focusable="false" height="24" viewBox="0 0 24 24" width="24">...</svg>ARIA attributes (aria-hidden, focusable) are injected automatically. The SVG content is sanitized before it reaches the output.
Resize and style
Every method on *Icon returns a new copy, so the original stays untouched.
html := icon.Size(24).Class("text-blue").Fill("currentColor").ToHTML()Attributes can also go through Get() directly:
icon, err := manager.Get("home", map[string]string{ "class": "nav-icon", "id": "home-btn",})Caller-supplied attributes take the highest precedence. The class attribute concatenates rather than replaces.
Beyond Lucide
The swarm-icons CLI downloads Tabler, Heroicons, Material Design, or any of the other 200+ Iconify sets from the npm registry (no Node.js required), and JsonCollectionProvider serves them at runtime:
go install github.com/frostybee/go-swarm-icons/cmd/swarm-icons@latestswarm-icons json download tablerWorking with Icon Sets walks through the full workflow, from browsing the catalog to registering the provider.
What's next
- Core Concepts: providers, prefixes, attribute layers, and how they fit together
- Working with Icon Sets: add Tabler, Heroicons, Material Design, or any other Iconify set
- Icon Manipulation:
Rotate,Flip,Opacity,Title, and the rest of the fluent API - Providers: directories, JSON files, the Iconify HTTP API, or all of them at once