Skip to content

Commit 956cc17

Browse files
committed
sumdb/internal/sumweb: simplify code, clarify comments
Followup work from CL 172964 review comments. (That CL was in a different directory and is too hard to get back to.) - Simplify to one cache for Conn.ReadTile. - Replace Client.GetURL with Client.ReadRemote, which takes only a path, not a full URL. It works better for the client to take care of URL mapping. - Rename FindKey to Lookup throughout (matches URL). - Apply !-decoding in Handler. Change-Id: Ib004ebb1b608d9ee2f8bdf768628acdd5b985158 Reviewed-on: https://go-review.googlesource.com/c/exp/+/173945 Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]>
1 parent bd9ab2f commit 956cc17

File tree

5 files changed

+148
-113
lines changed

5 files changed

+148
-113
lines changed

sumdb/gosumcheck/main.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func usage() {
5454

5555
var (
5656
height = flag.Int("h", 8, "tile height")
57-
vkey = flag.String("k", "rsc-goog.appspot.com+eecb1dec+AbTy1QXWdqYd1TTpuaUqsk6u7p+n4AqLiLB8SBwoB831", "key") // TODO: Replace with real key.
57+
vkey = flag.String("k", "sum.golang.org+033de0ae+Ac4zctda0e5eza+HJyk9SxEdh+s3Ux18htTTAD8OuAn8", "key")
5858
url = flag.String("u", "", "url to server (overriding name)")
5959
vflag = flag.Bool("v", false, "enable verbose output")
6060
)
@@ -149,7 +149,7 @@ type client struct{}
149149

150150
func (*client) ReadConfig(file string) ([]byte, error) {
151151
if file == "key" {
152-
return []byte(*vkey + "\n" + *url), nil
152+
return []byte(*vkey), nil
153153
}
154154
if strings.HasSuffix(file, "/latest") {
155155
// Looking for cached latest tree head.
@@ -184,22 +184,30 @@ func init() {
184184
http.DefaultClient.Timeout = 1 * time.Minute
185185
}
186186

187-
func (*client) GetURL(url string) ([]byte, error) {
187+
func (*client) ReadRemote(path string) ([]byte, error) {
188+
name := *vkey
189+
if i := strings.Index(name, "+"); i >= 0 {
190+
name = name[:i]
191+
}
188192
start := time.Now()
189-
resp, err := http.Get(url)
193+
target := "https://" + name + path
194+
if *url != "" {
195+
target = *url + path
196+
}
197+
resp, err := http.Get(target)
190198
if err != nil {
191199
return nil, err
192200
}
193201
defer resp.Body.Close()
194202
if resp.StatusCode != 200 {
195-
return nil, fmt.Errorf("GET %v: %v", url, resp.Status)
203+
return nil, fmt.Errorf("GET %v: %v", target, resp.Status)
196204
}
197205
data, err := ioutil.ReadAll(io.LimitReader(resp.Body, 1<<20))
198206
if err != nil {
199207
return nil, err
200208
}
201209
if *vflag {
202-
fmt.Fprintf(os.Stderr, "%.3fs %s\n", time.Since(start).Seconds(), url)
210+
fmt.Fprintf(os.Stderr, "%.3fs %s\n", time.Since(start).Seconds(), target)
203211
}
204212
return data, nil
205213
}

0 commit comments

Comments
 (0)