rafthttp: move new funcs to right place

This commit is contained in:
Xiang Li 2015-10-17 22:34:48 -07:00
parent 478fab6aca
commit e87cd0c17b

View File

@ -48,27 +48,10 @@ var (
errClusterIDMismatch = errors.New("cluster ID mismatch")
)
func newSnapshotHandler(r Raft, snapSaver SnapshotSaver, cid types.ID) http.Handler {
return &snapshotHandler{
r: r,
snapSaver: snapSaver,
cid: cid,
}
}
type peerGetter interface {
Get(id types.ID) Peer
}
func newStreamHandler(peerGetter peerGetter, r Raft, id, cid types.ID) http.Handler {
return &streamHandler{
peerGetter: peerGetter,
r: r,
id: id,
cid: cid,
}
}
type writerToResponse interface {
WriteTo(w http.ResponseWriter)
}
@ -140,6 +123,14 @@ type snapshotHandler struct {
cid types.ID
}
func newSnapshotHandler(r Raft, snapSaver SnapshotSaver, cid types.ID) http.Handler {
return &snapshotHandler{
r: r,
snapSaver: snapSaver,
cid: cid,
}
}
// ServeHTTP serves HTTP request to receive and process snapshot message.
//
// If request sender dies without closing underlying TCP connection,
@ -211,6 +202,15 @@ type streamHandler struct {
cid types.ID
}
func newStreamHandler(peerGetter peerGetter, r Raft, id, cid types.ID) http.Handler {
return &streamHandler{
peerGetter: peerGetter,
r: r,
id: id,
cid: cid,
}
}
func (h *streamHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
w.Header().Set("Allow", "GET")