Skip to content

Instantly share code, notes, and snippets.

@thecarlhall
Created June 8, 2020 01:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thecarlhall/718de74c702e5d7993260e42d7160507 to your computer and use it in GitHub Desktop.
Save thecarlhall/718de74c702e5d7993260e42d7160507 to your computer and use it in GitHub Desktop.
Scripts to check the API implementation of Gonic
#!/usr/bin/env bash
curl http://www.subsonic.org/pages/api.jsp | \
grep -A 4 '<h3' | \
grep -e '<h3' -e Since | \
tail -n +6 | tr -d "\r\n" | \
sed -e $'s/<h3>/\\\n/g' | \
sed 's/<[^>]*>//g' | \
awk '{print $3, $1}' | \
sort -V > api-by-version.csv
from collections import defaultdict
red = '\033[31m'
green = '\033[32m'
clear = '\033[0m'
checkmark = green + '✓'
xmark = red + 'x'
## adjust path to match where server.go is relative to this file
with open('../server/server.go') as server:
impl = server.read()
total_endpoints = 0
## dict structure: version => [ endpoints ]
api_versions = defaultdict(list)
with open('api-by-version.csv', 'r') as api:
for line in api:
[version, endpoint] = line.strip().split(',')
api_versions[version].append(endpoint)
for version, endpoints in api_versions.items():
version_endpoints = 0
num_impled = 0
endpoints_state = {}
for endpoint in endpoints:
version_endpoints += 1
total_endpoints += 1
impled = '/' + endpoint + '{' in impl
endpoints_state[endpoint] = impled
num_impled += 1 if impled else 0
print(checkmark if num_impled == version_endpoints else xmark, version,
'(', round((num_impled / version_endpoints) * 100, 2), '%)', clear)
for endpoint, impled in endpoints_state.items():
print(' ', checkmark if impled else xmark, endpoint, clear)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment