Example #1
0
// NewHandler returns a new, mocked instance Handler.
func NewHandler() *Handler {
	h := &Handler{Handler: server.NewHandler(false, []string{""})}
	h.Handler.Store = &h.Store
	h.Store.IsLeaderFn = func() bool { return true }
	h.Store.GetPeersFn = func() ([]string, error) {
		return []string{""}, nil
	}
	h.Store.LastIndexFn = func() uint64 { return 0 }
	return h
}
Example #2
0
File: main.go Project: QY-Y/flynn
// openHTTPServer initializes and opens the HTTP server.
// The store must already be open.
func (m *Main) openHTTPServer(ln net.Listener, peers []string) error {
	// If we have no store then simply start a proxy handler.
	if m.store == nil {
		go http.Serve(ln, &server.ProxyHandler{Peers: peers})
		return nil
	}

	// Otherwise initialize and start handler.
	h := server.NewHandler()
	h.Store = m.store
	go http.Serve(ln, h)

	return nil
}
Example #3
0
// openHTTPServer initializes and opens the HTTP server.
// The store must already be open.
func (m *Main) openHTTPServer() error {
	h := server.NewHandler(false, m.peers)
	h.Main = m
	h.Peers = m.peers
	// If we have no store then start the handler in proxy mode
	if m.store == nil {
		h.Proxy.Store(true)
	} else {
		h.Store = m.store
	}
	m.handler = h
	m.httpServer = &http.Server{Handler: h}

	// Create listener via mux
	// HTTP listens to all methods: CONNECT, DELETE, GET, HEAD, OPTIONS, POST, PUT, TRACE.
	httpLn := m.mux.Listen([]byte{'C', 'D', 'G', 'H', 'O', 'P', 'T'})
	go m.httpServer.Serve(httpLn)
	return nil
}
Example #4
0
File: main.go Project: rikur/flynn
// openHTTPServer initializes and opens the HTTP server.
// The store must already be open.
func (m *Main) openHTTPServer(addr string, peers []string) error {
	// Open HTTP API.
	ln, err := net.Listen("tcp4", addr)
	if err != nil {
		return err
	}
	m.httpListener = ln

	// If we have no store then simply start a proxy handler.
	if m.store == nil {
		go http.Serve(m.httpListener, &server.ProxyHandler{Peers: peers})
		return nil
	}

	// Otherwise initialize and start handler.
	h := server.NewHandler()
	h.Store = m.store
	go http.Serve(m.httpListener, h)

	return nil
}
Example #5
0
// NewHandler returns a new, mocked instance Handler.
func NewHandler() *Handler {
	h := &Handler{Handler: server.NewHandler()}
	h.Handler.Store = &h.Store
	return h
}