Skip to content

Commit

Permalink
add code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
faceair committed Jun 18, 2018
1 parent 0c3d341 commit ab7a38b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

<p align="center">
<a href="https://raw.githubusercontent.com/faceair/gotit/master/LICENSE"><img src="https://img.shields.io/hexpm/l/plug.svg" alt="License"></a>
<a href="https://travis-ci.org/faceair/gotit"><img src="https://img.shields.io/travis/faceair/gotit/master.svg" alt="Travis branch"></a>
<a href="https://coveralls.io/github/faceair/gotit?branch=master"><img src="https://coveralls.io/repos/github/faceair/gotit/badge.svg?branch=master" alt="Coverage Status"></a>
<a href="https://goreportcard.com/report/github.com/faceair/gotit"><img src="https://goreportcard.com/badge/github.com/faceair/gotit" alt="Go Report Card"></a>
<a href="https://travis-ci.org/faceair/gotit"><img src="https://img.shields.io/travis/faceair/gotit/master.svg?t=1529297795" alt="Travis branch"></a>
<a href="https://coveralls.io/github/faceair/gotit?branch=master"><img src="https://coveralls.io/repos/github/faceair/gotit/badge.svg?branch=master&t=1529297795" alt="Coverage Status"></a>
<a href="https://goreportcard.com/report/github.com/faceair/gotit"><img src="https://goreportcard.com/badge/github.com/faceair/gotit?t=1529297795" alt="Go Report Card"></a>
<a href="https://godoc.org/github.com/faceair/gotit"><img src="https://godoc.org/github.com/faceair/gotit?status.svg" alt="GoDoc"></a>
</p>

Expand Down Expand Up @@ -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
```
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

<p align="center">
<a href="https://raw.githubusercontent.com/faceair/gotit/master/LICENSE"><img src="https://img.shields.io/hexpm/l/plug.svg" alt="License"></a>
<a href="https://travis-ci.org/faceair/gotit"><img src="https://img.shields.io/travis/faceair/gotit/master.svg" alt="Travis branch"></a>
<a href="https://coveralls.io/github/faceair/gotit?branch=master"><img src="https://coveralls.io/repos/github/faceair/gotit/badge.svg?branch=master" alt="Coverage Status"></a>
<a href="https://goreportcard.com/report/github.com/faceair/gotit"><img src="https://goreportcard.com/badge/github.com/faceair/gotit" alt="Go Report Card"></a>
<a href="https://travis-ci.org/faceair/gotit"><img src="https://img.shields.io/travis/faceair/gotit/master.svg?t=1529297795" alt="Travis branch"></a>
<a href="https://coveralls.io/github/faceair/gotit?branch=master"><img src="https://coveralls.io/repos/github/faceair/gotit/badge.svg?branch=master&t=1529297795" alt="Coverage Status"></a>
<a href="https://goreportcard.com/report/github.com/faceair/gotit"><img src="https://goreportcard.com/badge/github.com/faceair/gotit?t=1529297795" alt="Go Report Card"></a>
<a href="https://godoc.org/github.com/faceair/gotit"><img src="https://godoc.org/github.com/faceair/gotit?status.svg" alt="GoDoc"></a>
</p>

Expand Down Expand Up @@ -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 监听的端口上
```
Expand All @@ -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
```

#### 其他包管理工具
Expand Down
11 changes: 11 additions & 0 deletions git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -151,39 +155,46 @@ 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
}
return 0, io.EOF
}

// NewLogBuffer create a LogBuffer instance
func NewLogBuffer(prefix string) *LogBuffer {
return &LogBuffer{
prefix: prefix,
buffer: make([]byte, 0, 128),
}
}

// 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)
}

0 comments on commit ab7a38b

Please sign in to comment.