Help us shape the future of Go! Take the 2026 Go Developer Survey

failure

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package failure classifies a failed action for the Outcome a provider reports, and answers and reports a provider's requests. Its functions and the Reporter are safe for concurrent use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Result

func Result(err error) auth.Result

Result is the Result of an action that failed with err (not nil): auth.ResultError when auth.ResponseFor answers err with 500, auth.ResultDenied (a refusal) otherwise.

func UnlessAbsent

func UnlessAbsent(err error) error

UnlessAbsent returns err unless it only says that there is nothing (auth.ErrUnauthenticated), e.g. no session or no identity in it.

Types

type Reporter

type Reporter struct {
	// contains filtered or unexported fields
}

Reporter answers a provider's failed requests and reports the outcome of every request.

func NewReporter

func NewReporter(options *ReporterOptions) (*Reporter, error)

NewReporter validates options and returns a Reporter working on a copy of them.

func (*Reporter) Refuse

func (r *Reporter) Refuse(ctx context.Context, writer http.ResponseWriter, outcome auth.Outcome)

Refuse answers outcome.Err as JSON and reports the outcome as a failure.

func (*Reporter) RefuseCallback

func (r *Reporter) RefuseCallback(ctx context.Context, writer http.ResponseWriter, outcome auth.Outcome)

RefuseCallback is Refuse, except that with ErrorURL set the failure (a refusal or code=internal) redirects to ErrorURL?code=<code>.

func (*Reporter) Report

func (r *Reporter) Report(ctx context.Context, outcome auth.Outcome)

Report sets Provider on outcome and passes it to the Observer.

func (*Reporter) ReportFailure

func (r *Reporter) ReportFailure(ctx context.Context, outcome auth.Outcome)

ReportFailure reports outcome as denied (a refusal) or error (answered with 500).

type ReporterOptions

type ReporterOptions struct {
	Provider string        // required; set as Outcome.Provider
	Observer auth.Observer // optional; nil reports nothing
	ErrorURL string        // optional; where RefuseCallback sends the browser: a path or an absolute http(s) URL, without a fragment
}

ReporterOptions configures NewReporter.

Jump to

Keyboard shortcuts

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