From e6353f53ccbf1595972ffb95293dc251d45be570 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Thu, 9 Feb 2017 23:00:28 -0500 Subject: [PATCH] Use string type instead of template.URL. Now that html/template is not heavily used (after #68), it's no longer worth it to import the entire html/template package only for its URL type. It's simpler to use string and add URL to the variable name to indicate that it's a URL. --- cmd/Go-Package-Store/development.go | 121 ++++++++++++++-------------- cmd/Go-Package-Store/main.go | 8 +- presentation.go | 20 +++-- presenter/github/github.go | 11 ++- presenter/gitiles/gitiles.go | 9 +-- workspace/workspace.go | 9 +-- 6 files changed, 86 insertions(+), 92 deletions(-) diff --git a/cmd/Go-Package-Store/development.go b/cmd/Go-Package-Store/development.go index 210dc82..038d98c 100644 --- a/cmd/Go-Package-Store/development.go +++ b/cmd/Go-Package-Store/development.go @@ -4,7 +4,6 @@ package main import ( "errors" - "html/template" "net/http" "time" @@ -47,31 +46,31 @@ var mockRepoPresentations = []workspace.RepoPresentation{ Root: (string)("github.com/gopherjs/gopherjs"), }, Presentation: &gps.Presentation{ - Home: (template.URL)("https://github.com/gopherjs/gopherjs"), - Image: (template.URL)("https://avatars.githubusercontent.com/u/6654647?v=3"), + Home: (string)("https://github.com/gopherjs/gopherjs"), + Image: (string)("https://avatars.githubusercontent.com/u/6654647?v=3"), Changes: ([]gps.Change)([]gps.Change{ (gps.Change)(gps.Change{ Message: (string)("improved reflect support for blocking functions"), - URL: (template.URL)("https://github.com/gopherjs/gopherjs/commit/87bf7e405aa3df6df0dcbb9385713f997408d7b9"), + URL: (string)("https://github.com/gopherjs/gopherjs/commit/87bf7e405aa3df6df0dcbb9385713f997408d7b9"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("small cleanup"), - URL: (template.URL)("https://github.com/gopherjs/gopherjs/commit/77a838f965881a888416bae38f790f76bb1f64bd"), + URL: (string)("https://github.com/gopherjs/gopherjs/commit/77a838f965881a888416bae38f790f76bb1f64bd"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(1), - URL: (template.URL)("https://www.example.com/"), + URL: (string)("https://www.example.com/"), }), }), (gps.Change)(gps.Change{ Message: (string)("replaced js.This and js.Arguments by js.MakeFunc"), - URL: (template.URL)("https://github.com/gopherjs/gopherjs/commit/29dd054a0753760fe6e826ded0982a1bf69f702a"), + URL: (string)("https://github.com/gopherjs/gopherjs/commit/29dd054a0753760fe6e826ded0982a1bf69f702a"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), }), @@ -83,15 +82,15 @@ var mockRepoPresentations = []workspace.RepoPresentation{ Root: (string)("golang.org/x/image"), }, Presentation: &gps.Presentation{ - Home: (template.URL)("http://golang.org/x/image"), - Image: (template.URL)("https://avatars.githubusercontent.com/u/4314092?v=3"), + Home: (string)("http://golang.org/x/image"), + Image: (string)("https://avatars.githubusercontent.com/u/4314092?v=3"), Changes: ([]gps.Change)([]gps.Change{ (gps.Change)(gps.Change{ Message: (string)("draw: generate code paths for image.Gray sources."), - URL: (template.URL)("https://github.com/golang/image/commit/f510ad81a1256ee96a2870647b74fa144a30c249"), + URL: (string)("https://github.com/golang/image/commit/f510ad81a1256ee96a2870647b74fa144a30c249"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), }), @@ -112,8 +111,8 @@ var mockRepoPresentations = []workspace.RepoPresentation{ }{Revision: "d34db33f01010101010101010101010101010101"}, }, Presentation: &gps.Presentation{ - Home: (template.URL)("https://unknown.com/package"), - Image: (template.URL)("https://github.com/images/gravatars/gravatar-user-420.png"), + Home: (string)("https://unknown.com/package"), + Image: (string)("https://github.com/images/gravatars/gravatar-user-420.png"), }, }, @@ -122,8 +121,8 @@ var mockRepoPresentations = []workspace.RepoPresentation{ Root: (string)("golang.org/x/foobar"), }, Presentation: &gps.Presentation{ - Home: (template.URL)("http://golang.org/x/foobar"), - Image: (template.URL)("https://avatars.githubusercontent.com/u/4314092?v=3"), + Home: (string)("http://golang.org/x/foobar"), + Image: (string)("https://avatars.githubusercontent.com/u/4314092?v=3"), Changes: ([]gps.Change)(nil), Error: (error)(errors.New("something went wrong\n\nnew lines are kept - spaces are too.")), }, @@ -136,175 +135,175 @@ var mockRepoPresentations = []workspace.RepoPresentation{ Root: (string)("github.com/influxdb/influxdb"), }, Presentation: &gps.Presentation{ - Home: (template.URL)("https://github.com/influxdb/influxdb"), - Image: (template.URL)("https://avatars.githubusercontent.com/u/5713248?v=3"), + Home: (string)("https://github.com/influxdb/influxdb"), + Image: (string)("https://avatars.githubusercontent.com/u/5713248?v=3"), Changes: ([]gps.Change)([]gps.Change{ (gps.Change)(gps.Change{ Message: (string)("Add link to \"How to Report Bugs Effectively\""), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/6f398c1daf88fe34faede69f4404a334202acae8"), + URL: (string)("https://github.com/influxdb/influxdb/commit/6f398c1daf88fe34faede69f4404a334202acae8"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("Update CONTRIBUTING.md"), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/37fa6056009dd4e84e9852ec50ce747e22375a99"), + URL: (string)("https://github.com/influxdb/influxdb/commit/37fa6056009dd4e84e9852ec50ce747e22375a99"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("Update CONTRIBUTING.md"), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/87a6a8f15a13c5bf0ac60608edc1be570e7b023e"), + URL: (string)("https://github.com/influxdb/influxdb/commit/87a6a8f15a13c5bf0ac60608edc1be570e7b023e"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("Add note about requiring distro details"), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/901f91dc9559bebddf9b49607eac4ffd5caa4158"), + URL: (string)("https://github.com/influxdb/influxdb/commit/901f91dc9559bebddf9b49607eac4ffd5caa4158"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(4), - URL: (template.URL)("https://www.example.com/"), + URL: (string)("https://www.example.com/"), }), }), (gps.Change)(gps.Change{ Message: (string)("Correct typo in change log"), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/8eefdba0d3ef3ab5a408073ae275d495b67c9535"), + URL: (string)("https://github.com/influxdb/influxdb/commit/8eefdba0d3ef3ab5a408073ae275d495b67c9535"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("Correct markdown for URL"), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/41688ea6af78d45d051c7f6ac24a6468d36b9fad"), + URL: (string)("https://github.com/influxdb/influxdb/commit/41688ea6af78d45d051c7f6ac24a6468d36b9fad"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("Update with PR1744"), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/db09b20d199c973a209e181c9e2f890969bd0b57"), + URL: (string)("https://github.com/influxdb/influxdb/commit/db09b20d199c973a209e181c9e2f890969bd0b57"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("Merge pull request #1770 from kylezh/dev"), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/a7c0d71d9ccadde17e7aa5cbba538b4a99670633"), + URL: (string)("https://github.com/influxdb/influxdb/commit/a7c0d71d9ccadde17e7aa5cbba538b4a99670633"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("Merge pull request #1787 from influxdb/measurement_batch_in_series"), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/40479784e2bd690b9021ec730287c426124230dd"), + URL: (string)("https://github.com/influxdb/influxdb/commit/40479784e2bd690b9021ec730287c426124230dd"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("Store Measurement commands in batches"), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/a5749bebfb40239b8fd7b25d2ab1aa234c31c6b2"), + URL: (string)("https://github.com/influxdb/influxdb/commit/a5749bebfb40239b8fd7b25d2ab1aa234c31c6b2"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("Merge pull request #1786 from influxdb/remove-syslog"), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/2facd6158620e86262407ae3c4c131860f6953c5"), + URL: (string)("https://github.com/influxdb/influxdb/commit/2facd6158620e86262407ae3c4c131860f6953c5"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("Merge pull request #1785 from influxdb/1784"), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/4a5fdcc9ea3bf6dc178f45758332b871e45b93eb"), + URL: (string)("https://github.com/influxdb/influxdb/commit/4a5fdcc9ea3bf6dc178f45758332b871e45b93eb"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("Fix urlgen to work on Ubuntu"), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/666d09367690627f9c3212c1c25c566416c645da"), + URL: (string)("https://github.com/influxdb/influxdb/commit/666d09367690627f9c3212c1c25c566416c645da"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("Remove unused syslog.go"), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/06bfd9c496becacff404e6768e7c0fd8ce9603c2"), + URL: (string)("https://github.com/influxdb/influxdb/commit/06bfd9c496becacff404e6768e7c0fd8ce9603c2"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("Fix timezone abbreviation."), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/06eac99c230dcc24bee9c3e1c1ef01725ce017ad"), + URL: (string)("https://github.com/influxdb/influxdb/commit/06eac99c230dcc24bee9c3e1c1ef01725ce017ad"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("Merge pull request #1782 from influxdb/more_contains_unit_tests"), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/fffbcf3fbe953e03e69ac1d22c142ecd6b3aba3b"), + URL: (string)("https://github.com/influxdb/influxdb/commit/fffbcf3fbe953e03e69ac1d22c142ecd6b3aba3b"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("More shard \"contains\" unit tests"), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/ec93341f3fddd294f404fd1469fb651d4ba16e4c"), + URL: (string)("https://github.com/influxdb/influxdb/commit/ec93341f3fddd294f404fd1469fb651d4ba16e4c"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("Update changelog for rc6 release"), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/65b4d1a060883a5901bd7c40492a3345d2eabc77"), + URL: (string)("https://github.com/influxdb/influxdb/commit/65b4d1a060883a5901bd7c40492a3345d2eabc77"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("Merge pull request #1781 from influxdb/single_shard_data"), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/5889b12832b2e43424951c92089db03f31df1078"), + URL: (string)("https://github.com/influxdb/influxdb/commit/5889b12832b2e43424951c92089db03f31df1078"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("Refactor shard group time bound checking"), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/05d630bfb8041362c89249e3e6fabe6261cecc66"), + URL: (string)("https://github.com/influxdb/influxdb/commit/05d630bfb8041362c89249e3e6fabe6261cecc66"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), (gps.Change)(gps.Change{ Message: (string)("Fix error when alter retention policy"), - URL: (template.URL)("https://github.com/influxdb/influxdb/commit/9f8639ded8778a270cc99cf2d9ee1a09f635d67d"), + URL: (string)("https://github.com/influxdb/influxdb/commit/9f8639ded8778a270cc99cf2d9ee1a09f635d67d"), Comments: (gps.Comments)(gps.Comments{ Count: (int)(0), - URL: (template.URL)(""), + URL: (string)(""), }), }), }), diff --git a/cmd/Go-Package-Store/main.go b/cmd/Go-Package-Store/main.go index e8c5c3c..ffda511 100644 --- a/cmd/Go-Package-Store/main.go +++ b/cmd/Go-Package-Store/main.go @@ -123,8 +123,8 @@ func mainHandler(w http.ResponseWriter, req *http.Request) { for _, c := range rp.Presentation.Changes { cs = append(cs, gpscomponent.Change{ Message: c.Message, - URL: string(c.URL), - Comments: gpscomponent.Comments{Count: c.Comments.Count, URL: string(c.Comments.URL)}, + URL: c.URL, + Comments: gpscomponent.Comments{Count: c.Comments.Count, URL: c.Comments.URL}, }) } repoPresentation := gpscomponent.RepoPresentation{ @@ -132,8 +132,8 @@ func mainHandler(w http.ResponseWriter, req *http.Request) { ImportPathPattern: rp.Repo.ImportPathPattern(), LocalRevision: rp.Repo.Local.Revision, RemoteRevision: rp.Repo.Remote.Revision, - HomeURL: string(rp.Presentation.Home), - ImageURL: string(rp.Presentation.Image), + HomeURL: rp.Presentation.HomeURL, + ImageURL: rp.Presentation.ImageURL, Changes: cs, Updated: rp.Updated, UpdateSupported: c.updateHandler.updater != nil, diff --git a/presentation.go b/presentation.go index da82430..5c89933 100644 --- a/presentation.go +++ b/presentation.go @@ -1,26 +1,24 @@ package gps -import "html/template" - // Presentation provides infomation about a Go package repo with an available update. type Presentation struct { - Home template.URL // Home URL of the Go package. Optional (empty string means none available). - Image template.URL // Image representing the Go package, typically its owner. - Changes []Change // List of changes, starting with the most recent. - Error error // Any error that occurred during presentation, to be displayed to user. + HomeURL string // Home URL of the Go package. Optional (empty string means none available). + ImageURL string // Image representing the Go package, typically its owner. + Changes []Change // List of changes, starting with the most recent. + Error error // Any error that occurred during presentation, to be displayed to user. } // Change represents a single commit message. type Change struct { - Message string // Commit message of this change. - URL template.URL // URL of this change. - Comments Comments // Comments on this change. + Message string // Commit message of this change. + URL string // URL of this change. + Comments Comments // Comments on this change. } // Comments represents change discussion. type Comments struct { - Count int // Count of comments on this change. - URL template.URL // URL of change discussion. Optional (empty string means none available). + Count int // Count of comments on this change. + URL string // URL of change discussion. Optional (empty string means none available). } // Presenter returns a Presentation for r, or nil if it can't. diff --git a/presenter/github/github.go b/presenter/github/github.go index 75d40f5..ea44097 100644 --- a/presenter/github/github.go +++ b/presenter/github/github.go @@ -3,7 +3,6 @@ package github import ( "fmt" - "html/template" "net/http" "strings" @@ -54,8 +53,8 @@ func NewPresenter(httpClient *http.Client) gps.Presenter { func presentGitHubRepo(gh *github.Client, repo *gps.Repo, ghOwner, ghRepo string) *gps.Presentation { p := &gps.Presentation{ - Home: template.URL("https://" + repo.Root), - Image: "https://github.com/images/gravatars/gravatar-user-420.png", // Default fallback. + HomeURL: "https://" + repo.Root, + ImageURL: "https://github.com/images/gravatars/gravatar-user-420.png", // Default fallback. } // This might take a while. @@ -69,7 +68,7 @@ func presentGitHubRepo(gh *github.Client, repo *gps.Repo, ghOwner, ghRepo string // Use the repo owner avatar image. if user, _, err := gh.Users.Get(ghOwner); err == nil && user.AvatarURL != nil { - p.Image = template.URL(*user.AvatarURL) + p.ImageURL = *user.AvatarURL } else if rateLimitErr, ok := err.(*github.RateLimitError); ok { setFirstError(p, rateLimitError{rateLimitErr}) } else { @@ -85,11 +84,11 @@ func extractChanges(cc *github.CommitsComparison) []gps.Change { c := cc.Commits[len(cc.Commits)-1-i] // Reverse order. change := gps.Change{ Message: firstParagraph(*c.Commit.Message), - URL: template.URL(*c.HTMLURL), + URL: *c.HTMLURL, } if commentCount := c.Commit.CommentCount; commentCount != nil && *commentCount > 0 { change.Comments.Count = *commentCount - change.Comments.URL = template.URL(*c.HTMLURL + "#comments") + change.Comments.URL = *c.HTMLURL + "#comments" } cs = append(cs, change) } diff --git a/presenter/gitiles/gitiles.go b/presenter/gitiles/gitiles.go index c7461d7..649dec4 100644 --- a/presenter/gitiles/gitiles.go +++ b/presenter/gitiles/gitiles.go @@ -5,7 +5,6 @@ import ( "bytes" "encoding/json" "fmt" - "html/template" "io" "net/http" "strings" @@ -35,9 +34,9 @@ func presentGitilesRepo(client *http.Client, repo *gps.Repo) *gps.Presentation { } return &gps.Presentation{ - Home: template.URL("https://" + repo.Root), - Image: "https://ssl.gstatic.com/codesite/ph/images/defaultlogo.png", - Changes: extractChanges(repo, log), + HomeURL: "https://" + repo.Root, + ImageURL: "https://ssl.gstatic.com/codesite/ph/images/defaultlogo.png", + Changes: extractChanges(repo, log), } } @@ -102,7 +101,7 @@ func extractChanges(repo *gps.Repo, l log) []gps.Change { } cs = append(cs, gps.Change{ Message: firstParagraph(commit.Message), - URL: template.URL(repo.Remote.RepoURL + "/+/" + commit.Commit + "%5e%21"), + URL: repo.Remote.RepoURL + "/+/" + commit.Commit + "%5e%21", }) } return cs diff --git a/workspace/workspace.go b/workspace/workspace.go index 1910ada..4300a9b 100644 --- a/workspace/workspace.go +++ b/workspace/workspace.go @@ -4,7 +4,6 @@ package workspace import ( "fmt" "go/build" - "html/template" "log" "sync" @@ -643,9 +642,9 @@ func (p *Pipeline) present(repo *gps.Repo) *gps.Presentation { // Generic presentation. return &gps.Presentation{ - Home: template.URL("https://" + repo.Root), - Image: "https://github.com/images/gravatars/gravatar-user-420.png", - Changes: nil, - Error: nil, + HomeURL: "https://" + repo.Root, + ImageURL: "https://github.com/images/gravatars/gravatar-user-420.png", + Changes: nil, + Error: nil, } }