diff --git a/tracker/middleware.go b/tracker/middleware.go index 5f3c5eb..ba8e133 100644 --- a/tracker/middleware.go +++ b/tracker/middleware.go @@ -18,13 +18,16 @@ type AnnounceMiddleware func(AnnounceHandler) AnnounceHandler // AnnounceMiddleware from a MiddlewareConfig. 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...) } -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 { return nil } @@ -82,13 +85,16 @@ type ScrapeMiddleware func(ScrapeHandler) ScrapeHandler // ScrapeMiddleware from a MiddlewareConfig. 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...) } -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 { return nil } diff --git a/tracker/middleware_test.go b/tracker/middleware_test.go index 5fd6011..4d5f19d 100644 --- a/tracker/middleware_test.go +++ b/tracker/middleware_test.go @@ -40,7 +40,7 @@ func testAnnounceMW3(next AnnounceHandler) AnnounceHandler { } func TestAnnounceChain(t *testing.T) { - var achain announceChain + var achain AnnounceChain achain.Append(testAnnounceMW1) achain.Append(testAnnounceMW2) achain.Append(testAnnounceMW3) diff --git a/tracker/tracker.go b/tracker/tracker.go index 5a451b2..11a81f5 100644 --- a/tracker/tracker.go +++ b/tracker/tracker.go @@ -31,7 +31,7 @@ type Tracker struct { // NewTracker constructs a newly allocated Tracker composed of the middleware // in the provided configuration. func NewTracker(cfg *chihaya.TrackerConfig) (*Tracker, error) { - var achain announceChain + var achain AnnounceChain for _, mwConfig := range cfg.AnnounceMiddleware { mw, ok := announceMiddlewareConstructors[mwConfig.Name] if !ok { @@ -44,7 +44,7 @@ func NewTracker(cfg *chihaya.TrackerConfig) (*Tracker, error) { achain.Append(middleware) } - var schain scrapeChain + var schain ScrapeChain for _, mwConfig := range cfg.ScrapeMiddleware { mw, ok := scrapeMiddlewareConstructors[mwConfig.Name] if !ok {