mirror of
https://github.com/LBRYFoundation/tracker.git
synced 2025-08-30 00:41:29 +00:00
tracker: made (Scrape|Announce)Chain exported
This commit is contained in:
parent
83ffc0425e
commit
c6a3830c4b
3 changed files with 15 additions and 9 deletions
|
@ -18,13 +18,16 @@ type AnnounceMiddleware func(AnnounceHandler) AnnounceHandler
|
||||||
// AnnounceMiddleware from a MiddlewareConfig.
|
// AnnounceMiddleware from a MiddlewareConfig.
|
||||||
type AnnounceMiddlewareConstructor func(chihaya.MiddlewareConfig) (AnnounceMiddleware, error)
|
type AnnounceMiddlewareConstructor func(chihaya.MiddlewareConfig) (AnnounceMiddleware, error)
|
||||||
|
|
||||||
type announceChain struct{ mw []AnnounceMiddleware }
|
// AnnounceChain is a chain of AnnounceMiddlewares.
|
||||||
|
type AnnounceChain struct{ mw []AnnounceMiddleware }
|
||||||
|
|
||||||
func (c *announceChain) Append(mw ...AnnounceMiddleware) {
|
// Append appends AnnounceMiddlewares to the AnnounceChain.
|
||||||
|
func (c *AnnounceChain) Append(mw ...AnnounceMiddleware) {
|
||||||
c.mw = append(c.mw, mw...)
|
c.mw = append(c.mw, mw...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *announceChain) Handler() AnnounceHandler {
|
// Handler builds an AnnounceChain into an AnnounceHandler.
|
||||||
|
func (c *AnnounceChain) Handler() AnnounceHandler {
|
||||||
final := func(cfg *chihaya.TrackerConfig, req *chihaya.AnnounceRequest, resp *chihaya.AnnounceResponse) error {
|
final := func(cfg *chihaya.TrackerConfig, req *chihaya.AnnounceRequest, resp *chihaya.AnnounceResponse) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -82,13 +85,16 @@ type ScrapeMiddleware func(ScrapeHandler) ScrapeHandler
|
||||||
// ScrapeMiddleware from a MiddlewareConfig.
|
// ScrapeMiddleware from a MiddlewareConfig.
|
||||||
type ScrapeMiddlewareConstructor func(chihaya.MiddlewareConfig) (ScrapeMiddleware, error)
|
type ScrapeMiddlewareConstructor func(chihaya.MiddlewareConfig) (ScrapeMiddleware, error)
|
||||||
|
|
||||||
type scrapeChain struct{ mw []ScrapeMiddleware }
|
// ScrapeChain is a chain of ScrapeMiddlewares.
|
||||||
|
type ScrapeChain struct{ mw []ScrapeMiddleware }
|
||||||
|
|
||||||
func (c *scrapeChain) Append(mw ...ScrapeMiddleware) {
|
// Append appends ScrapeMiddlewares to the ScrapeChain.
|
||||||
|
func (c *ScrapeChain) Append(mw ...ScrapeMiddleware) {
|
||||||
c.mw = append(c.mw, mw...)
|
c.mw = append(c.mw, mw...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *scrapeChain) Handler() ScrapeHandler {
|
// Handler builds the ScrapeChain into a ScrapeHandler.
|
||||||
|
func (c *ScrapeChain) Handler() ScrapeHandler {
|
||||||
final := func(cfg *chihaya.TrackerConfig, req *chihaya.ScrapeRequest, resp *chihaya.ScrapeResponse) error {
|
final := func(cfg *chihaya.TrackerConfig, req *chihaya.ScrapeRequest, resp *chihaya.ScrapeResponse) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ func testAnnounceMW3(next AnnounceHandler) AnnounceHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAnnounceChain(t *testing.T) {
|
func TestAnnounceChain(t *testing.T) {
|
||||||
var achain announceChain
|
var achain AnnounceChain
|
||||||
achain.Append(testAnnounceMW1)
|
achain.Append(testAnnounceMW1)
|
||||||
achain.Append(testAnnounceMW2)
|
achain.Append(testAnnounceMW2)
|
||||||
achain.Append(testAnnounceMW3)
|
achain.Append(testAnnounceMW3)
|
||||||
|
|
|
@ -31,7 +31,7 @@ type Tracker struct {
|
||||||
// NewTracker constructs a newly allocated Tracker composed of the middleware
|
// NewTracker constructs a newly allocated Tracker composed of the middleware
|
||||||
// in the provided configuration.
|
// in the provided configuration.
|
||||||
func NewTracker(cfg *chihaya.TrackerConfig) (*Tracker, error) {
|
func NewTracker(cfg *chihaya.TrackerConfig) (*Tracker, error) {
|
||||||
var achain announceChain
|
var achain AnnounceChain
|
||||||
for _, mwConfig := range cfg.AnnounceMiddleware {
|
for _, mwConfig := range cfg.AnnounceMiddleware {
|
||||||
mw, ok := announceMiddlewareConstructors[mwConfig.Name]
|
mw, ok := announceMiddlewareConstructors[mwConfig.Name]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -44,7 +44,7 @@ func NewTracker(cfg *chihaya.TrackerConfig) (*Tracker, error) {
|
||||||
achain.Append(middleware)
|
achain.Append(middleware)
|
||||||
}
|
}
|
||||||
|
|
||||||
var schain scrapeChain
|
var schain ScrapeChain
|
||||||
for _, mwConfig := range cfg.ScrapeMiddleware {
|
for _, mwConfig := range cfg.ScrapeMiddleware {
|
||||||
mw, ok := scrapeMiddlewareConstructors[mwConfig.Name]
|
mw, ok := scrapeMiddlewareConstructors[mwConfig.Name]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
Loading…
Add table
Reference in a new issue