shieldeddotdev

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 24 Imported by: 0

README

Shielded.dev

CI Last Update

Free badges for your README files. Make a badge. Put it in a project. Update it when your work changes.

Start with Shielded.dev

Use the hosted service unless you need to run your own copy. It is free. It is ready at shielded.dev.

  1. Visit shielded.dev.
  2. Sign in with GitHub.
  3. Create a shield.
  4. Copy the Markdown from the shield page into your README.

Your public badge uses a stable image address like this:

![Build](https://img.shielded.dev/s/your-public-id)

The shield page gives you the real address. It also gives you a private update token. Keep that token out of your README, source code, or public logs.

Update a shield from a script

Use the shield token when a script needs to update one shield.

curl -X POST https://api.shielded.dev/ \
  -H 'Authorization: token <your-shield-token>' \
  --data-urlencode 'title=Build' \
  --data-urlencode 'text=passing' \
  --data-urlencode 'color=00aa55'

You can change title, text, color. Leave out any value you do not want to change.

Update several shields

The User tokens page can create a token for several shields. Give each shield a key. Use that key with the user token.

curl -X POST https://api.shielded.dev/ \
  -H 'Authorization: token <your-full-user-token>' \
  --data-urlencode 'shield_key=main-build' \
  --data-urlencode 'text=passing'

If the key does not exist yet, Shielded.dev creates the shield for you. A user token starts with sdu_. A shield token does not use shield_key.

There is also a command line tool plus a GitHub Action.

Run your own copy

The hosted service is the easy path. Run your own copy when you need control over the service, data, host names.

You need:

  • Go 1.26.2 or newer
  • Node.js
  • MySQL 8
  • a GitHub sign-in application
  • three public host names: one for the site, one for updates, one for badge images

Start with a new database. schema/000_BASELINE.sql removes its tables before it creates them. Do not use it on a database that holds data you need.

for file in schema/[0-9][0-9][0-9]_*.sql; do
	mysql shielded < "$file"
done

Use your normal MySQL login details for those commands. The loop starts with the baseline. It applies every later numbered file in order.

Build the program with your three public host names. This follows the same -X pattern used by the Makefile for local work.

git clone https://github.com/ShieldedDotDev/shieldeddotdev.git
cd shieldeddotdev
npm install

make LDADDIT="-X main.rootHost=badges.example.com -X main.apiHost=updates.example.com -X main.imgHost=images.example.com" build

Point those names at your server. Also point www.badges.example.com at it. The program sends that name to badges.example.com.

Create a GitHub sign-in application. Set its return address to:

https://badges.example.com/github/callback

Then start the program with your database details plus the GitHub application values.

./shielded \
  -run-local=false \
  -dsn 'user:password@tcp(database-host:3306)/shielded?parseTime=true' \
  -client-id '<github-client-id>' \
  -client-secret '<github-client-secret>'

In this mode the program gets certificates for the three public names itself. Let web traffic reach the server on ports 80 and 443.

Work on a local copy

For local work, install Go, Node.js, Docker, Caddy. Then follow the host-file plus local certificate notes in Caddyfile.local. Run:

./run-local.sh

The script starts a fresh MySQL container, applies the schema files, starts the program, starts Caddy. Visit https://local.shielded.dev/. Press Control-C when you are done. The script stops every local service.

Project notes

ARCHITECTURE.md describes the routes, data, sign-in flow, build steps. AGENTS.md has notes for people changing the code.

Useful checks:

make lint
go test ./...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedColor = errors.New("unsupported color")
View Source
var StaticAssets fs.FS = os.DirFS("static")

StaticAssets is a static site asset filesystem

Functions

func NormalizeColor

func NormalizeColor(color string) (string, error)

Types

type ApiHandler

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

func NewApiHandler

func NewApiHandler(sm *model.ShieldMapper, tm *model.UserAPITokenMapper, imgHost string) *ApiHandler

func (*ApiHandler) HandlePOST

func (ah *ApiHandler) HandlePOST(w http.ResponseWriter, r *http.Request)

type DashboardShieldApiHandler

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

func NewDashboardShieldApiHandler

func NewDashboardShieldApiHandler(sm *model.ShieldMapper, jwtAuth *JwtAuth) *DashboardShieldApiHandler

func (*DashboardShieldApiHandler) HandleDELETE

func (sah *DashboardShieldApiHandler) HandleDELETE(w http.ResponseWriter, r *http.Request)

func (*DashboardShieldApiHandler) HandlePUT

type DashboardShieldApiIndexHandler

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

func NewDashboardShieldApiIndexHandler

func NewDashboardShieldApiIndexHandler(sm *model.ShieldMapper, jwtAuth *JwtAuth) *DashboardShieldApiIndexHandler

func (*DashboardShieldApiIndexHandler) HandleGET

func (*DashboardShieldApiIndexHandler) HandlePOST

type DashboardUserAPITokenHandler added in v0.2.0

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

func NewDashboardUserAPITokenHandler added in v0.2.0

func NewDashboardUserAPITokenHandler(tm *model.UserAPITokenMapper, jwtAuth *JwtAuth) *DashboardUserAPITokenHandler

func (*DashboardUserAPITokenHandler) HandleDELETE added in v0.2.0

type DashboardUserAPITokenIndexHandler added in v0.2.0

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

func NewDashboardUserAPITokenIndexHandler added in v0.2.0

func NewDashboardUserAPITokenIndexHandler(tm *model.UserAPITokenMapper, jwtAuth *JwtAuth) *DashboardUserAPITokenIndexHandler

func (*DashboardUserAPITokenIndexHandler) HandleGET added in v0.2.0

func (*DashboardUserAPITokenIndexHandler) HandlePOST added in v0.2.0

type DebugAuthHandler

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

func NewDebugAuthHandler

func NewDebugAuthHandler(um *model.UserMapper, jwtAuth *JwtAuth) *DebugAuthHandler

func (*DebugAuthHandler) LoginHandler

func (ah *DebugAuthHandler) LoginHandler(w http.ResponseWriter, r *http.Request)

type GitHubAuthHandler

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

func NewGitHubAuthHandler

func NewGitHubAuthHandler(um *model.UserMapper, clientID string, clientSecret string, jwtAuth *JwtAuth) *GitHubAuthHandler

func (*GitHubAuthHandler) CallbackHandler

func (ah *GitHubAuthHandler) CallbackHandler(w http.ResponseWriter, r *http.Request)

func (*GitHubAuthHandler) LoginHandler

func (ah *GitHubAuthHandler) LoginHandler(w http.ResponseWriter, r *http.Request)

type JwtAuth

type JwtAuth struct {
	Secret []byte
}

func (*JwtAuth) Authorize

func (j *JwtAuth) Authorize(w http.ResponseWriter, uid int64) error

func (*JwtAuth) GetAuth

func (j *JwtAuth) GetAuth(r *http.Request) *int64

type KeyedShieldHandler added in v0.3.0

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

func NewKeyedShieldHandler added in v0.3.0

func NewKeyedShieldHandler(sm *model.ShieldMapper) *KeyedShieldHandler

func (*KeyedShieldHandler) ServeHTTP added in v0.3.0

func (sh *KeyedShieldHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ShieldHandler

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

func NewShieldHandler

func NewShieldHandler(sm *model.ShieldMapper) *ShieldHandler

func (*ShieldHandler) ServeHTTP

func (sh *ShieldHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type StaticShieldHandler

type StaticShieldHandler struct{}

func (*StaticShieldHandler) ServeHTTP

func (ssh *StaticShieldHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis
cmd
shielded command
templ: version: v0.3.1020
templ: version: v0.3.1020

Jump to

Keyboard shortcuts

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