Skip to content

Commit

Permalink
change organization name
Browse files Browse the repository at this point in the history
  • Loading branch information
vvatanabe committed Nov 27, 2017
1 parent f23c6b3 commit 104084a
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ before_script:
- docker build -t go-git-http-xfer .

script:
- docker run --rm -v $PWD:/go/src/github.com/vvatanabe/go-git-http-xfer go-git-http-xfer bash -c "gotestcover -v -covermode=count -coverprofile=coverage.out ./..."
- docker run --rm -v $PWD:/go/src/github.com/nulab/go-git-http-xfer go-git-http-xfer bash -c "gotestcover -v -covermode=count -coverprofile=coverage.out ./..."
- $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service travis-ci
19 changes: 2 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
#
# [docker build]
# docker build -t go-git-http-xfer .
#
# [test]
# docker run --rm -v $PWD:/go/src/github.com/vvatanabe/go-git-http-xfer go-git-http-xfer bash -c "gotestcover -v -covermode=count -coverprofile=coverage.out ./..."
#
# [attach]
# docker run -it --rm -v $PWD:/go/src/github.com/vvatanabe/go-git-http-xfer -p 8080:8080 go-git-http-xfer bash
#
# [run server](in container)
# go run /go/src/github.com/vvatanabe/go-git-http-xfer/example/main.go -p 8080
# And
# gin -t ./example -p 8080 -a 5050
#
# OFFICIAL REPOSITORY: https://hub.docker.com/_/golang/
FROM golang:1.9

Expand All @@ -36,8 +21,8 @@ ENV GIT_TEST_REPO_DIR /data/git/test.git
RUN mkdir -p $GIT_TEST_REPO_DIR && cd $GIT_TEST_REPO_DIR && git init --bare --shared


ENV SRC_DIR /go/src/github.com/vvatanabe/go-git-http-xfer
ENV SRC_DIR /go/src/github.com/nulab/go-git-http-xfer
RUN mkdir -p $SRC_DIR
WORKDIR $SRC_DIR

EXPOSE 8080
EXPOSE 5050
40 changes: 22 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# go-git-http-xfer [![Build Status](https://travis-ci.org/vvatanabe/go-git-http-xfer.svg?branch=master)](https://travis-ci.org/vvatanabe/go-git-http-xfer) [![Coverage Status](https://coveralls.io/repos/github/vvatanabe/go-git-http-xfer/badge.svg?branch=master)](https://coveralls.io/github/vvatanabe/go-git-http-xfer?branch=master)
# go-git-http-xfer [![Build Status](https://travis-ci.org/nulab/go-git-http-xfer.svg?branch=master)](https://travis-ci.org/nulab/go-git-http-xfer) [![Coverage Status](https://coveralls.io/repos/github/nulab/go-git-http-xfer/badge.svg?branch=master)](https://coveralls.io/github/nulab/go-git-http-xfer?branch=master)

Implements Git HTTP Transport.

Expand All @@ -16,23 +16,27 @@ Implements Git HTTP Transport.
Let's clone this repository and execute the following commands.

```` zsh
# docker build
$ docker build -t git-http-xfer .
$ docker run -it --rm -v $PWD:/go/src/github.com/vvatanabe/go-git-http-xfer \
-p 8080:8080 git-http-xfer bash

# in container
$ go run /go/src/github.com/vvatanabe/go-git-http-xfer/example/main.go -p 8080
# test
$ docker run --rm -v $PWD:/go/src/github.com/nulab/go-git-http-xfer go-git-http-xfer \
bash -c "gotestcover -v -covermode=count -coverprofile=coverage.out ./..."

# run server
$ docker run -it --rm -v $PWD:/go/src/github.com/nulab/go-git-http-xfer -p 5050:5050 go-git-http-xfer \
bash -c "go run ./example/main.go -p 5050"

# in your local machine
$ git clone http://localhost:8080/example.git
$ git clone http://localhost:5050/example.git
````

## Installation

This package can be installed with the go get command:

``` zsh
$ go get github.com/vvatanabe/go-git-http-xfer
$ go get github.com/nulab/go-git-http-xfer
```

## Usage
Expand All @@ -45,7 +49,7 @@ import (
"log"
"net/http"

"github.com/vvatanabe/go-git-http-xfer/githttpxfer"
"github.com/nulab/go-git-http-xfer/githttpxfer"
)

func main() {
Expand All @@ -56,21 +60,21 @@ func main() {
return
}

if err := http.ListenAndServe(":8080", ghx); err != nil {
if err := http.ListenAndServe(":5050", ghx); err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
```
You can add optional parameters to constructor function.
* `WithoutUploadPack` : Disable `git-upload-pack` command.
* `WithoutReceivePack`: Disable `git-receive-pack` command.
* `WithoutDumbProto` : Disable `dumb protocol` handling.
* `DisableUploadPack` : Disable `git upload-pack` command.
* `DisableReceivePack`: Disable `git receive-pack` command.
* `WithoutDumbProto` : Without `dumb protocol` handling.
```go
ghx, err := githttpxfer.New(
"/data/git",
"/usr/bin/git",
githttpxfer.WithoutUploadPack(),
githttpxfer.WithoutReceivePack(),
githttpxfer.DisableUploadPack(),
githttpxfer.DisableReceivePack(),
githttpxfer.WithoutDumbProto(),
)
```
Expand Down Expand Up @@ -103,7 +107,7 @@ func main() {
},
))

if err := http.ListenAndServe(":8080", ghx); err != nil {
if err := http.ListenAndServe(":5050", ghx); err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
Expand All @@ -120,7 +124,7 @@ func main() {

handler := Logging(ghx)

if err := http.ListenAndServe(":8080", ghx); err != nil {
if err := http.ListenAndServe(":5050", ghx); err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
Expand All @@ -137,7 +141,7 @@ func Logging(next http.Handler) http.Handler {
You can add some addon handler. (git archive)
``` go
import (
"github.com/vvatanabe/go-git-http-xfer/addon/archivehandler"
"github.com/nulab/go-git-http-xfer/addon/archivehandler"
)

func main() {
Expand All @@ -153,7 +157,7 @@ func main() {
archivehandler.New(ghx).HandlerFunc,
))

if err := http.ListenAndServe(":8080", ghx); err != nil {
if err := http.ListenAndServe(":5050", ghx); err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion addon/handler/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"regexp"
"strings"

"github.com/vvatanabe/go-git-http-xfer/githttpxfer"
"github.com/nulab/go-git-http-xfer/githttpxfer"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion addon/handler/archive/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path"
"testing"

"github.com/vvatanabe/go-git-http-xfer/githttpxfer"
"github.com/nulab/go-git-http-xfer/githttpxfer"
)

func Test_it_should_download_archive_repository(t *testing.T) {
Expand Down
44 changes: 35 additions & 9 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

"strings"

"github.com/vvatanabe/go-git-http-xfer/addon/handler/archive"
"github.com/vvatanabe/go-git-http-xfer/githttpxfer"
"github.com/nulab/go-git-http-xfer/addon/handler/archive"
"github.com/nulab/go-git-http-xfer/githttpxfer"
)

func main() {
Expand All @@ -26,12 +26,12 @@ func main() {
return
}

ghx.Event.On(githttpxfer.PrepareServiceRPCUpload, func(ctx githttpxfer.Context) {
// prepare run service rpc upload.
ghx.Event.On(githttpxfer.BeforeUploadPack, func(ctx githttpxfer.Context) {
// before run service rpc upload.
})

ghx.Event.On(githttpxfer.PrepareServiceRPCReceive, func(ctx githttpxfer.Context) {
// prepare run service rpc receive.
ghx.Event.On(githttpxfer.BeforeReceivePack, func(ctx githttpxfer.Context) {
// before run service rpc receive.
})

ghx.Event.On(githttpxfer.AfterMatchRouting, func(ctx githttpxfer.Context) {
Expand Down Expand Up @@ -65,14 +65,22 @@ func main() {
))

// You can add some middleware.
handler := Logging(ghx)
chain := NewChain()
chain.Use(Logging)
chain.Use(BasicAuth)
handler := chain.Build(ghx)

if err := http.ListenAndServe(fmt.Sprintf(":%d", port), handler); err != nil {
appAddr := fmt.Sprintf(":%d", port)
log.Println("Starting ListenAndServe " + appAddr)

if err := http.ListenAndServe(appAddr, handler); err != nil {
log.Fatal("ListenAndServe: ", err)
}

}

type Middleware func(http.Handler) http.Handler

func Logging(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
t1 := time.Now()
Expand All @@ -95,8 +103,26 @@ func BasicAuth(next http.Handler) http.Handler {

func RenderUnauthorized(w http.ResponseWriter) {
w.Header().Set("WWW-Authenticate", `Basic realm="Please enter your username and password."`)

w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(http.StatusText(http.StatusUnauthorized)))
w.Header().Set("Content-Type", "text/plain")
}

func NewChain() *chain {
return &chain{[]Middleware{}}
}

type chain struct {
middlewares []Middleware
}

func (c *chain) Use(m Middleware) {
c.middlewares = append(c.middlewares, m)
}

func (c *chain) Build(h http.Handler) http.Handler {
for i := range c.middlewares {
h = c.middlewares[len(c.middlewares)-1-i](h)
}
return h
}
14 changes: 7 additions & 7 deletions githttpxfer/githttpxfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ type options struct {

type Option func(*options)

func WithoutUploadPack() Option {
func DisableUploadPack() Option {
return func(o *options) {
o.uploadPack = false
}
}

func WithoutReceivePack() Option {
func DisableReceivePack() Option {
return func(o *options) {
o.receivePack = false
}
Expand Down Expand Up @@ -193,9 +193,9 @@ func newEvent() *event {
type EventKey string

const (
PrepareServiceRPCUpload EventKey = "prepare-service-rpc-upload"
PrepareServiceRPCReceive EventKey = "prepare-service-rpc-receive"
AfterMatchRouting EventKey = "after-match-routing"
BeforeUploadPack EventKey = "before-upload-pack"
BeforeReceivePack EventKey = "before-receive-pack"
AfterMatchRouting EventKey = "after-match-routing"
)

type event struct {
Expand All @@ -214,12 +214,12 @@ func (e *event) On(evt EventKey, listener HandlerFunc) {
}

func (ghx *GitHTTPXfer) serviceRPCUpload(ctx Context) {
ghx.Event.emit(PrepareServiceRPCUpload, ctx)
ghx.Event.emit(BeforeUploadPack, ctx)
ghx.serviceRPC(ctx, uploadPack)
}

func (ghx *GitHTTPXfer) serviceRPCReceive(ctx Context) {
ghx.Event.emit(PrepareServiceRPCReceive, ctx)
ghx.Event.emit(BeforeReceivePack, ctx)
ghx.serviceRPC(ctx, receivePack)
}

Expand Down
4 changes: 2 additions & 2 deletions githttpxfer/githttpxfer_end_to_end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ func setupEndToEndTest(t *testing.T) error {
}

endToEndTestParams.ghx = ghx
endToEndTestParams.ghx.Event.On(PrepareServiceRPCUpload, func(ctx Context) {
endToEndTestParams.ghx.Event.On(BeforeUploadPack, func(ctx Context) {
t.Log("prepare run service rpc upload.")
})
endToEndTestParams.ghx.Event.On(PrepareServiceRPCReceive, func(ctx Context) {
endToEndTestParams.ghx.Event.On(BeforeReceivePack, func(ctx Context) {
t.Log("prepare run service rpc receive.")
})
endToEndTestParams.ghx.Event.On(AfterMatchRouting, func(ctx Context) {
Expand Down
28 changes: 14 additions & 14 deletions githttpxfer/githttpxfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ func Test_GitHTTPXfer_GitHTTPXferOption(t *testing.T) {
}

tests := []struct {
description string
url string
contentsType string
expectedCode int
description string
url string
contentsType string
expectedCode int
gitHTTPXferOption Option
}{
{
description: "it should return 403 if upload-pack is off",
url: "/test.git/git-upload-pack",
contentsType: "application/x-git-upload-pack-request",
expectedCode: 403,
gitHTTPXferOption: WithoutUploadPack(),
description: "it should return 403 if upload-pack is off",
url: "/test.git/git-upload-pack",
contentsType: "application/x-git-upload-pack-request",
expectedCode: 403,
gitHTTPXferOption: DisableUploadPack(),
},
{
description: "it should return 403 if receive-pack is off",
url: "/test.git/git-receive-pack",
contentsType: "application/x-git-receive-pack-request",
expectedCode: 403,
gitHTTPXferOption: WithoutReceivePack(),
description: "it should return 403 if receive-pack is off",
url: "/test.git/git-receive-pack",
contentsType: "application/x-git-receive-pack-request",
expectedCode: 403,
gitHTTPXferOption: DisableReceivePack(),
},
}

Expand Down

0 comments on commit 104084a

Please sign in to comment.