onfinished

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package onfinished registers callbacks that run when an HTTP response finishes, mirroring the behavior of the npm on-finished library in an idiomatic, httptest-friendly way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tracker

type Tracker struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

Tracker wraps an http.ResponseWriter and tracks whether the response has finished. Callbacks registered via OnFinished are invoked once when Done is called.

func New

func New(w http.ResponseWriter) *Tracker

New wraps w in a Tracker. The returned Tracker implements http.ResponseWriter and passes WriteHeader, Write, and Flush through to w.

func (*Tracker) Done

func (t *Tracker) Done(err error)

Done marks the response as finished and invokes all registered callbacks with err. It is idempotent: subsequent calls do nothing.

func (*Tracker) Flush

func (t *Tracker) Flush()

Flush implements http.Flusher when the underlying ResponseWriter supports it; otherwise it is a no-op.

func (*Tracker) IsFinished

func (t *Tracker) IsFinished() bool

IsFinished reports whether the response has finished.

func (*Tracker) OnFinished

func (t *Tracker) OnFinished(fn func(err error))

OnFinished registers fn to be called when the response finishes. If the response has already finished, fn is invoked immediately with the recorded error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL