This is a simple implementation of the iconify server API as a Go module. It provides an HTTP handler to serve SVG icons or JSON data.
| Endpoint | Handler | Description |
|---|---|---|
| /{prefix}.json?icons={icons} | json |
Returns JSON data for the specified icons. |
| /{prefix}/{icon}.svg | svg |
Returns SVG image. Supports query parameters for color, width, and height. |
Instantiate the Server with
iconifygo.NewIconifyServer(basePath, iconsetPath, handlers...)where basePath is the base path for serving icons and iconsetPath is the path to the directory containing the icon sets.
handlers is a slice of strings that specifies which handlers to enable. The default is ["all"], which enables all handlers.
Available handlers are svg and json or all. See Implemented Endpoints for the handled endpoints.
Register the Handler like so:
http.HandleFunc("GET /icons", iconify.HandlerFunc(), "svg", "json")The following example handles the /icons endpoint. It serves the JSON files from the ./iconsets directory.
import (
"net/http"
iconifygo "github.com/andyburri/iconify-go"
)
func main() {
mux := http.NewServeMux()
iconify := iconifygo.NewIconifyServer("/icons/", "./iconsets")
mux.HandleFunc("/icons/", iconify.HandlerFunc())
err := http.ListenAndServe(":8080", mux)
if err != nil {
panic(err)
}
}To use the local API, the API URL has to be added as a new IconifyProvider.
<script>
IconifyProviders = {
"": {
resources: ["/icons"],
},
};
</script>