gfonts

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2020 License: BSD-3-Clause Imports: 8 Imported by: 1

README

gfonts

Go bindings for the Google Fonts Developer API.

godoc

cmd/gfonts

This command downloads fonts from the API.

Usage of gfonts:
  -c	concurrent downloads mode
  -category value
    	set the category to filter for, can be passed multiple times
  -flat
    	use a flat file structure
  -j int
    	number of threads to use for downloading (default 64)
  -key string
    	API key for google fonts (required)
  -n int
    	number of font families to download, n <= -1 means unlimited (default 1)
  -sort string
    	sorting mode, valid values are alpha, date, popularity, style, trending. (default "popularity")
  -style value
    	set the style to filter for, can be passed multiple times
  -subset value
    	set the subset to filter for, can be passed multiple times
  -t int
    	max attempts to try downloading every file (default 3)

cmd/gfonts-analyzer

This command gets and shows a response from the API/tool

Usage of gfonts-analyzer:
  -category value
    	set the category to filter for, can be passed multiple times
  -dedup
    	deduplicate results
  -key string
    	API key
  -n int
    	number of font families to download, n < 0 means unlimited (default -1)
  -sort
    	sort results
  -sortmode string
    	sort mode, one of alpha, date, popularity, style, trending
  -style value
    	set the style to filter for, can be passed multiple times
  -subset value
    	set the subset to filter for, can be passed multiple times

cmd/gfonts-match

This command gets a response from the API and will find the closest font that matches the given query.

Usage of gfonts-match:
  -b value
    	bags of n-grams, can pass more than one (default "2,3,4")
  -k string
    	API key
  -n int
    	number of outputs to print in verbose mode (default 8)
  -v	verbose output

Documentation

Overview

Package gfonts provides bindings for the Google Fonts Developer API.

Index

Constants

View Source
const (
	SortAlpha      = "alpha"
	SortDate       = "date"
	SortPopularity = "popularity"
	SortStyle      = "style"
	SortTrending   = "trending"
)

Sort modes for the API

Variables

View Source
var (
	SortModes = []string{SortAlpha, SortDate, SortPopularity, SortStyle, SortTrending}

	ErrNoKey = errors.New("empty API key")
)

Functions

This section is empty.

Types

type APIResponse

type APIResponse struct {
	Kind  string `json:"kind"`
	Items []struct {
		Kind         string            `json:"kind"`
		Family       string            `json:"family"`
		Category     string            `json:"category"`
		Version      string            `json:"version"`
		LastModified string            `json:"lastModified"`
		Subsets      []string          `json:"subsets"`
		Variants     []string          `json:"variants"`
		Files        map[string]string `json:"files"`
	} `json:"items"`
}

type Family

type Family struct {
	Name         string
	Category     string
	Version      string
	LastModified time.Time
	Subsets      []string

	// Fonts is a map of style to URL
	Fonts map[string]string
}

Family is a collection of font styles.

type Response

type Response []Family

Response is a slice of Family, satisfies json.Unmarshaler and download.Interface.

func Get

func Get(key, sort string) (r *Response, err error)

Get a response with all the available fonts from google fonts.

func (*Response) Categories

func (r *Response) Categories(valid ...string) *Response

Categories filters out fonts that are not in any of those categories. Passing no valid categories will not filter out anything.

func (*Response) Filter

func (r *Response) Filter(fn func(Family) bool) *Response

Filter a response, will run fn on every family.

func (*Response) Styles

func (r *Response) Styles(valid ...string) *Response

Styles filters out fonts that don't have any of the valid styles. The returned response will only have valid styles. Passing no valid styles will not filter out anything.

func (*Response) Subsets

func (r *Response) Subsets(valid ...string) *Response

Subsets filters out fonts that don't have any of the valid subsets. Passing no valid subsets will not filter out anything.

func (*Response) Trim

func (r *Response) Trim(n int) *Response

Trim response down to len(response) == n. Passing n <= 0 or n > len(response) will not trim anything.

func (*Response) URLs

func (r *Response) URLs() (files []download.File)

URLs satisfies download.Interface.

func (*Response) UnmarshalJSON

func (r *Response) UnmarshalJSON(b []byte) error

UnmarshalJSON satisfies json.Unmarshaler.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL