remove config package

This commit is contained in:
Jimmy Zelinskie
2016-03-02 20:18:55 -05:00
parent 47f85ec961
commit 0dfc26caea
16 changed files with 129 additions and 123 deletions
+17 -19
View File
@@ -1,20 +1,17 @@
// Copyright 2016 The Chihaya Authors. All rights reserved.
// Use of this source code is governed by the BSD 2-Clause license,
// which can be found in the LICENSE file.package middleware
// which can be found in the LICENSE file.
package tracker
import (
"github.com/chihaya/chihaya"
"github.com/chihaya/chihaya/config"
)
import "github.com/chihaya/chihaya"
// AnnounceHandler is a function that operates on an AnnounceResponse before it
// has been delivered to a client.
type AnnounceHandler func(*config.TrackerConfig, *chihaya.AnnounceRequest, *chihaya.AnnounceResponse) error
type AnnounceHandler func(*chihaya.TrackerConfig, *chihaya.AnnounceRequest, *chihaya.AnnounceResponse) error
// AnnounceMiddleware is higher-order AnnounceHandler used to implement modular
// behavior processing an announce.
// AnnounceMiddleware is a higher-order function used to implement the chaining
// of AnnounceHandlers.
type AnnounceMiddleware func(AnnounceHandler) AnnounceHandler
type announceChain struct{ mw []AnnounceMiddleware }
@@ -24,9 +21,10 @@ func (c *announceChain) Append(mw ...AnnounceMiddleware) {
}
func (c *announceChain) Handler() AnnounceHandler {
final := func(cfg *config.TrackerConfig, req *chihaya.AnnounceRequest, resp *chihaya.AnnounceResponse) error {
final := func(cfg *chihaya.TrackerConfig, req *chihaya.AnnounceRequest, resp *chihaya.AnnounceResponse) error {
return nil
}
for i := len(c.mw) - 1; i >= 0; i-- {
final = c.mw[i](final)
}
@@ -35,8 +33,8 @@ func (c *announceChain) Handler() AnnounceHandler {
var announceMiddleware = make(map[string]AnnounceMiddleware)
// RegisterAnnounceMiddleware makes a middleware available to the tracker under
// the provided named.
// RegisterAnnounceMiddleware makes a middleware globally available under the
// provided named.
//
// If this function is called twice with the same name or if the handler is nil,
// it panics.
@@ -52,12 +50,12 @@ func RegisterAnnounceMiddleware(name string, mw AnnounceMiddleware) {
announceMiddleware[name] = mw
}
// ScrapeHandler is a middleware function that operates on a ScrapeResponse
// before it has been delivered to a client.
type ScrapeHandler func(*config.TrackerConfig, *chihaya.ScrapeRequest, *chihaya.ScrapeResponse) error
// ScrapeHandler is a function that operates on a ScrapeResponse before it has
// been delivered to a client.
type ScrapeHandler func(*chihaya.TrackerConfig, *chihaya.ScrapeRequest, *chihaya.ScrapeResponse) error
// ScrapeMiddleware is higher-order ScrapeHandler used to implement modular
// behavior processing a scrape.
// ScrapeMiddleware is higher-order function used to implement the chaining of
// ScrapeHandlers.
type ScrapeMiddleware func(ScrapeHandler) ScrapeHandler
type scrapeChain struct{ mw []ScrapeMiddleware }
@@ -67,7 +65,7 @@ func (c *scrapeChain) Append(mw ...ScrapeMiddleware) {
}
func (c *scrapeChain) Handler() ScrapeHandler {
final := func(cfg *config.TrackerConfig, req *chihaya.ScrapeRequest, resp *chihaya.ScrapeResponse) error {
final := func(cfg *chihaya.TrackerConfig, req *chihaya.ScrapeRequest, resp *chihaya.ScrapeResponse) error {
return nil
}
for i := len(c.mw) - 1; i >= 0; i-- {
@@ -78,8 +76,8 @@ func (c *scrapeChain) Handler() ScrapeHandler {
var scrapeMiddleware = make(map[string]ScrapeMiddleware)
// RegisterScrapeMiddleware makes a middleware available to the tracker under
// the provided named.
// RegisterScrapeMiddleware makes a middleware globally available under the
// provided named.
//
// If this function is called twice with the same name or if the handler is nil,
// it panics.