mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-23 08:14:48 -07:00
storage: add storage interface and registration
This also fixes bugs in the Hooks registration.
This commit is contained in:
10
hooks.go
10
hooks.go
@@ -16,9 +16,6 @@ package trakr
|
||||
|
||||
import "github.com/jzelinskie/trakr/bittorrent"
|
||||
|
||||
// HookConstructor is a function used to create a new instance of a Hook.
|
||||
type HookConstructor func(interface{}) (Hook, error)
|
||||
|
||||
// Hook abstracts the concept of anything that needs to interact with a
|
||||
// BitTorrent client's request and response to a BitTorrent tracker.
|
||||
type Hook interface {
|
||||
@@ -26,6 +23,9 @@ type Hook interface {
|
||||
HandleScrape(context.Context, bittorrent.ScrapeRequest, bittorrent.ScrapeResponse) error
|
||||
}
|
||||
|
||||
// HookConstructor is a function used to create a new instance of a Hook.
|
||||
type HookConstructor func(interface{}) (Hook, error)
|
||||
|
||||
var preHooks = make(map[string]HookConstructor)
|
||||
|
||||
// RegisterPreHook makes a HookConstructor available by the provided name.
|
||||
@@ -44,7 +44,7 @@ func RegisterPreHook(name string, con HookConstructor) {
|
||||
|
||||
// NewPreHook creates an instance of the given PreHook by name.
|
||||
func NewPreHook(name string, config interface{}) (Hook, error) {
|
||||
con := preHooks[name]
|
||||
con, ok := preHooks[name]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("trakr: unknown PreHook %q (forgotten import?)", name)
|
||||
}
|
||||
@@ -69,7 +69,7 @@ func RegisterPostHook(name string, con HookConstructor) {
|
||||
|
||||
// NewPostHook creates an instance of the given PostHook by name.
|
||||
func NewPostHook(name string, config interface{}) (Hook, error) {
|
||||
con := preHooks[name]
|
||||
con, ok := preHooks[name]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("trakr: unknown PostHook %q (forgotten import?)", name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user