http

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrReadingAuthCookie  = fmt.Errorf("failed to read auth cookie")
	ErrInvalidAuthCookie  = fmt.Errorf("invalid auth cookie")
	ErrInvalidAccessToken = fmt.Errorf("invalid access token")
)

ErrReadingAuthCookie occurs when tavern is unable to read the auth cookie of the request. ErrInvalidAuthCookie occurs when the auth cookie provided by the request is invalid. ErrInvalidAccessToken occurs when the access token provided by the request is invalid.

Functions

This section is empty.

Types

type Authenticator

type Authenticator interface {
	Authenticate(r *http.Request) (context.Context, error)
}

An Authenticator returns an authenticated context based on the given http request. If no authenticated identity is associated with the request, the authenticator should just return the request context, and it should not error in this case. This is to allow unauthenticated endpoints to function as expected, authorization will occur later in the stack.

type Endpoint

type Endpoint struct {
	// LoginRedirectURI defines the path to redirect unauthenticated requests to.
	// If unset, no redirect will be performed.
	LoginRedirectURI string

	http.Handler
}

An Endpoint wraps an HTTP handler with configuration options.

func (Endpoint) ServeHTTP

func (endpoint Endpoint) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP traffic based on the configured handler.

type Logger

type Logger interface {
	Log(r *http.Request)
}

A Logger to display information about the incoming request.

type Option

type Option func(*Server)

An Option to configure a Tavern HTTP Server.

func WithAuthentication added in v0.0.6

func WithAuthentication(graph *ent.Client) Option

WithAuthentication enables http request authentication for the server.

func WithAuthenticationBypass

func WithAuthenticationBypass(graph *ent.Client) Option

WithAuthenticationBypass enables requests to bypass authentication for the server.

func WithRequestLogging

func WithRequestLogging(logger *log.Logger) Option

WithRequestLogging configures HTTP request logging for the server.

type RouteMap

type RouteMap map[string]http.Handler

A RouteMap contains a mapping of route patterns to http handlers.

func (RouteMap) Handle

func (routes RouteMap) Handle(pattern string, handler http.Handler)

Handle registers the handler for the given pattern. If a handler already exists for pattern, Handle panics.

func (RouteMap) HandleFunc

func (routes RouteMap) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

HandleFunc registers the handler function for the given pattern.

type ServeMux

type ServeMux interface {
	Handle(pattern string, handler http.Handler)
}

ServeMux used for endpoint registration.

type Server

type Server struct {
	Authenticator
	Logger
	http.Handler
}

A Server for Tavern HTTP traffic.

func NewServer

func NewServer(routes RouteMap, options ...Option) *Server

NewServer configures a new server for serving HTTP traffic.

func (*Server) ServeHTTP

func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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