badges

module
v0.0.0-...-bb0d5b7 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: MPL-2.0

README

earthly:badges

passed passed

badges is a web application written in go that exposes a REST API to:

  • create and store a badge
  • Retrieve it by ID

PUT /badges/[badgeId]

Creates or updates a badge.

Request
  • Content-type: application/json
  • Authorization: Bearer token required
  • Body structure:
    • label: The label of the badge (first text over gray background)
    • message: The message of the badge (following text over colored background)
    • color: Background color of the message
Response
  • Content-type: application/json
  • Body structure:
    • id: Id of the badge

GET /badges/{badgeId}

Retrieves the badge image, ready to embed in documentation.

Request
  • Content-type: N/A
  • Authorization: Not required
Response
  • Content-type: image/svg+xml

Data storage

Current implementation only supports local Sqlite db, so a persistent filesystem is required.

Authorization

PUT requests require a bearer token. Current implementation only accepts a single token value, that is passed as an environment entry.

Configuration

Configuration is done through environment entries.

Local test

Set up your bearer token secret:

export SECRET=<your-bearer-token>

Use earthly to start up a local docker compose stack.

 earthly +dev-up

Create a new badge:

curl -X PUT \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer $SECRET" \
     -d '{"label":"lunar", "message":"passing 22/22", "color":"#97ca00"}' \
     http://127.0.0.1:8081/badges/foo

And fetch it!

http://127.0.0.1:8081/badges/foo

passed

Finally, tear the stack down via:

earthly +dev-down

Creating/pushing image

earthly [--push] +badges-image --NAME=<image-name> --VERSION=<image-tag>

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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