dvmweb

package module
v0.0.0-...-d623804 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 20 Imported by: 0

README

dvmweb

Web application for Die Virtuelle Mittagsfrau (Coding da Vinci 2018). Archived: http://web.archive.org/web/20180624045907/https://mittagsfrau.de/

We won a prize!

Out of compentition. Thanks!

Static files

 $ tree -shd static
static
├── [4.0K]  cache
├── [4.0K]  css
├── [4.0K]  images
│   ├── [4.0K]  artifacts
│   ├── [4.0K]  landscapes
│   └── [4.0K]  people
└── [276K]  videos

7 directories

Images are categorized (we need three), videos are named dvm-010203, where 01 names an artifact, 02 names a landscape, 03 a picture of people.

Start server

$ make
go build -o dvmweb cmd/dvmweb/main.go

$ ./dvmweb
2019/02/21 13:11:16 starting server at http://0.0.0.0:3000
...

More on the project

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Inventory *Inventory
	// contains filtered or unexported fields
}

App configuration and data access layer.

func New

func New(dsn, imagesDir, videosDir string) (*App, error)

New create a new web app given a data source and some static directories.

func (*App) String

func (app *App) String() string

type CategorizedImage

type CategorizedImage struct {
	Identifier string
	Path       string
	Category   string
}

CategorizedImage belongs to a category, path records the absolute path. The identifier is just the basename of the image, e.g. 12 for 12.jpg file.

type Handler

type Handler struct {
	App *App

	StaticDir    string
	TemplatesDir string
	Version      string
	// contains filtered or unexported fields
}

Handler implements HTTP request for reading, writing and rendering stories. Has access to application and static directory for assets, e.g. cached images.

func (*Handler) AboutHandler

func (h *Handler) AboutHandler(w http.ResponseWriter, r *http.Request)

AboutHandler render information about the app.

func (*Handler) CacheImageRedirect

func (h *Handler) CacheImageRedirect(w http.ResponseWriter, r *http.Request)

CacheImageRedirect is a helper handler, which creates an image on the fly, of just redirects to the static location of the image.

func (*Handler) IndexHandler

func (h *Handler) IndexHandler(w http.ResponseWriter, r *http.Request)

IndexHandler render the home page.

func (*Handler) NotFoundHandler

func (h *Handler) NotFoundHandler(w http.ResponseWriter, r *http.Request)

NotFoundHandler renders a 404 page.

func (*Handler) RandomRead

func (h *Handler) RandomRead(w http.ResponseWriter, r *http.Request)

RandomRead redirects to a random read page.

func (*Handler) ReadHandler

func (h *Handler) ReadHandler(w http.ResponseWriter, r *http.Request)

ReadHandler reads a story, given a random (image) identifier, e.g. "121403" or similar.

func (*Handler) StoryHandler

func (h *Handler) StoryHandler(w http.ResponseWriter, r *http.Request)

StoryHandler links to a single story. One image can have multiple.

func (*Handler) WriteHandler

func (h *Handler) WriteHandler(w http.ResponseWriter, r *http.Request)

WriteHandler creates a new story.

type Inventory

type Inventory struct {
	Images []CategorizedImage
	Videos []string
}

Inventory make images and videos accessible in various ways. The slices contain the absolute path and a bit of derived information. This struct exposes a few functions, that help to locate images by category, by identifier and the like. TODO(miku): maybe categorize videos as well.

func (*Inventory) ByCategory

func (inv *Inventory) ByCategory(category string) (images []CategorizedImage)

ByCategory returns image paths by category, empty list, if the category does not exist.

func (*Inventory) ByCategoryAndIdentifier

func (inv *Inventory) ByCategoryAndIdentifier(category, identifier string) (*CategorizedImage, error)

ByCategoryAndIdentifier returns the image descriptor for a given category and identifier.

func (*Inventory) Categories

func (inv *Inventory) Categories() (categories []string)

Categories returns the unique image categories.

func (*Inventory) NumAssets

func (inv *Inventory) NumAssets() int

NumAssets returns the total number of items in inventory.

func (*Inventory) Ok

func (inv *Inventory) Ok() bool

Ok checks if the inventory is somewhat usable. Also, we want three categories at the moment.

func (*Inventory) RandomImageIdentifier

func (inv *Inventory) RandomImageIdentifier() (rid string, err error)

RandomImageIdentifier returns a random composite image identifier from fixed categories (artifacts, people, landscape).

func (*Inventory) RandomVideoIdentifier

func (inv *Inventory) RandomVideoIdentifier() (vid string, err error)

RandomVideoIdentifier returns the id to a random video.

type Story

type Story struct {
	Identifier      int       `db:"id"`
	ImageIdentifier string    `db:"imageid"`
	Text            string    `db:"text"`
	Language        string    `db:"language"`
	Created         time.Time `db:"created"`
}

Story describes a minimal story.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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