mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-15 16:51:03 +00:00
This commit refactors the config into a `main.Config` object instead of a global singleton. The `core.Service` is also refactored into the `main` package and individual pieces of the service are wired together by the `pilosa` binary. These two changes are required to begin to decouple packages from one another and allow them to be individually unit tested. Previously most top-level objects in the system could access any other top-level object through the `core.Service` which effectively made `Service` a singleton in the system. Each top-level object now has inline interfaces for their dependencies so that can be set at runtime by the `main` package or can be mocked by a test package.
56 lines
1,010 B
Go
56 lines
1,010 B
Go
package transport
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/umbel/pilosa/db"
|
|
)
|
|
|
|
const DefaultHTTPPort = 15001
|
|
|
|
type HttpTransport struct {
|
|
port int
|
|
outbox chan *db.Message
|
|
done chan int
|
|
}
|
|
|
|
func (trans *HttpTransport) Init() error {
|
|
log.Println("Bind to port", trans.port)
|
|
trans.done = make(chan int)
|
|
go trans.Loop()
|
|
return nil
|
|
}
|
|
|
|
func (trans *HttpTransport) Loop() {
|
|
var message *db.Message
|
|
for {
|
|
select {
|
|
case message = <-trans.outbox:
|
|
log.Println(message)
|
|
case <-trans.done:
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
func (trans *HttpTransport) Close() {
|
|
log.Println("Closing HTTP transport.")
|
|
trans.done <- 1
|
|
}
|
|
|
|
func (trans *HttpTransport) Send(node string, message *db.Message) error {
|
|
log.Println("Send", message, "to", node)
|
|
trans.outbox <- message
|
|
return nil
|
|
}
|
|
|
|
func (trans *HttpTransport) Receive() (*db.Message, error) {
|
|
return &db.Message{}, nil
|
|
}
|
|
|
|
func NewHttpTransport(port int) *HttpTransport {
|
|
trans := new(HttpTransport)
|
|
trans.port = port
|
|
trans.outbox = make(chan *db.Message, 10)
|
|
return trans
|
|
}
|