Skip to content

A simple implementation of the iconify server API as a Go module. Provides an HTTP handler to serve SVG icons or JSON data.

License

Notifications You must be signed in to change notification settings

andyburri/iconify-go

Repository files navigation

Iconify Server in Go

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.

Implemented Endpoints

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.

Usage

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)
	}
}

Add API url to web component

To use the local API, the API URL has to be added as a new IconifyProvider.

<script>
  IconifyProviders = {
    "": {
      resources: ["/icons"],
    },
  };
</script>

About

A simple implementation of the iconify server API as a Go module. Provides an HTTP handler to serve SVG icons or JSON data.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published