diff --git a/README.md b/README.md index a82964e..20b4cad 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@

License - Travis branch - Coverage Status - Go Report Card + Travis branch + Coverage Status + Go Report Card GoDoc

@@ -45,7 +45,7 @@ Run `gotit` directly see help for other commands. Gotit use system `GOPATH` to s #### dep -dep don't support skip HTTPS certificate verification, we need [patch](https://github.com/faceair/dep/commit/43c5e6bf4597bc644a9326d16849b986076b7921) dep. You can build it yourself in this [fork source](https://github.com/faceair/dep) or [download modified binary files](https://github.com/faceair/dep/releases/latest). +dep don't support skip HTTPS certificate verification, we need [patch](https://github.com/faceair/dep/commit/43c5e6bf4597bc644a9326d16849b986076b7921) dep. You can build it yourself in this [fork repository](https://github.com/faceair/dep) or [download modified binary files](https://github.com/faceair/dep/releases/latest). Then set HTTPS_PROXY to Gotit address ``` @@ -60,7 +60,7 @@ dep ensure -v #### go get ``` -env HTTPS_PROXY=http://127.0.0.1:8080 GIT_SSL_NO_VERIFY=true go get -v -insecure github.com/faceair/gotit +HTTPS_PROXY=http://127.0.0.1:8080 GIT_SSL_NO_VERIFY=true go get -v -insecure github.com/faceair/gotit ``` #### other diff --git a/README.zh.md b/README.zh.md index 7dcd5bd..917cb28 100644 --- a/README.zh.md +++ b/README.zh.md @@ -3,9 +3,9 @@

License - Travis branch - Coverage Status - Go Report Card + Travis branch + Coverage Status + Go Report Card GoDoc

@@ -45,7 +45,7 @@ $GOPATH/bin/gotit -port 8080 #### dep -dep 不支持关闭 HTTPS 证书校验,我们需要打上自己的 [Patch](https://github.com/faceair/dep/commit/43c5e6bf4597bc644a9326d16849b986076b7921)。你可以自己在这份 [Fork 源码](https://github.com/faceair/dep)构建,或者[下载修改后的二进制文件](https://github.com/faceair/dep/releases/latest)。 +dep 不支持关闭 HTTPS 证书校验,我们需要打上自己的 [Patch](https://github.com/faceair/dep/commit/43c5e6bf4597bc644a9326d16849b986076b7921)。你可以自己在这份 [Fork 仓库](https://github.com/faceair/dep)构建,或者[下载修改后的二进制文件](https://github.com/faceair/dep/releases/latest)。 然后使用时指定 HTTPS_PROXY 到 Gotit 监听的端口上 ``` @@ -60,7 +60,7 @@ dep ensure -v #### go get ``` -env HTTPS_PROXY=http://127.0.0.1:8080 GIT_SSL_NO_VERIFY=true go get -v -insecure github.com/faceair/gotit +HTTPS_PROXY=http://127.0.0.1:8080 GIT_SSL_NO_VERIFY=true go get -v -insecure github.com/faceair/gotit ``` #### 其他包管理工具 diff --git a/git/git.go b/git/git.go index f80ce30..46ddf87 100644 --- a/git/git.go +++ b/git/git.go @@ -17,6 +17,8 @@ import ( var vscRegex = regexp.MustCompile(`([A-Za-z0-9_.-]+(/[A-Za-z0-9_.-]+)+?)(/info/refs|/git-upload-pack|\?go-get=1)`) +// NewServer create a Server instance +// The gopath should be a valid folder and will store git repositories later func NewServer(gopath string) *Server { err := os.Setenv("GOPATH", gopath) if err != nil { @@ -31,12 +33,14 @@ func NewServer(gopath string) *Server { return g } +// Server implement interface of betproxy.Client type Server struct { gopath string queue chan string upTime sync.Map } +// Do receive client requests and return git repository information func (g *Server) Do(req *http.Request) (*http.Response, error) { match := vscRegex.FindStringSubmatch(req.URL.String()) if match == nil { @@ -151,14 +155,17 @@ func (g *Server) cmd(dir string, args ...string) *exec.Cmd { return cmd } +// NewStdoutReader return an io.reader that closes the command when it finishes reading data func NewStdoutReader(stdout io.Reader, cmd *exec.Cmd) io.Reader { return io.MultiReader(stdout, &StdoutCloser{cmd}) } +// StdoutCloser implement interface of io.Reader type StdoutCloser struct { cmd *exec.Cmd } +// Read wait and close the child process to avoid zombie process func (c *StdoutCloser) Read(p []byte) (n int, err error) { if err = c.cmd.Wait(); err != nil { return 0, err @@ -166,6 +173,7 @@ func (c *StdoutCloser) Read(p []byte) (n int, err error) { return 0, io.EOF } +// NewLogBuffer create a LogBuffer instance func NewLogBuffer(prefix string) *LogBuffer { return &LogBuffer{ prefix: prefix, @@ -173,17 +181,20 @@ func NewLogBuffer(prefix string) *LogBuffer { } } +// LogBuffer implement interface of io.Writer type LogBuffer struct { prefix string buffer []byte } +// Write write log to stdout and collect logs to buffer func (l *LogBuffer) Write(p []byte) (n int, err error) { log.Printf("%s: %s", l.prefix, p) l.buffer = append(l.buffer, p...) return len(p), nil } +// String return cached logs func (l *LogBuffer) String() string { return string(l.buffer) }