Install the package
$ go get github.com/bubblestudent/gocolournamer
Then add the import to the top of whichever file you want to use the package in
import "github.com/bubblestudent/gocolournamer"
All of the packages functionality is exposed in one method. ToNearestColour is called with a valid hex colour and returns the named struct and an error.
named, err := gocolournamer.ToNearestColour(hexstring)
Additional documentation available on godoc: http://godoc.org/github.com/bubblestudent/gocolournamer
package main
import (
"encoding/json"
"fmt"
"github.com/bubblestudent/gocolournamer"
)
func main() {
hex := "#905E26" //hash is optional
named, err := gocolournamer.ToNearestColour(hex)
if err != nil {
fmt.Println(err.Error())
return
}
out, _ := json.Marshal(named)
fmt.Printf("%s", string(out))
}
The above program outputs
{"hex":"905E26","colour":"Afghan Tan","hue":"Yellow","huehex":"FFFF00"}
Idea and colour list from http://chir.ag/projects/ntc/ javascript implementation.
Distributed free for any use under an MIT licence.