internal

package
v0.0.0-...-f6d8437 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const AuthCookieName = "home-auth-token"

Variables

View Source
var (
	EnvDev  = "dev"
	EnvProd = "prod"
)
View Source
var ErrAuthInvalidToken = errors.New("invalid token")

Functions

func AuthClearCookie

func AuthClearCookie(w http.ResponseWriter)

func AuthCookieMiddleware

func AuthCookieMiddleware(tokenFunc AuthTokenFunc, unauthorizedHandler http.HandlerFunc) func(http.Handler) http.Handler

func AuthHeaderMiddleware

func AuthHeaderMiddleware(tokenFunc AuthTokenFunc, unauthorizedHandler http.HandlerFunc) func(http.Handler) http.Handler

func AuthRequired

func AuthRequired(unauthorizedHandler http.HandlerFunc) func(http.Handler) http.Handler

func AuthSetCookie

func AuthSetCookie(w http.ResponseWriter, t string)

func Bind

func Bind(r *http.Request, v interface{}) ([]string, bool)

func Env

func Env() string

Env returns which environment we're running in. Currently this only checks if stdin is a tty, but in the future we might use environment variables.

func ExtractUser

func ExtractUser(ctx context.Context) *models.UserInfo

func GetVersion

func GetVersion(overrides ...string) string

GetVersion extracts the commit information from the build info, falling back to the string "unknown". If any non-empty "override" variables are passed in, they will override the returned version. This still allows for stamping releases, while also providing a fallback.

func NewLogger

func NewLogger() (*slog.Logger, error)

Types

type AuthTokenFunc

type AuthTokenFunc func(ctx context.Context, token string) (*models.UserInfo, error)

AuthTokenFunc takes a token and returns either a UserInfo object or an error.

If ErrAuthInvalidToken is returned, a 401 will be returned to the user, otherwise a 500.

type LoggerConfig

type LoggerConfig struct {
	Level slog.Level `envconfig:"level"`
}

type Password

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

func NewPasswordFromPlaintext

func NewPasswordFromPlaintext(password string) (*Password, error)

func (*Password) BytesValue

func (p *Password) BytesValue() ([]byte, error)

func (*Password) Matches

func (p *Password) Matches(password string) (bool, error)

func (*Password) ScanBytes

func (p *Password) ScanBytes(v []byte) error

func (*Password) Set

func (p *Password) Set(password string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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