badges

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: BSD-3-Clause Imports: 8 Imported by: 1

README

go-badges

Release Go Report Card CI

Install

go get -u go.osspkg.com/badges

Colors

ColorPrimary  
ColorSecondary 
ColorSuccess   
ColorDanger   
ColorWarning  
ColorInfo      
ColorLight

Examples

package main

import (
	"net/http"

	"go.osspkg.com/badges"
)

func main() {
	b, err := badges.New()
	if err != nil {
		panic(err)
	}

	http.Handle("/image.svg", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		title := r.URL.Query().Get("title")
		content := r.URL.Query().Get("data")

		err = b.WriteResponse(w, badges.ColorInfo, title, content)
		if err != nil {
			panic(err)
		}
	}))

	http.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		_, err = w.Write([]byte("<html><body><img src=\"/image.svg?title=User ID&data=12 34 567890\"></body></html>"))
		if err != nil {
			panic(err)
		}
	}))

	if err = http.ListenAndServe(":8080", nil); err != nil {
		panic(err)
	}
}

License

BSD-3-Clause License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ColorPrimary   = Color{TitleBG: "#555", TitleFont: "#fff", DataBG: "#0d6efd", DataFont: "#fff"}
	ColorSecondary = Color{TitleBG: "#555", TitleFont: "#fff", DataBG: "#6c757d", DataFont: "#fff"}
	ColorSuccess   = Color{TitleBG: "#555", TitleFont: "#fff", DataBG: "#198754", DataFont: "#fff"}
	ColorDanger    = Color{TitleBG: "#555", TitleFont: "#fff", DataBG: "#dc3545", DataFont: "#fff"}
	ColorWarning   = Color{TitleBG: "#555", TitleFont: "#fff", DataBG: "#ffc107", DataFont: "#000"}
	ColorInfo      = Color{TitleBG: "#555", TitleFont: "#fff", DataBG: "#0dcaf0", DataFont: "#000"}
	ColorLight     = Color{TitleBG: "#555", TitleFont: "#fff", DataBG: "#f8f9fa", DataFont: "#000"}
)

Functions

This section is empty.

Types

type Badges

type Badges struct {
	// contains filtered or unexported fields
}

func New

func New() (*Badges, error)

func (*Badges) Write

func (v *Badges) Write(w io.Writer, color Color, title, data string) error

Write generate badge and write it to io.Writer

func (*Badges) WriteResponse

func (v *Badges) WriteResponse(w http.ResponseWriter, color Color, title, data string) error

WriteResponse generate badge and write it to http.Response

type Color

type Color struct {
	TitleBG   string
	TitleFont string
	DataBG    string
	DataFont  string
}

Color model

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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