Skip to content
This repository has been archived by the owner on Oct 2, 2020. It is now read-only.

Commit

Permalink
Externalize the stacked library
Browse files Browse the repository at this point in the history
Reviewers: abg

Reviewed By: abg
  • Loading branch information
Joshua T Corbin committed May 19, 2016
1 parent 1a15b5f commit 98d4e6e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 329 deletions.
6 changes: 6 additions & 0 deletions glide.lock

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

4 changes: 3 additions & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
package: github.com/uber-go/gwr
import: []
import:
- package: github.com/uber-common/stacked
version: ^1.0.2
29 changes: 3 additions & 26 deletions internal/resp/server.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package resp

import (
"bufio"
"fmt"
"net"
"net/http"

"github.com/uber-go/gwr/internal/stacked"
)

// RedisServer serves a RedisHandler on a listening socket.
Expand Down Expand Up @@ -45,17 +41,9 @@ func (h RedisServer) Serve(ln net.Listener) error {
return nil
}

// WrapHTTPHandler bundles together a RedisHandler and an http.Handler into a
// dual protocol server. The server detects the RESP protocol based on the
// first byte (if it is one of "-:+$*").
func WrapHTTPHandler(respHandler RedisHandler, httpHandler http.Handler) *stacked.Server {
return &stacked.Server{[]stacked.Detector{
respDetector(respHandler),
stacked.DefaultHTTPHandler(httpHandler),
}}
}

func isFirstByteRespTag(p []byte) bool {
// IsFirstByteRespTag returns true if the first byte in the passed slice is a
// valid RESP tag character (i.e. if it is one of "-:+$*").
func IsFirstByteRespTag(p []byte) bool {
switch p[0] {
case '-':
fallthrough
Expand All @@ -71,14 +59,3 @@ func isFirstByteRespTag(p []byte) bool {
return false
}
}

func respDetector(respHandler RedisHandler) stacked.Detector {
hndl := stacked.ConnHandlerFunc(func(conn net.Conn, bufr *bufio.Reader) {
NewRedisConnection(conn, bufr).Handle(respHandler)
})
return stacked.Detector{
Needed: 1,
Test: isFirstByteRespTag,
Handler: hndl,
}
}
112 changes: 0 additions & 112 deletions internal/stacked/buf_listener.go

This file was deleted.

187 changes: 0 additions & 187 deletions internal/stacked/server.go

This file was deleted.

Loading

0 comments on commit 98d4e6e

Please sign in to comment.