Skip to content

Instantly share code, notes, and snippets.

@GeorgeErickson
Created November 29, 2017 20:43
Show Gist options
  • Save GeorgeErickson/48ccfefd1b2487f4ebc7039d8d71a5b8 to your computer and use it in GitHub Desktop.
Save GeorgeErickson/48ccfefd1b2487f4ebc7039d8d71a5b8 to your computer and use it in GitHub Desktop.
create a bare httptrace.ClientTrace implementation
#!/usr/bin/env -S awk -f
# usage: go doc httptrace.ClientTrace | trace.awk
BEGIN {
flag=0;
}
# check if we are inside the struct.
/{/ { flag=1 }
/}/ { flag=0 }
# print comments as is.
/\/\// && flag { print $0 }
# manipulate func defs
/func/ && flag {
sub(/ func/, "", $0);
sub(/DNSStartInfo/, "si httptrace.DNSStartInfo", $0);
sub(/DNSDoneInfo/, "di httptrace.DNSDoneInfo", $0);
sub(/WroteRequestInfo/, "ri httptrace.WroteRequestInfo", $0);
sub(/GotConnInfo/, "ri httptrace.GotConnInfo", $0);
sub(/, error/, ", err error", $0);
print "func (t *httpTrace)", $0, "{}";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment