middleware

package
v0.0.0-...-ca8de47 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicAuth

func BasicAuth(uss radio.UserStorageService) func(http.Handler) http.Handler

BasicAuth lets users login through the HTTP Basic Authorization header

This should ONLY be used for situations where a human cannot input the login info somehow. Namely for icecast source clients.

func BasicAuthFailure

func BasicAuthFailure(w http.ResponseWriter, r *http.Request)

BasicAuthFailure writes a http StatusUnauthorized response with extra text that some icecast source clients expect

func GetTrack

func GetTrack(ctx context.Context) (radio.Song, bool)

GetTrack returns the track from the given context if one exists. See TrackCtx for supplier of this

func GetUser

func GetUser(ctx context.Context) (radio.User, bool)

GetUser returns the user from the given context if one exists.

func InputMiddleware

func InputMiddleware(cfg config.Config, status *util.Value[radio.Status]) func(http.Handler) http.Handler

InputMiddleware generates an Input for each request and makes it available through InputFromRequest

func NewSessionManager

func NewSessionManager(ctx context.Context, storage radio.SessionStorageService) *scs.SessionManager

func RequestWithUser

func RequestWithUser(r *http.Request, u *radio.User) *http.Request

RequestWithUser adds a user to a requests context and returns the new updated request after, user can be retrieved by UserFromContext

func RequirePermission

func RequirePermission(perm radio.UserPermission, handler http.HandlerFunc) http.HandlerFunc

func TrackCtx

func TrackCtx(storage radio.TrackStorageService) func(http.Handler) http.Handler

TrackCtx reads an URL parameter named TrackID and tries to find the track associated with it.

func UserByDJIDCtx

func UserByDJIDCtx(storage radio.UserStorageService) func(http.Handler) http.Handler

UserByDJIDCtx reads an URL router parameter named DJID and tries to find the user associated with it. The result can be retrieved with GetUser

func UserFromContext

func UserFromContext(ctx context.Context) *radio.User

UserFromContext returns the user stored in the context, a user is available after the LoginMiddleware

Types

type Authentication

type Authentication interface {
	UserMiddleware(http.Handler) http.Handler
	LoginMiddleware(http.Handler) http.Handler
	GetLogin(http.ResponseWriter, *http.Request)
	PostLogin(http.ResponseWriter, *http.Request)
	LogoutHandler(http.ResponseWriter, *http.Request)
}

func NewAuthentication

func NewAuthentication(storage radio.StorageService, tmpl templates.Executor, sessions *scs.SessionManager) Authentication

type Input

type Input struct {
	Now        time.Time
	IsUser     bool
	IsHTMX     bool
	User       *radio.User
	Status     radio.Status
	StreamURL  template.URL
	RequestURL template.URL
}

Input is a bunch of data that should be accessable to the base template

func InputFromContext

func InputFromContext(ctx context.Context) Input

func InputFromRequest

func InputFromRequest(r *http.Request) Input

InputFromRequest returns the Input associated with the request

func (Input) TemplateName

func (Input) TemplateName() string

type JSONCodec

type JSONCodec struct{}

JSONCodec implements scs.Codec

func (JSONCodec) Decode

func (JSONCodec) Decode(b []byte) (time.Time, map[string]interface{}, error)

Decode implements scs.Codec

func (JSONCodec) Encode

func (JSONCodec) Encode(deadline time.Time, values map[string]interface{}) ([]byte, error)

Encode implements scs.Codec

type LoginInput

type LoginInput struct {
	Input
	CSRFTokenInput template.HTML
	ErrorMessage   string
}

func NewLoginInput

func NewLoginInput(r *http.Request, message string) LoginInput

func (LoginInput) TemplateBundle

func (LoginInput) TemplateBundle() string

type SessionStore

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

SessionStore implements scs.Store by using a radio.SessionStorageService as its backing storage.

func NewSessionStore

func NewSessionStore(ctx context.Context, storage radio.SessionStorageService) SessionStore

NewSessionStore returns a new SessionStore that uses the storage provided

func (SessionStore) Commit

func (ss SessionStore) Commit(token string, b []byte, expiry time.Time) error

Commit implements scs.Store

func (SessionStore) Delete

func (ss SessionStore) Delete(token string) error

Delete implements scs.Store

func (SessionStore) Find

func (ss SessionStore) Find(token string) ([]byte, bool, error)

Find implements scs.Store

Jump to

Keyboard shortcuts

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