Skip to content

Modern cowsay in Go: CLI tool, REST API, and web UI in a single binary with 52 cows and 8 moods. Minimal dependencies, stdlib-first.

License

Notifications You must be signed in to change notification settings

vnykmshr/gowsay

Repository files navigation

gowsay

Implementation of cowsay in Go

Single binary, multiple modes:

  • Command-line tool (like original cowsay)
  • HTTP API server for Slack integration
  • Web UI with embedded assets
  • 51 different cows
  • 8 moods (borg, dead, greedy, paranoid, stoned, tired, wired, young)

Status: gowsay 2.0 - CLI tool, Web UI, JSON API

Usage

CLI Tool

# Basic usage
gowsay "Hello World"

# Use a different cow
gowsay -c dragon "Fire!"

# Make the cow think instead of speak
gowsay -t "Hmm..."

# Random cow and mood
gowsay -r "Surprise!"

# Use mood
gowsay -c tux -m dead "System crashed"

# From pipe
echo "Hello from pipe" | gowsay

# List available cows and moods
gowsay -l

# Help
gowsay --help

Web Interface

Start the server and open http://localhost:9000 in your browser:

./bin/gowsay serve
# or with custom port
PORT=8080 ./bin/gowsay serve

Features:

  • Modern, polished UI with dark mode
  • Choose from 51 different cows
  • Apply moods (borg, dead, greedy, etc.)
  • Random button for surprise cows
  • Copy output to clipboard
  • Mobile responsive

HTTP API

Endpoints:

# Generate cowsay (query params)
curl 'http://localhost:9000/api/moo?text=Hello&cow=dragon&action=say'

# Generate cowsay (JSON)
curl -X POST http://localhost:9000/api/moo \
  -H 'Content-Type: application/json' \
  -d '{"text":"Hello","cow":"dragon","mood":"wired"}'

# List all cows
curl http://localhost:9000/api/cows

# List all moods
curl http://localhost:9000/api/moods

# Health check
curl http://localhost:9000/health

API Parameters:

  • text - Message to display (required)
  • cow - Cow name (default: "default", or "random")
  • mood - Mood name (optional, or "random")
  • action - "say" or "think" (default: "say")
  • columns - Text width for wrapping (default: 40)

Error Responses:

{"error": "text is required"}
{"error": "cow 'invalid' not found"}
{"error": "mood 'invalid' not found"}

Slack Command

Deployed at https://gowsay.vnykmshr.com/say

/moo [think|surprise] [cow] [mood] message

Cows

`apt`, `beavis.zen`, `bong`, `bud-frogs`, `bunny`, `calvin`, `cheese`, `cock`, `cower`,
`daemon`, `default`, `dragon`, `dragon-and-cow`, `duck`, `elephant`, `elephant-in-snake`,
`eyes`, `flaming-sheep`, `ghostbusters`, `gnu`, `head-in`, `hellokitty`, `kiss`, `kitty`,
`koala`, `kosh`, `luke-koala`, `mech-and-cow`, `meow`, `milk`, `moofasa`, `moose`,
`mutilated`, `pony`, `pony-smaller`, `ren`, `sheep`, `skeleton`, `snowman`,
`sodomized-sheep`, `stegosaurus`, `stimpy`, `suse`, `three-eyes`, `turkey`, `turtle`,
`tux`, `unipony`, `unipony-smaller`, `vader`, `vader-koala`, `www`

Moods

`borg`, `dead`, `greedy`, `paranoid`, `stoned`, `tired`, `wired`, `young`

Configuration

Configuration via environment variables:

  • PORT - Server port (default: 9000)
  • GOWSAY_TOKEN - Authentication token (default: devel, allows any request - set in production)
  • GOWSAY_COLUMNS - Text column width (default: 40)

Development

Build

make build
# or
go build -ldflags "-X 'main.version=`git log -1 --pretty=format:"%h"`'" -v

Run CLI

./bin/gowsay "Hello World"

Run Server

make run/server
# or
./bin/gowsay serve
# or with custom port
PORT=8080 ./bin/gowsay serve

Test

make test

Cross-compile

Linux:

GOOS=linux GOARCH=amd64 go build -o bin/gowsay-linux

Raspberry Pi:

GOOS=linux GOARCH=arm GOARM=5 go build -o bin/gowsay-pi

Docker

Build and run with Docker:

# Build image
docker build -t gowsay .

# Run container
docker run -p 9000:9000 gowsay

# Or use docker compose
docker compose up

Docker image details:

  • Multi-stage build using Go 1.23
  • Final image uses scratch base (~11MB including embedded web assets)
  • Default command runs server mode
  • Can override for CLI: docker run gowsay --help

Slack Integration

Example request:

curl -X POST 'https://gowsay.vnykmshr.com/say' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'token=xxx' \
  --data-urlencode 'text=Hello World'

Documentation

License

MIT License - see LICENSE for details

About

Modern cowsay in Go: CLI tool, REST API, and web UI in a single binary with 52 cows and 8 moods. Minimal dependencies, stdlib-first.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •