app

package
v0.0.0-...-b7c93c8 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleError

func HandleError(w http.ResponseWriter, err error)

func RemoveIndex

func RemoveIndex(s []string, index int) []string

func RespondJSON

func RespondJSON[T any](w http.ResponseWriter, status int, payload T) error

func RespondOK

func RespondOK(w http.ResponseWriter, response string) error

func RespondStatus

func RespondStatus(w http.ResponseWriter, status int) error

func RespondText

func RespondText(w http.ResponseWriter, status int, payload string) error

Types

type API

type API struct {
	*Config
	R map[string]any
}

func (API) ServeHTTP

func (api API) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Auth

type Auth struct {
	*Config
	R map[string]any
}

func (Auth) ServeHTTP

func (a Auth) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Config

type Config struct {
	Addr         *string
	Router       *http.ServeMux
	User         *string
	Password     *string
	CsrfSecret   *string
	CacheTag     *string
	DB           DB
	Domain       *string
	Version      *string
	DBConnection *string
	Runtime      *string
	River        *river.Client[pgx.Tx]
}

func (*Config) CacheHandler

func (c *Config) CacheHandler(h http.Handler) http.HandlerFunc

func (*Config) CreateCsrfToken

func (c *Config) CreateCsrfToken(sessionID string) (string, error)

func (*Config) GetCsrfToken

func (c *Config) GetCsrfToken(r *http.Request) (string, error)

func (*Config) InitTemplate

func (c *Config) InitTemplate(custom Tmpl, r *http.Request) Tmpl

func (*Config) Redirect

func (c *Config) Redirect(w http.ResponseWriter, r *http.Request, message string) error

func (*Config) Respond

func (c *Config) Respond(w http.ResponseWriter, r *http.Request, t Tmpl) error

func (*Config) RespondData

func (c *Config) RespondData(w http.ResponseWriter, r *http.Request, handler string, data any) error

func (*Config) RespondErr

func (c *Config) RespondErr(w http.ResponseWriter, r *http.Request, handler string, message string) error

func (*Config) ValidCsrfToken

func (c *Config) ValidCsrfToken(r *http.Request) bool

type DB

type DB struct {
	Client *gorm.DB
}

func (*DB) GetCurrentUser

func (db *DB) GetCurrentUser(r *http.Request) (M.User, error)

func (*DB) GetCurrentUserID

func (db *DB) GetCurrentUserID(r *http.Request) (uuid.UUID, error)

func (*DB) GetSessionID

func (db *DB) GetSessionID(r *http.Request) (bool, string)

func (*DB) LoggedIn

func (db *DB) LoggedIn(r *http.Request) bool

type Error

type Error interface {
	error
	Status() int
}

type Public

type Public struct {
	*Config
	R map[string]any
}

func (Public) ServeHTTP

func (p Public) ServeHTTP(w http.ResponseWriter, r *http.Request)

type StatusError

type StatusError struct {
	Code int
	Err  error
	Msg  string
}

func RespondError

func RespondError(args ...interface{}) StatusError

func (StatusError) Error

func (se StatusError) Error() string

func (StatusError) Message

func (se StatusError) Message() string

func (StatusError) Status

func (se StatusError) Status() int

type Tmpl

type Tmpl struct {
	Handler  string
	Fn       string
	Format   string
	Layout   string
	Partial  bool
	Code     int
	Data     any
	CacheTag *string
	Csrf     string
	// Turbo Streams
	Action  string
	Target  string // targeting one element
	Targets string // targeting multiple elements
}

Jump to

Keyboard shortcuts

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