Version: v0.0.0-...-8a6596c Latest Latest

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

Go to latest
Published: May 9, 2021 License: AGPL-3.0 Imports: 21 Imported by: 0




View Source
const DefaultTheme = LightTheme


View Source
var Empty = Render{}

Empty is a blank page.


func RegisterCSSFile

func RegisterCSSFile(path string)

RegisterCSSFile adds the CSS file to the global CSS file, which can be located in /components.css

func SetThemeCookie

func SetThemeCookie(w http.ResponseWriter, theme Theme)

func SetWeakCookie

func SetWeakCookie(w http.ResponseWriter, k, v string)

SetWeakCookie sets an insecure cookie for user settings.

func ThemeM

func ThemeM(next http.Handler) http.Handler


type CommonCtx

type CommonCtx struct {

	Config   Config
	Username string
	Session  *client.Session

type Component

type Component struct {
	Template   string
	Components map[string]Component
	Functions  template.FuncMap

type Config

type Config struct {
	SiteName string `toml:"siteName"`

func NewConfig

func NewConfig() Config

func (*Config) Validate

func (c *Config) Validate() error

type ErrorRenderer

type ErrorRenderer = func(r *Request, err error) (Render, error)

ErrorRenderer represents a renderable page for errors.

type Mux

type Mux struct {
	// contains filtered or unexported fields

func NewHTTPMux

func NewHTTPMux(backendHTTP string, cfg Config) *Mux

NewHTTPMux creates a new frontend muxer with the given backendHTTP endpoint. This endpoint will be used to make HTTP requests to the server.

func NewMux

func NewMux(backendSocket string, cfg Config) *Mux

NewMux creates a new frontend muxer with the given backendSocket as the Unix socket path to call the backend.

func (*Mux) Delete

func (m *Mux) Delete(route string, r Renderer)

func (*Mux) Get

func (m *Mux) Get(route string, r Renderer)

func (*Mux) M

func (m *Mux) M(render Renderer) http.HandlerFunc

M is the middleware wrapper.

func (*Mux) Mount

func (m *Mux) Mount(route string, mounter func(Muxer) http.Handler)

func (*Mux) NewRequest

func (m *Mux) NewRequest(w http.ResponseWriter, r *http.Request) *Request

NewRequest makes a new internal request struct. The returned Request pointer is never nil.

func (*Mux) Post

func (m *Mux) Post(route string, r Renderer)

func (*Mux) SetErrorRenderer

func (m *Mux) SetErrorRenderer(r ErrorRenderer)

type Muxer

type Muxer interface {
	M(Renderer) http.HandlerFunc

Muxer implements the interface that's passable to pages' mount functions.

type Page

type Page struct {
	Template   string
	Components map[string]Component
	Functions  template.FuncMap

type Render

type Render struct {
	Title       string // og:title, <title>
	Description string // og:description
	ImageURL    string // og:image

	Body template.HTML

type Renderer

type Renderer = func(r *Request) (Render, error)

Renderer represents a renderable page.

type Request

type Request struct {

	Writer http.ResponseWriter
	// contains filtered or unexported fields

func (*Request) Cookie

func (r *Request) Cookie(name string) *http.Cookie

Cookie returns the cookie from the Request. These cookies won't have anything else filled other than the value field.

func (*Request) CookieValue

func (r *Request) CookieValue(name string) string

func (*Request) FlushCookies

func (r *Request) FlushCookies()

FlushCookies dumps all the session state's cookies to the response writer.

func (*Request) IDParam

func (r *Request) IDParam() (int64, error)

IDParam returns the ID parameter from chi.

func (*Request) Me

func (r *Request) Me() (smolboard.UserPart, error)

func (*Request) Param

func (r *Request) Param(name string) string

func (*Request) Push

func (r *Request) Push(url string)

func (*Request) Redirect

func (r *Request) Redirect(path string, code int)

func (*Request) SetWeakCookie

func (r *Request) SetWeakCookie(k, v string)

SetWeakCookie calls SetWeakCookie with the writer in Request.

func (*Request) TokenCookie

func (r *Request) TokenCookie() *http.Cookie

TokenCookie returns the cookie that contains the token if any or nil if none. This function searches the cookie from the smolboard client.

type Template

type Template struct {
	// contains filtered or unexported fields

func BuildPage

func BuildPage(n string, p Page) *Template

func (*Template) Render

func (t *Template) Render(v interface{}) template.HTML

Render renders the template with the given argument into HTML.

type Theme

type Theme uint8
const (
	LightTheme Theme = iota
	NordTheme // also light


func GetTheme

func GetTheme(ctx context.Context) Theme

func ParseTheme

func ParseTheme(name string) Theme

func (Theme) String

func (t Theme) String() string

func (Theme) URL

func (t Theme) URL() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL