Skip to content

osspkg/go-badges

Repository files navigation

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.