diff --git a/middleware/torrentapproval/container/container.go b/middleware/torrentapproval/container/container.go index 28f718b..5a00cee 100644 --- a/middleware/torrentapproval/container/container.go +++ b/middleware/torrentapproval/container/container.go @@ -6,9 +6,7 @@ import ( "sync" ) -type Builder interface { - Build([]byte) (Container, error) -} +type Builder func ([]byte) (Container, error) var ( buildersMU sync.Mutex @@ -43,7 +41,7 @@ func GetContainer(name string, confBytes []byte) (Container, error) { if builder, exist := builders[name]; !exist { err = ErrContainerDoesNotExist } else { - cn, err = builder.Build(confBytes) + cn, err = builder(confBytes) } return cn, err } diff --git a/middleware/torrentapproval/container/directory/directory.go b/middleware/torrentapproval/container/directory/directory.go index 1635d1a..c4063e1 100644 --- a/middleware/torrentapproval/container/directory/directory.go +++ b/middleware/torrentapproval/container/directory/directory.go @@ -11,17 +11,15 @@ import ( ) func init() { - container.Register("directory", builder{}) + container.Register("directory", build) } -type builder struct {} - type Config struct { WhitelistPath string `yaml:"whitelist_path"` BlacklistPath string `yaml:"blacklist_path"` } -func (b builder) Build(confBytes []byte) (container.Container, error) { +func build(confBytes []byte) (container.Container, error) { c := new(Config) if err := yaml.Unmarshal(confBytes, c); err != nil { return nil, fmt.Errorf("unable to deserialise configuration: %v", err) diff --git a/middleware/torrentapproval/container/list/list.go b/middleware/torrentapproval/container/list/list.go index 77a89c9..ad2df74 100644 --- a/middleware/torrentapproval/container/list/list.go +++ b/middleware/torrentapproval/container/list/list.go @@ -10,11 +10,9 @@ import ( ) func init() { - container.Register("list", builder{}) + container.Register("list", build) } -type builder struct {} - type Config struct { Whitelist []string `yaml:"whitelist"` Blacklist []string `yaml:"blacklist"` @@ -22,7 +20,7 @@ type Config struct { var DUMMY struct{} -func (b builder) Build(confBytes []byte) (container.Container, error) { +func build(confBytes []byte) (container.Container, error) { c := new(Config) if err := yaml.Unmarshal(confBytes, c); err != nil { return nil, fmt.Errorf("unable to deserialise configuration: %v", err) diff --git a/middleware/torrentapproval/torrentapproval.go b/middleware/torrentapproval/torrentapproval.go index 45e34b5..b2a51db 100644 --- a/middleware/torrentapproval/torrentapproval.go +++ b/middleware/torrentapproval/torrentapproval.go @@ -44,7 +44,7 @@ func (d driver) NewHook(optionBytes []byte) (middleware.Hook, error) { return nil, err } - if c, err := container.GetContainer(cfg.Name, confBytes); err == nil{ + if c, err := container.GetContainer(cfg.Name, confBytes); err == nil { return &hook{c}, nil } else { return nil, err @@ -58,24 +58,23 @@ type hook struct { hashContainer container.Container } - -func (h *hook) HandleAnnounce(ctx context.Context, req *bittorrent.AnnounceRequest, resp *bittorrent.AnnounceResponse) (context.Context, error) { +func (h *hook) HandleAnnounce(ctx context.Context, req *bittorrent.AnnounceRequest, _ *bittorrent.AnnounceResponse) (context.Context, error) { var err error - if !h.hashContainer.Contains(req.InfoHash){ + if !h.hashContainer.Contains(req.InfoHash) { err = ErrTorrentUnapproved } return ctx, err } -func (h *hook) HandleScrape(ctx context.Context, req *bittorrent.ScrapeRequest, resp *bittorrent.ScrapeResponse) (context.Context, error) { +func (h *hook) HandleScrape(ctx context.Context, req *bittorrent.ScrapeRequest, _ *bittorrent.ScrapeResponse) (context.Context, error) { // Scrapes don't require any protection. return ctx, nil } func (h *hook) Stop() stop.Result { - if st, isOk := h.hashContainer.(stop.Stopper); isOk{ + if st, isOk := h.hashContainer.(stop.Stopper); isOk { return st.Stop() } return stop.AlreadyStopped