func NewNode(stop chan bool) *Node { n := new(Node) n.stop = stop n.stopBoard = make(chan bool, 2) n.stopThread = make(chan bool, 2) n.stopPost = make(chan bool, 2) n.stopFile = make(chan bool, 2) n.Stats = NewNodeStats() n.Config = parseFlags() n.Storage = fourchan.NewStorage(n.Config.CassKeyspace, n.Config.CassEndpoints...) cfg := etcd.Config{ Endpoints: n.Config.EtcdEndpoints, Transport: etcd.DefaultTransport, HeaderTimeoutPerRequest: 3 * time.Second, } c, err := etcd.New(cfg) if err != nil { log.Fatal("Failed to connected to etcd: ", err) } n.Keys = etcd.NewKeysAPI(c) n.Closed = false // TODO these chan sizes are rather arbitrary... n.CBoard = make(chan *fourchan.Board, numBoardRoutines) n.CThread = make(chan *fourchan.Thread, numThreadRoutines) n.CPost = make(chan *fourchan.Post, numPostRoutines) n.CFile = make(chan *fourchan.File, numFileRoutines) n.Files = make(map[int]string) return n }
func NewApiServer(stop chan<- bool) *ApiServer { as := new(ApiServer) as.Config = parseFlags() as.stop = stop as.Stats = node.NewNodeStats() as.Storage = fourchan.NewStorage(as.Config.CassKeyspace, as.Config.CassEndpoints...) cfg := etcd.Config{ Endpoints: as.Config.EtcdEndpoints, Transport: etcd.DefaultTransport, HeaderTimeoutPerRequest: time.Second, } c, err := etcd.New(cfg) if err != nil { log.Fatal("Failed to connected to etcd: ", err) return nil } as.Keys = etcd.NewKeysAPI(c) return as }