godest

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2023 License: Apache-2.0 Imports: 20 Imported by: 2

README

godest

A framework for writing Go web apps with modest Javascript approaches.

Usage

Development

To install various backend development tools, run make install.

To run linter checks on Go files and Rego policy files, run make lint. To autoformat Go files and Rego policy files, run make fmt.

License

Copyright Prakash Lab and the Sargassum project contributors.

SPDX-License-Identifier: Apache-2.0 OR BlueOak-1.0.0

You can use this project either under the Apache 2.0 License or under the Blue Oak Model License 1.0.0; you get to decide. We chose the Apache license because it's OSI-approved, and because it goes well together with the Solderpad Hardware License, which is a license for open hardware used in other related projects but not this project. We prefer the Blue Oak Model License because it's easier to read and understand.

Documentation

Overview

Package godest provides a mildly opinionated framework for more easily writing web apps with modest Javascript approaches, especially with the Hotwire libraries. It provides support for using templates in a clear and structured way. It also makes it easy to embed all templates, static assets (e.g. images) and app-related assets (e.g. JS bundles) into the compiled server binary, and it takes care of the details of browser caching for assets and templated pages. Finally, it provides some standalone utilities for caching data on the server, getting the values of environment variables, and using cookies for form-based authentication.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeCSPHash added in v0.4.3

func ComputeCSPHash(resource []byte) string

func HandleFS

func HandleFS(routePrefix string, fsys fs.FS, age time.Duration) http.Handler

func HandleFSFileRevved

func HandleFSFileRevved(routePrefix string, fsys fs.FS) http.Handler

Types

type EchoRouter

type EchoRouter interface {
	CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
}

EchoRouter is a simple interface which specifies echo.Route addition functions which are present on both echo.Echo and echo.Group, since we want to allow using either of them for path registration.

type Embeds

type Embeds struct {
	StaticFS    fs.FS
	StaticHFS   *hashfs.FS
	TemplatesFS fs.FS
	AppFS       fs.FS
	AppHFS      *hashfs.FS
	FontsFS     fs.FS
}

func (Embeds) GetAppHashedNamer

func (e Embeds) GetAppHashedNamer(urlPrefix string) func(string) string

func (Embeds) GetStaticHashedNamer

func (e Embeds) GetStaticHashedNamer(urlPrefix string) func(string) string

type HeaderOption

type HeaderOption func(http.Header)

func WithAlwaysRevalidate

func WithAlwaysRevalidate() HeaderOption

func WithContentType

func WithContentType(contentType string) HeaderOption

func WithRevalidateWhenStale

func WithRevalidateWhenStale(maxAge int) HeaderOption

func WithUncacheable

func WithUncacheable() HeaderOption

type Inlines

type Inlines struct {
	CSS      map[string]template.CSS
	JS       map[string]template.JS
	JSStr    map[string]template.JSStr
	HTML     map[string]template.HTML
	HTMLAttr map[string]template.HTMLAttr
	SrcSet   map[string]template.Srcset
}

func (Inlines) ComputeCSSHashesForCSP

func (i Inlines) ComputeCSSHashesForCSP() (hashes []string)

func (Inlines) ComputeJSHashesForCSP

func (i Inlines) ComputeJSHashesForCSP() (hashes []string)

type Logger

type Logger interface {
	Print(i ...interface{})
	Printf(format string, args ...interface{})
	Debug(i ...interface{})
	Debugf(format string, args ...interface{})
	Info(i ...interface{})
	Infof(format string, args ...interface{})
	Warn(i ...interface{})
	Warnf(format string, args ...interface{})
	Error(i ...interface{})
	Errorf(format string, args ...interface{})
	Fatal(i ...interface{})
	Fatalf(format string, args ...interface{})
	Panic(i ...interface{})
	Panicf(format string, args ...interface{})
}

Logger is a reduced interface for loggers.

type RenderData

type RenderData struct {
	Meta struct {
		Path       string
		RequestURI string
	}
	Inlines interface{}
	Data    interface{}
	Auth    interface{}
}

type TemplateRenderer

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

func NewTemplateRenderer

func NewTemplateRenderer(
	e Embeds, inlines interface{}, funcs ...template.FuncMap,
) (tr TemplateRenderer, err error)

func (TemplateRenderer) CacheablePage

func (tr TemplateRenderer) CacheablePage(
	w http.ResponseWriter, r *http.Request,
	templateName string, templateData interface{}, authData interface{},
	headerOptions ...HeaderOption,
) error

func (TemplateRenderer) MustHave

func (tr TemplateRenderer) MustHave(templateNames ...string)

func (TemplateRenderer) Page

func (tr TemplateRenderer) Page(
	w http.ResponseWriter, r *http.Request,
	status int, templateName string, templateData interface{}, authData interface{},
	headerOptions ...HeaderOption,
) error

func (TemplateRenderer) TurboStream

func (tr TemplateRenderer) TurboStream(
	w http.ResponseWriter, messages ...turbostreams.Message,
) error

func (TemplateRenderer) WritePartial

func (tr TemplateRenderer) WritePartial(
	w io.Writer, partialName string, partialData interface{},
) error

func (TemplateRenderer) WriteTurboStream

func (tr TemplateRenderer) WriteTurboStream(w io.Writer, messages ...turbostreams.Message) error

Directories

Path Synopsis
Package actioncable provides a server-side implementation of the Rails Action Cable protocol (https://docs.anycable.io/misc/action_cable_protocol)
Package actioncable provides a server-side implementation of the Rails Action Cable protocol (https://docs.anycable.io/misc/action_cable_protocol)
Package authn provides a high-level client for user authentication
Package authn provides a high-level client for user authentication
Package clientcache provides support for caching requests as a client
Package clientcache provides support for caching requests as a client
Package database provides a high-level relational database interface with schema migration, connection pooling, prepared statement, and embedded query support, wrapping around zombiezen.com/go/sqlite's CGo-free sqlite interface
Package database provides a high-level relational database interface with schema migration, connection pooling, prepared statement, and embedded query support, wrapping around zombiezen.com/go/sqlite's CGo-free sqlite interface
Package env contains code for handling environment variables
Package env contains code for handling environment variables
Package handling provides utilities for handlers and background workers
Package handling provides utilities for handlers and background workers
Package httperr provides utilities for writing human-readable HTTP error page templates.
Package httperr provides utilities for writing human-readable HTTP error page templates.
Package marshaling provides a uniform thread-safe interface to various encoding/decoding formats such as Gob, JSON, and MessagePack, following the JSON marshal/unmarshal function interface.
Package marshaling provides a uniform thread-safe interface to various encoding/decoding formats such as Gob, JSON, and MessagePack, following the JSON marshal/unmarshal function interface.
Package middleware provides middleware functionality not provided by other packages.
Package middleware provides middleware functionality not provided by other packages.
Package opa provides a high-level client for using embedded Rego policies with OPA
Package opa provides a high-level client for using embedded Rego policies with OPA
Package pubsub provides pub-sub functionality.
Package pubsub provides pub-sub functionality.
Package session standardizes session management with Gorilla sessions
Package session standardizes session management with Gorilla sessions
memstore
Package memstore provides an in-RAM (non-persistent) session store
Package memstore provides an in-RAM (non-persistent) session store
sqlitestore
Package sqlitestore store provides a sqlite-backed session store using [database.DB]
Package sqlitestore store provides a sqlite-backed session store using [database.DB]
Package turbostreams provides server-side support for sending Hotwired Turbo Streams in POST responses as well as over Action Cable.
Package turbostreams provides server-side support for sending Hotwired Turbo Streams in POST responses as well as over Action Cable.

Jump to

Keyboard shortcuts

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