Back to godoc.org
git.sr.ht/~mendelmaleh/gfonts

Package gfonts

v0.1.0
Latest Go to latest

The latest major version is .

Published: Jun 5, 2020 | License: BSD-3-Clause | Module: git.sr.ht/~mendelmaleh/gfonts

Overview

Package gfonts provides bindings for the Google Fonts Developer API.

Index

Constants

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

Sort modes for the API

Variables

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

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

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.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier