Skip to content

Commit 5e9be5a

Browse files
authored
hooks: Add documentation for NewHandlerWithHooks
Closes #1007
1 parent 285b2f5 commit 5e9be5a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pkg/hooks/hooks.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,19 @@ func invokeHookSync(typ HookType, event handler.HookEvent, hookHandler HookHandl
211211
return true, res, nil
212212
}
213213

214+
// NewHandlerWithHooks creates a tusd request handler, whose notifcation channels and callbacks are configured to
215+
// emit the hooks on the provided hook handler. NewHandlerWithHooks will overwrite the `config.Notify*` and `config.*Callback`
216+
// fields depending on the enabled hooks. These can be controlled via the `enabledHooks` slice. Non-enabled hooks will
217+
// not be emitted.
218+
//
219+
// If you want to create an UnroutedHandler instead of the routed handler, you can first create a routed handler and then
220+
// extract an unrouted one:
221+
// routedHandler := hooks.NewHandlerWithHooks(...)
222+
// unroutedHandler := routedHandler.UnroutedHandler
223+
//
224+
// Note: NewHandlerWithHooks sets up a goroutine to consume the notfication channels (CompleteUploads, TerminatedUploads,
225+
// CreatedUploads, UploadProgress) on the created handler. These channels must not be consumed by the caller or otherwise
226+
// events might not be passed to the hook handler.
214227
func NewHandlerWithHooks(config *handler.Config, hookHandler HookHandler, enabledHooks []HookType) (*handler.Handler, error) {
215228
if err := hookHandler.Setup(); err != nil {
216229
return nil, fmt.Errorf("unable to setup hooks for handler: %s", err)

0 commit comments

Comments
 (0)