Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4a0db80

Browse files
author
xuxinhua
committed
解决 golang.org/x... 被墙问题
1 parent 5739189 commit 4a0db80

File tree

5 files changed

+118
-17
lines changed

5 files changed

+118
-17
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ studygolang_data.sql
4040

4141
welcome.png
4242

43-
*.json
43+
*.json
44+
45+
.DS_Store

websites/code/gox_dispatcher/install

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
if [ ! -f install ]; then
6+
echo 'install must be run within its container folder' 1>&2
7+
exit 1
8+
fi
9+
10+
CURDIR=`pwd`
11+
OLDGOPATH="$GOPATH"
12+
export GOPATH="$CURDIR"
13+
14+
if [ ! -d "src/github.com/studygolang/mux" ]; then
15+
go get -u -v github.com/studygolang/mux
16+
fi
17+
18+
gofmt -w src
19+
20+
go install gox
21+
22+
export GOPATH="$OLDGOPATH"
23+
export PATH="$OLDPATH"
24+
25+
echo 'finished'
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright 2015 The StudyGolang Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
// http://studygolang.com http://golang.top
5+
// Author:polaris [email protected]
6+
7+
// golang.org/x/... 系列的包,go get 不下来,原因你懂的
8+
// 该程序解决此问题,要求使用 go get 的客户端,配置如下 host:
9+
// 101.251.196.90 golang.org
10+
package main
11+
12+
import (
13+
"fmt"
14+
"log"
15+
"net/http"
16+
"runtime"
17+
"strings"
18+
"text/template"
19+
20+
"github.com/studygolang/mux"
21+
)
22+
23+
func init() {
24+
runtime.GOMAXPROCS(runtime.NumCPU())
25+
}
26+
27+
func main() {
28+
29+
router := initRouter()
30+
http.Handle("/", router)
31+
log.Fatal(http.ListenAndServe(":9999", nil))
32+
}
33+
34+
// TODO:多人同时请求不同的包,验证可能会失败
35+
var project = ""
36+
37+
func initRouter() *mux.Router {
38+
router := mux.NewRouter()
39+
40+
router.PathPrefix("/x").HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
41+
path := req.URL.Path
42+
43+
paths := strings.SplitN(path, "/", 4)
44+
45+
if len(paths) < 3 {
46+
return parseTmpl(rw)
47+
}
48+
project = paths[2]
49+
50+
parseTmpl(rw)
51+
})
52+
53+
return router
54+
}
55+
56+
func parseTmpl(rw http.ResponseWriter) {
57+
tmpl, err := template.New("gox").Parse(tpl)
58+
if err != nil {
59+
fmt.Fprintln(rw, "error:", err)
60+
return
61+
}
62+
63+
err = tmpl.Execute(rw, project)
64+
if err != nil {
65+
fmt.Fprintln(rw, "error:", err)
66+
return
67+
}
68+
}
69+
70+
var tpl = `
71+
<!DOCTYPE html>
72+
<html lang="zh-CN">
73+
<head>
74+
<meta charset="utf-8">
75+
<meta name="go-import" content="golang.org/x/{{.}} git https://github.com/golang/{{.}}">
76+
</head>
77+
<body>
78+
</body>
79+
</html>
80+
`

websites/code/thirdparty/getpkg

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,19 @@ go get -u -v github.com/robfig/cron
1717
go get -u -v github.com/qiniu/api
1818
go get -u -v github.com/dchest/captcha
1919

20-
if [ ! -d "src/golang.org/x/text" ]; then
21-
git clone https://github.com/golang/text src/golang.org/x/text
22-
fi
23-
go install golang.org/x/text/...
24-
25-
if [ ! -d "src/golang.org/x/net" ]; then
26-
git clone https://github.com/golang/net src/golang.org/x/net
27-
fi
28-
go install golang.org/x/net/...
29-
#go get -u -v golang.org/x/net
20+
cp /etc/hosts ~/hosts
21+
echo "golang.org 101.251.196.90" > /etc/hosts
22+
#echo "127.0.0.1 golang.org" > /etc/hosts
3023

31-
if [ ! -d "src/code.google.com/p/cascadia" ]; then
32-
git clone https://github.com/studygolang/cascadia src/code.google.com/p/cascadia
33-
fi
34-
go install code.google.com/p/cascadia
24+
trap "mv ~/hosts /etc/hosts" HUP INT QUIT TSTP
3525

3626
go get -u -v github.com/PuerkitoBio/goquery
3727

28+
if [ -f ~/hosts ]; then
29+
mv ~/hosts /etc/hosts
30+
fi
31+
3832
export GOPATH="$OLDGOPATH"
3933
export PATH="$OLDPATH"
4034

41-
echo 'finished'
35+
echo 'finished'

websites/code/thirdparty/getpkg.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ if not exist "github.com/PuerkitoBio/goquery" (
4141
set GOPATH=%OLDGOPATH%
4242

4343
:end
44-
echo finished
44+
echo finished

0 commit comments

Comments
 (0)