diff options
Diffstat (limited to 'src/cmd/gofix/url.go')
-rw-r--r-- | src/cmd/gofix/url.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/cmd/gofix/url.go b/src/cmd/gofix/url.go index c1e47bd4e..7135d8edf 100644 --- a/src/cmd/gofix/url.go +++ b/src/cmd/gofix/url.go @@ -27,6 +27,7 @@ func init() { } var urlRenames = []struct{ in, out string }{ + {"URL", "URL"}, {"ParseURL", "Parse"}, {"ParseURLReference", "ParseWithReference"}, {"ParseQuery", "ParseQuery"}, @@ -45,7 +46,12 @@ func url(f *ast.File) bool { fixed := false // Update URL code. + var skip interface{} urlWalk := func(n interface{}) { + if n == skip { + skip = nil + return + } // Is it an identifier? if ident, ok := n.(*ast.Ident); ok && ident.Name == "url" { ident.Name = "url_" @@ -56,6 +62,12 @@ func url(f *ast.File) bool { fixed = urlDoFields(fn.Params) || fixed fixed = urlDoFields(fn.Results) || fixed } + // U{url: ...} is likely a struct field. + if kv, ok := n.(*ast.KeyValueExpr); ok { + if ident, ok := kv.Key.(*ast.Ident); ok && ident.Name == "url" { + skip = ident + } + } } // Fix up URL code and add import, at most once. @@ -63,7 +75,7 @@ func url(f *ast.File) bool { if fixed { return } - walk(f, urlWalk) + walkBeforeAfter(f, urlWalk, nop) addImport(f, "url") fixed = true } |