shields

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: MIT Imports: 2 Imported by: 2

README

Shields.io Go SDK for creating an endpoint.

Build Status Coverage Status Go.Dev reference Go Report Card Release

$ go get -u clevergo.tech/shields
import (
	"encoding/json"
	"net/http"

	"clevergo.tech/shields"
)

func handler(w http.ResponseWriter, req *http.Request) {
    badge := shields.New("label", "message")
    badge.LabelColor = shields.ColorBlue
    err := badge.ParseRequest(req)
    if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }

    data, err := json.Marshal(badge)
    if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }

    w.Header().Set("Content-Type", "application/json")
    w.Write(data)
}

Documentation

Index

Constants

View Source
const (
	ColorBlue        = "blue"
	ColorBrightGreen = "brightgreen"
	ColorGreen       = "green"
	ColorLightGrey   = "lightgrey"
	ColorOrange      = "orange"
	ColorRed         = "red"
	ColorYellow      = "yellow"
	ColorYellowGreen = "yellowgreen"
)

Colors

View Source
const (
	StyleFlat        = "flat"
	StyleFlatSquare  = "flat-square"
	StyleForTheBadge = "for-the-badge"
	StylePlastic     = "plastic"
	StyleSocial      = "social"
)

Styles

Variables

This section is empty.

Functions

This section is empty.

Types

type Badge

type Badge struct {
	// Schema version. Always the number 1.
	// Required.
	Version int `json:"schemaVersion" schema:"-"`

	// The left text, or the empty string to omit the left side of the badge.
	// Required.
	Label string `json:"label" schema:"label"`

	// The right text.
	// Required.
	Message string `json:"message" schema:"-"`

	// The right color. Supports the eight named colors above,
	// as well as hex, rgb, rgba, hsl, hsla and css named colors.
	// Default: lightgrey.
	Color string `json:"color,omitempty" schema:"color"`

	// The left color.
	// Default: grey.
	LabelColor string `json:"labelColor,omitempty" schema:"labelColor"`

	// true to treat this as an error badge. This prevents the user from overriding the color.
	// In the future it may affect cache behavior.
	// Default: false.
	IsError bool `json:"isError,omitempty" schema:"-"`

	// Default: none.
	NamedLogo string `json:"namedLogo,omitempty" schema:"namedLogo"`

	// An SVG string containing a custom logo.
	// Default: none.
	LogoSvg string `json:"logoSvg,omitempty" schema:"logoSvg"`

	// Logo color.
	// Default: none.
	LogoColor string `json:"logoColor,omitempty" schema:"logoColor"`

	// The horizontal space to give to the logo.
	// Default: none.
	LogoWidth string `json:"logoWidth,omitempty" schema:"logoWidth"`

	// Logo position.
	// Default: none.
	LogoPosition string `json:"logoPosition,omitempty" schema:"logoPosition"`

	// The default template to use.
	// Default: flat.
	Style string `json:"style,omitempty" schema:"style"`

	// Set the HTTP cache lifetime in seconds, which should be respected by the Shields' CDN and downstream users.
	// Default: 300.
	CacheSeconds int `json:"cacheSeconds,omitempty" schema:"-"`
}

Badge is the endpoint schema of shields.io.

func New

func New(label, message string) *Badge

New returns a badge with the given label and message.

func (*Badge) ParseRequest added in v0.2.0

func (badge *Badge) ParseRequest(req *http.Request) error

ParseRequest parses request query params.

Jump to

Keyboard shortcuts

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