Skip to content

Commit

Permalink
Use string type instead of template.URL.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dmitshur committed Feb 10, 2017
1 parent 908130e commit e6353f5
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 92 deletions.
121 changes: 60 additions & 61 deletions cmd/Go-Package-Store/development.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package main

import (
"errors"
"html/template"
"net/http"
"time"

Expand Down Expand Up @@ -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)(""),
}),
}),
}),
Expand All @@ -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)(""),
}),
}),
}),
Expand All @@ -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"),
},
},

Expand All @@ -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.")),
},
Expand All @@ -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)(""),
}),
}),
}),
Expand Down
8 changes: 4 additions & 4 deletions cmd/Go-Package-Store/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,17 @@ 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{
RepoRoot: rp.Repo.Root,
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,
Expand Down
20 changes: 9 additions & 11 deletions presentation.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Loading

0 comments on commit e6353f5

Please sign in to comment.