You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rwxrob-dot/scripts/gomethods

20 lines
407 B
Bash

#!/usr/bin/env bash
_trim() {
local it="${1#"${1%%[![:space:]]*}"}"
echo -e "${it%"${it##*[![:space:]]}"}"
}
receiver="$1"
while IFS= read -r name; do
name=$(_trim "$name")
[[ -z "$name" ]] && continue
printf "func (r *%s) %s() string {return r.%s}\n" \
"$receiver" "${name^}" "${name,}"
printf "func (r *%s) Set%s(v string) {r.%s = v}\n" \
"$receiver" "${name^}" "${name,}"
done