Skip to content

Commit 2aa267a

Browse files
committed
Revert to mustOpen(api()) by retrieving GOROOT value correctly.
1 parent 350ad0a commit 2aa267a

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

playground/imports/mkstdlib.go

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,17 @@ import (
1414
"io"
1515
"io/ioutil"
1616
"log"
17-
"net/http"
1817
"os"
1918
"path"
2019
"path/filepath"
2120
"regexp"
21+
"runtime"
2222
"sort"
2323
"strings"
2424
)
2525

2626
var outputFlag = flag.String("output", "", "output file name without extension; if empty, then print to stdout")
2727

28-
func mustOpenAPI(base string) io.Reader {
29-
resp, err := http.Get("https://raw.githubusercontent.com/golang/go/master/api/" + base)
30-
if err != nil {
31-
log.Fatal(err)
32-
}
33-
defer resp.Body.Close()
34-
body, err := ioutil.ReadAll(resp.Body)
35-
if err != nil {
36-
log.Fatal(err)
37-
}
38-
return bytes.NewReader(body)
39-
}
40-
4128
func mustOpen(name string) io.Reader {
4229
f, err := os.Open(name)
4330
if err != nil {
@@ -47,7 +34,7 @@ func mustOpen(name string) io.Reader {
4734
}
4835

4936
func api(base string) string {
50-
return filepath.Join(os.Getenv("GOROOT"), "api", base)
37+
return filepath.Join(runtime.GOROOT(), "api", base)
5138
}
5239

5340
var sym = regexp.MustCompile(`^pkg (\S+).*?, (?:var|func|type|const) ([A-Z]\w*)`)
@@ -69,12 +56,12 @@ func main() {
6956
outf("package imports\n")
7057
outf("var stdlib = map[string]string{\n")
7158
f := io.MultiReader(
72-
mustOpenAPI("go1.txt"),
73-
mustOpenAPI("go1.1.txt"),
74-
mustOpenAPI("go1.2.txt"),
75-
mustOpenAPI("go1.3.txt"),
76-
mustOpenAPI("go1.4.txt"),
77-
mustOpenAPI("go1.5.txt"),
59+
mustOpen(api("go1.txt")),
60+
mustOpen(api("go1.1.txt")),
61+
mustOpen(api("go1.2.txt")),
62+
mustOpen(api("go1.3.txt")),
63+
mustOpen(api("go1.4.txt")),
64+
mustOpen(api("go1.5.txt")),
7865
)
7966
sc := bufio.NewScanner(f)
8067
fullImport := map[string]string{} // "zip.NewReader" => "archive/zip"

0 commit comments

Comments
 (0)