Skip to content

Commit

Permalink
Merge pull request #36 from kazeburo/use-xid
Browse files Browse the repository at this point in the history
use xid. xid is good performance
  • Loading branch information
kazeburo authored Jun 11, 2019
2 parents 1ae5552 + 48f1b29 commit 4fd25b4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 47 deletions.
34 changes: 13 additions & 21 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
name = "github.com/jessevdk/go-flags"
version = "1.4.0"

[[constraint]]
name = "github.com/lestrrat-go/apache-logformat"
branch = "master"

[[constraint]]
name = "github.com/lestrrat-go/file-rotatelogs"
branch = "master"
Expand All @@ -45,18 +41,10 @@
branch = "master"
name = "github.com/lestrrat/go-server-starter-listener"

[[constraint]]
name = "github.com/renstrom/shortuuid"
version = "3.0.1"

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.3.0"

[[constraint]]
name = "go.mercari.io/go-dnscache"
version = "0.1.0"

[[constraint]]
name = "go.uber.org/zap"
version = "1.9.1"
Expand Down
17 changes: 4 additions & 13 deletions proxy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"sync"

"github.com/kazeburo/chocon/upstream"
"github.com/renstrom/shortuuid"
"github.com/rs/xid"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -65,7 +65,7 @@ func New(transport *http.RoundTripper, version string, upstream *upstream.Upstre
func (proxy *Proxy) ServeHTTP(writer http.ResponseWriter, originalRequest *http.Request) {
proxyID := originalRequest.Header.Get(proxyIDHeader)
if proxyID == "" {
proxyID = shortuuid.New()
proxyID = xid.New().String()
originalRequest.Header.Set(proxyIDHeader, proxyID)
}
writer.Header().Set(proxyIDHeader, proxyID)
Expand Down Expand Up @@ -129,9 +129,8 @@ func (proxy *Proxy) ServeHTTP(writer http.ResponseWriter, originalRequest *http.

buf := pool.Get().([]byte)
defer func() {
defer response.Body.Close()
// Ensure a response body from upstream will be always closed.
defer pool.Put(buf)
response.Body.Close()
pool.Put(buf)
}()

// Copy all header fields.
Expand Down Expand Up @@ -216,13 +215,5 @@ func (proxy *Proxy) copyRequest(originalRequest *http.Request) *http.Request {
sv = sv[n:]
}

// Append this machine's host name into X-Forwarded-For.
// if requestHost, _, err := net.SplitHostPort(originalRequest.RemoteAddr); err == nil {
// if originalValues, ok := proxyRequest.Header["X-Forwarded-For"]; ok {
// requestHost = strings.Join(originalValues, ", ") + ", " + requestHost
// }
// proxyRequest.Header.Set("X-Forwarded-For", requestHost)
// }

return proxyRequest
}
1 change: 0 additions & 1 deletion upstream/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ func (u *Upstream) Get() (string, *IPwc, error) {
ipwc := &IPwc{
ip: u.ipwcs[0].ip,
version: u.ipwcs[0].version,
busy: 0, // dummy
}
return h, ipwc, nil
}
Expand Down

0 comments on commit 4fd25b4

Please sign in to comment.