Exprash/examples/cats.sh

34 lines
616 B
Bash
Raw Normal View History

2022-09-28 22:05:02 -07:00
#!/bin/bash
printf '%s\n\n' 'Content-Type: text/html';
2022-09-28 22:33:08 -07:00
source exprash.sh;
2022-09-28 22:05:02 -07:00
declare -A cats;
cats[calico]="Calico";
cats[sphynx]="Sphynx";
cats[ragdoll]="Ragdoll";
cats[scottish_fold]="Scottish Fold";
get '/' && {
printf '<h1>Cats</h1>\n';
printf '<ul>\n';
for key in "${!cats[@]}"; do
printf '<li><a href="cats/%s">%s</a></li>\n' "$key" "${cats[$key]}";
done
printf '</ul>\n';
}
get '/cats/:cat' && {
key=$(param 'cat');
if [[ -v "cats[$key]" ]]; then
printf '<h1>Your Cat: %s</h1>\n' "${cats[$key]}";
else
next;
fi;
}
2022-09-28 22:33:08 -07:00
use && {
2022-09-28 22:05:02 -07:00
printf '<h1>Error: Cannot find that cat</h1>\n';
2022-09-28 22:33:08 -07:00
}