framework

package
v0.0.0-...-567e4a1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

README

Framework

This is the seed of a Go-based web framework I am writing. It is being built alongside EventHunt but will eventually be pulled out into its own project.

Documentation

Overview

* A resuable app framework.

Index

Constants

This section is empty.

Variables

View Source
var Validator *validator.Validate // validates variables and structs to enforce rules

Functions

This section is empty.

Types

type App

type App struct {
	Router *chi.Mux
	DB     *pgxpool.Pool

	ThemeName string
	ThemeRoot string
	Version   string

	Slug         string
	LoggingLevel *slog.LevelVar
	// contains filtered or unexported fields
}

* App represents the overall state of the application and what makes it unique, * particularly when it comes to environment variables. The database connection * and log level in particular and tracked here.

func NewApp

func NewApp(appName, dbUser, dbPassword, dbHost string, dbPort int, dbName string, opts ...AppOption) (*App, error)

* NewApp returns a new instance of App with many of its fields initialized. * Zero or more AppOptions may be provided to customize default values. * * The called of this function should defer close the DB connection.

func (*App) Name

func (a *App) Name() string

* Name returns the display name used by the App.

func (*App) Port

func (a *App) Port() uint16

* Port returns the TCP port that the app is listening on.

func (*App) Run

func (a *App) Run()

* Run starts the HTTP server up.

type AppOption

type AppOption func(*App)

* AppOption customizes how an App is configured via the constructor.

func WithPort

func WithPort(port uint16) AppOption

* WithPort returns an AppOption to set a custom HTTP port for an App. Logs a * warning when a privileged port is specified.

type BaseModel

type BaseModel struct {
	DB          *pgxpool.Pool `db:"-"`
	ID          uint64        `db:"id"`
	CreatedTime time.Time     `db:"created_time",json:"created_time"`
	UpdatedTime time.Time     `db:"updated_time",json:"updated_time"`
}

* BaseModel defines the minimum that all models should contain in terms of * fields. It's intended to be used with the Model interface.

func (*BaseModel) IDString

func (m *BaseModel) IDString() string

type Flash

type Flash struct {
	Type    FlashType
	Message string
}

* Flash represents a cross-page message to the user. It typically appears once * and then is erased.

func Flashes

func Flashes(session *sessions.Session) []Flash

type FlashType

type FlashType uint8
const (
	FlashSuccess FlashType = iota
	FlashInfo
	FlashWarn
	FlashFail
)

type Model

type Model interface {

	// just a timesaver
	IDString()
	// contains filtered or unexported methods
}

* A model represents structured data that can undergo standard CRUD operations * with a PostgreSQL database. * * As the current plan is not to create an ORM, this interface is around to * simply help reduce boilerplate and for programmers to remember what their * models should have in terms of methods. * * Models implementing this interface should use the suffix `Model` and should * embed BaseModel.

Jump to

Keyboard shortcuts

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