foundation

package module
v0.0.0-...-84f50f4 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: MIT Imports: 9 Imported by: 0

README

foundation

Opinionated Go based web app template using modern tools.

Running the foundation-demo

First, install Mise. Then run:

mise setup 
mise dev

Then open your browser at http://localhost:3000. Change details in foundation_config.json as needed and the app will restart automatically.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assets

type Assets struct {
	Dist http.FileSystem
	Img  http.FileSystem
}

type Config

type Config struct {
	HostPort      string
	DBPath        string
	LitestreamYml string

	Startup       time.Time
	DevFileServer bool
}

Config is the type definition of the JSON config file.

func (*Config) Assets

func (c *Config) Assets() (*Assets, error)

type Context

type Context struct {
	context.Context
	Config *Config
}
type Link struct {
	bun.BaseModel `bun:"table:links,alias:l"`

	ShortLink   string       `bun:"short_link,pk"`
	FullURL     string       `bun:"full_url,notnull"`
	UserID      int64        `bun:"user_id,notnull"`
	CreatedAt   time.Time    `bun:"created_at,nullzero,notnull"`
	UpdatedAt   time.Time    `bun:"updated_at,nullzero,notnull"`
	User        *User        `bun:"rel:has-one,join:user_id=id"`
	Visits      []*LinkVisit `bun:"rel:has-many,join:short_link=short_link"`
	VisitsCount int64        `bun:"visits_count,scanonly"`
}

type LinkVisit

type LinkVisit struct {
	bun.BaseModel `bun:"table:link_visits,alias:lv"`

	ID        int64         `bun:"id,pk,autoincrement"`
	ShortLink string        `bun:"short_link,notnull"`
	UserID    sql.NullInt64 `bun:"user_id"`
	VisitedAt time.Time     `bun:"visited_at,nullzero,notnull"`
}

type Request

type Request struct {
	*Context
	Writer  http.ResponseWriter
	Request *http.Request
	Params  httprouter.Params

	Session         *Session
	PreviousSession *Session
	User            *User
}

func (*Request) CSRFToken

func (r *Request) CSRFToken() string

CSRFToken returns the CSRF token for this request's current session.

func (*Request) PreviousCSRFToken

func (r *Request) PreviousCSRFToken() string

PreviousCSRFToken returns the CSRF token for the potentially rotated out session.

type Session

type Session struct {
	bun.BaseModel `bun:"table:sessions,alias:s"`

	ID        string        `bun:"id,pk"`
	UserID    sql.NullInt64 `bun:"user_id"`
	CreatedAt time.Time     `bun:"created_at,nullzero,notnull"`
	ExpiresAt time.Time     `bun:"expires_at,nullzero,notnull"`
	CSRFToken string        `bun:"csrf_token,nullzero,notnull"`
}

type User

type User struct {
	bun.BaseModel `bun:"table:users,alias:u"`

	ID             int64     `bun:"id,pk,autoincrement"`
	DisplayName    string    `bun:"display_name,notnull"`
	UserName       string    `bun:"user_name,unique"`
	HashedPassword string    `bun:"hashed_password,notnull"`
	CreatedAt      time.Time `bun:"created_at,nullzero,notnull"`
	UpdatedAt      time.Time `bun:"updated_at,nullzero,notnull"`
}

Directories

Path Synopsis
cmd
foundation-demo command
db

Jump to

Keyboard shortcuts

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