starch

package module
v0.0.0-...-1510b09 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: MIT Imports: 8 Imported by: 1

README

starch

Experimental library for declarative go web apps. This had made many people very angry and has been widely regarded as a bad move.

Install

go get -u github.com/awesolabs/starch

Getting Started

in main.go:

package main

import . "github.com/awesolabs/starch"

var app = App{
	Route{
		Path:   "/",
		Handle: Text{`Hello, World!`},
	},
}

func main() {
	if err := app.Run(); err != nil {
		panic(err)
	}
}

Documentation

TBD. For now review various example apps under examples

Documentation

Index

Constants

View Source
const (
	VarIndent = "__indent"
)

Variables

View Source
var (
	VarIterItem   = "__iteritem"
	VarHTTPMethod = "__httpmethod"
)
View Source
var (
	CharsetUTF8        = Charset{"UTF-8"}
	CorsAnonymous      = Crossorigin{"anonymous"}
	CorsNone           = Crossorigin{""}
	CorsUseCredentials = Crossorigin{"use-credentials"}
	FormMethodGET      = FormMethod{"get"}
	FormMethodPOST     = FormMethod{"post"}
	MethodGET          = Method{"get"}
	MethodPOST         = Method{"post"}
	RelExternal        = Rel{"external"}
	RelHelp            = Rel{"help"}
	RelLicense         = Rel{"license"}
	RelNext            = Rel{"next"}
	RelNoFollow        = Rel{"nofollow"}
	RelNoOpener        = Rel{"noopener"}
	RelNoReferrer      = Rel{"noreferrer"}
	RelOpener          = Rel{"opener"}
	RelPrev            = Rel{"prev"}
	RelSearch          = Rel{"search"}
	RelStylesheet      = Rel{"stylesheet"}
	TargetBlank        = Target{"__blank"}
	TargetParent       = Target{"__parent"}
	TargetSelf         = Target{"__self"}
	TargetTop          = Target{"__top"}
	TypeButton         = Type{"button"}
	TypeCheckbox       = Type{"checkbox"}
	TypeColor          = Type{"color"}
	TypeDate           = Type{"date"}
	TypeDateTime       = Type{"datetime"}
	TypeDateTimeLocal  = Type{"datetime-local"}
	TypeEmail          = Type{"email"}
	TypeFile           = Type{"file"}
	TypeHidden         = Type{"hidden"}
	TypeImage          = Type{"image"}
	TypeJavascript     = Type{"text/javascript"}
	TypeMonth          = Type{"month"}
	TypeNumber         = Type{"number"}
	TypePassword       = Type{"password"}
	TypeRadio          = Type{"radio"}
	TypeRange          = Type{"range"}
	TypeReset          = Type{"reset"}
	TypeSearch         = Type{"search"}
	TypeSubmit         = Type{"submit"}
	TypeTel            = Type{"tel"}
	TypeText           = Type{"text"}
	TypeTime           = Type{"time"}
	TypeURL            = Type{"url"}
	TypeWeek           = Type{"week"}
)

Functions

func GetVar

func GetVar[T comparable](c Context, key string, defaultv ...T) T

Types

type A

type A []Component

func (A) Render

func (t A) Render(c Context) error

type Abbr

type Abbr []Component

type Acronym

type Acronym []Component

type Action

type Action []string

func (Action) AttrValueMerge

func (t Action) AttrValueMerge()

func (Action) Attribute

func (t Action) Attribute()

func (Action) Render

func (t Action) Render(c Context) error

type Address

type Address []Component

type App

type App []Component

func (App) Run

func (t App) Run() error

type AppContext

type AppContext struct {
	Routes map[*urlpath.Path]Route
}

func NewAppContext

func NewAppContext() *AppContext

func (*AppContext) AddRoute

func (t *AppContext) AddRoute(r Route)

func (*AppContext) ServeHTTP

func (t *AppContext) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Applet

type Applet []Component

type Area

type Area []Component

func (Area) SelfClosing

func (t Area) SelfClosing()

type Article

type Article []Component

type Aside

type Aside []Component

type Attr

type Attr []string

func (Attr) Attribute

func (t Attr) Attribute()

func (Attr) Render

func (t Attr) Render(c Context) error

type AttrIf

type AttrIf struct {
	Cond CondFunc
	Then Attribute
	Else Attribute
}

func (AttrIf) Attribute

func (t AttrIf) Attribute()

func (AttrIf) Render

func (t AttrIf) Render(c Context) error

type AttrValueMerge

type AttrValueMerge interface {
	Component
	AttrValueMerge()
}

type Attribute

type Attribute interface {
	Component
	Attribute()
}

type Audio

type Audio []Component

type B

type B []Component

func (B) Render

func (t B) Render(c Context) error

type Base

type Base []Component

func (Base) SelfClosing

func (t Base) SelfClosing()

type Basefont

type Basefont []Component

type Bdi

type Bdi []Component

type Bdo

type Bdo []Component

type Bgsound

type Bgsound []Component

type Big

type Big []Component
type Blink []Component

type Blockquote

type Blockquote []Component

type Body

type Body []Component

func (Body) Render

func (t Body) Render(c Context) error

type Br

type Br []Component

func (Br) SelfClosing

func (t Br) SelfClosing()

type Button

type Button []Component

func (Button) Render

func (t Button) Render(c Context) error

type CSSComponent

type CSSComponent interface {
	Component
	CSSComponent()
}

type CSSRule

type CSSRule struct {
	AlignItems      string
	BackgroundColor string
	Color           string
	Display         string
	JustifyContent  string
	Left            string
	Margin          string
	PlaceItems      string
	Position        string
	Top             string
	Transform       string
	Width           string
}

func (CSSRule) CSSComponent

func (t CSSRule) CSSComponent()

type CSSSelector

type CSSSelector map[string]CSSRule

func (CSSSelector) CSSComponent

func (t CSSSelector) CSSComponent()

func (CSSSelector) Render

func (t CSSSelector) Render(c Context) error

type Canvas

type Canvas []Component

type Caption

type Caption []Component

type Center

type Center []Component

type Charset

type Charset []string

func (Charset) Attribute

func (t Charset) Attribute()

func (Charset) Render

func (t Charset) Render(c Context) error

type Cite

type Cite []Component

type Class

type Class []string

func (Class) Attribute

func (t Class) Attribute()

func (Class) Render

func (t Class) Render(c Context) error

type Code

type Code []Component

type Col

type Col []Component

func (Col) SelfClosing

func (t Col) SelfClosing()

type Colgroup

type Colgroup []Component

type Command

type Command []Component

func (Command) SelfClosing

func (t Command) SelfClosing()

type Component

type Component interface {
	Render(Context) error
}

func ConvertSlice

func ConvertSlice[TIn Component](in []TIn) (out []Component)

type CondFunc

type CondFunc func(c Context) bool

type Context

type Context interface {
	io.Writer
	io.Reader
	Param(key string) string
	Redirect(url string) error
	Render(Component) error
	SetVar(key string, value any)
	Var(key string) any
	WriteHeader(string, string) error
	WriteStatus(int) error
	WriteString(string, ...any) error
}

type Crossorigin

type Crossorigin []string

func (Crossorigin) Attribute

func (t Crossorigin) Attribute()

func (Crossorigin) Render

func (t Crossorigin) Render(c Context) error

type CtxParam

type CtxParam []string

func (CtxParam) Render

func (t CtxParam) Render(c Context) error

type Data

type Data []Component

type Datalist

type Datalist []Component

type Dd

type Dd []Component

type Del

type Del []Component

type Details

type Details []Component

type Dfn

type Dfn []Component

type Dialog

type Dialog []Component

type Dir

type Dir []Component

type Div

type Div []Component

func (Div) Render

func (t Div) Render(c Context) error

type Dl

type Dl []Component

type Doctype

type Doctype []Component

type Dt

type Dt []Component

type Each

type Each[T any] struct {
	Items *[]T
	Thenf func(T) Component
}

func (Each[T]) Render

func (t Each[T]) Render(c Context) error

type Elems

type Elems []Component

func (Elems) Render

func (t Elems) Render(c Context) error

type Em

type Em []Component

type Embed

type Embed []Component

func (Embed) SelfClosing

func (t Embed) SelfClosing()

type Fieldset

type Fieldset []Component

type Figcaption

type Figcaption []Component

type Figure

type Figure []Component

type Font

type Font []Component
type Footer []Component

type Form

type Form []Component

func (Form) Render

func (t Form) Render(c Context) error

type FormAction

type FormAction []string

func (FormAction) AttrValueMerge

func (t FormAction) AttrValueMerge()

func (FormAction) Attribute

func (t FormAction) Attribute()

func (FormAction) Render

func (t FormAction) Render(c Context) error

type FormMethod

type FormMethod []string

func (FormMethod) Attribute

func (t FormMethod) Attribute()

func (FormMethod) Render

func (t FormMethod) Render(c Context) error

type FormatBlock

type FormatBlock interface {
	FormatBlock()
}

type Frame

type Frame []Component

type Frameset

type Frameset []Component

type H1

type H1 []Component

func (H1) Render

func (t H1) Render(c Context) error

type H2

type H2 []Component

func (H2) Render

func (t H2) Render(c Context) error

type H3

type H3 []Component

func (H3) Render

func (t H3) Render(c Context) error

type H4

type H4 []Component

func (H4) Render

func (t H4) Render(c Context) error

type H5

type H5 []Component

func (H5) Render

func (t H5) Render(c Context) error

type H6

type H6 []Component

func (H6) Render

func (t H6) Render(c Context) error

type HTML

type HTML []Component

func (HTML) Render

func (t HTML) Render(c Context) error

type HTMLFormatter

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

func NewHTMLFormatter

func NewHTMLFormatter(sink io.Writer) *HTMLFormatter

func (*HTMLFormatter) Format

func (t *HTMLFormatter) Format(data []byte) (n int, err error)

type HTTPContext

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

func NewHTTPContext

func NewHTTPContext() *HTTPContext

func (*HTTPContext) Param

func (t *HTTPContext) Param(key string) string

func (*HTTPContext) Read

func (t *HTTPContext) Read(buff []byte) (int, error)

func (*HTTPContext) Redirect

func (t *HTTPContext) Redirect(url string) error

func (*HTTPContext) Render

func (t *HTTPContext) Render(c Component) error

func (*HTTPContext) SetVar

func (t *HTTPContext) SetVar(key string, value any)

func (*HTTPContext) Var

func (t *HTTPContext) Var(key string) any

func (*HTTPContext) With

func (t *HTTPContext) With(f func(*HTTPContext)) *HTTPContext

func (*HTTPContext) Write

func (t *HTTPContext) Write(buff []byte) (int, error)

func (*HTTPContext) WriteHeader

func (t *HTTPContext) WriteHeader(key string, value string) error

func (*HTTPContext) WriteStatus

func (t *HTTPContext) WriteStatus(code int) error

func (*HTTPContext) WriteString

func (t *HTTPContext) WriteString(s string, args ...any) error
type Head []Component

func (Head) Render

func (t Head) Render(c Context) error
type Header []Component

type Hr

type Hr []Component

func (Hr) SelfClosing

func (t Hr) SelfClosing()

type Href

type Href []string

func (Href) AttrValueMerge

func (t Href) AttrValueMerge()

func (Href) Attribute

func (t Href) Attribute()

func (Href) Render

func (t Href) Render(c Context) error

type I

type I []Component

func (I) Render

func (t I) Render(c Context) error

type ID

type ID []string

func (ID) Attribute

func (t ID) Attribute()

func (ID) Render

func (t ID) Render(c Context) error

type If

type If struct {
	Cond CondFunc
	Then Component
	Else Component
}

func (If) Render

func (t If) Render(c Context) error

type Iframe

type Iframe []Component

type Img

type Img []Component

func (Img) SelfClosing

func (t Img) SelfClosing()

type Input

type Input []Component

func (Input) Render

func (t Input) Render(c Context) error

func (Input) SelfClosing

func (t Input) SelfClosing()

type Ins

type Ins []Component

type Integrity

type Integrity []string

func (Integrity) Attribute

func (t Integrity) Attribute()

func (Integrity) Render

func (t Integrity) Render(c Context) error

type Kbd

type Kbd []Component

type Keygen

type Keygen []Component

func (Keygen) SelfClosing

func (t Keygen) SelfClosing()

type Label

type Label []Component

func (Label) Render

func (t Label) Render(c Context) error

type Legend

type Legend []Component

type Li

type Li []Component

func (Li) Render

func (t Li) Render(c Context) error
type Link []Component

func (Link) FormatBlock

func (t Link) FormatBlock()

func (Link) Render

func (t Link) Render(c Context) error

func (Link) SelfClosing

func (t Link) SelfClosing()

type Main

type Main []Component

type Map

type Map []Component

type Mark

type Mark []Component

type Marquee

type Marquee []Component

type MemoryContext

type MemoryContext struct {
	Headers map[string]string
	Params  map[string]string
	Sink    bytes.Buffer
	Source  bytes.Buffer
	Status  int
	Vars    map[string]any
}

func NewMemoryContext

func NewMemoryContext() *MemoryContext

func (*MemoryContext) Param

func (t *MemoryContext) Param(key string) string

func (*MemoryContext) Read

func (t *MemoryContext) Read(buff []byte) (int, error)

func (*MemoryContext) Redirect

func (t *MemoryContext) Redirect(string) error

func (*MemoryContext) Render

func (t *MemoryContext) Render(c Component) error

func (*MemoryContext) SetVar

func (t *MemoryContext) SetVar(key string, value any)

func (*MemoryContext) Var

func (t *MemoryContext) Var(key string) any

func (*MemoryContext) Write

func (t *MemoryContext) Write(buff []byte) (int, error)

func (*MemoryContext) WriteHeader

func (t *MemoryContext) WriteHeader(key string, value string) error

func (*MemoryContext) WriteStatus

func (t *MemoryContext) WriteStatus(code int) error

func (*MemoryContext) WriteString

func (t *MemoryContext) WriteString(s string, args ...any) error
type Menu []Component
type Menuitem []Component

type Meta

type Meta []Component

func (Meta) FormatBlock

func (t Meta) FormatBlock()

func (Meta) Render

func (t Meta) Render(c Context) error

func (Meta) SelfClosing

func (t Meta) SelfClosing()

type Meter

type Meter []Component

type Method

type Method []string

func (Method) Attribute

func (t Method) Attribute()

func (Method) Render

func (t Method) Render(c Context) error

type Name

type Name []string

func (Name) Attribute

func (t Name) Attribute()

func (Name) Render

func (t Name) Render(c Context) error
type Nav []Component

type Noframes

type Noframes []Component

type NoopContext

type NoopContext struct{}

func NewNoopContext

func NewNoopContext() *NoopContext

func (*NoopContext) Param

func (t *NoopContext) Param(string) string

func (*NoopContext) Read

func (t *NoopContext) Read(buff []byte) (int, error)

func (*NoopContext) Redirect

func (t *NoopContext) Redirect(string) error

func (*NoopContext) Render

func (t *NoopContext) Render(c Component) error

func (*NoopContext) SetVar

func (t *NoopContext) SetVar(key string, value any)

func (*NoopContext) Var

func (t *NoopContext) Var(key string) any

func (*NoopContext) Write

func (t *NoopContext) Write(buff []byte) (int, error)

func (*NoopContext) WriteHeader

func (t *NoopContext) WriteHeader(key string, value string) error

func (*NoopContext) WriteStatus

func (t *NoopContext) WriteStatus(code int) error

func (*NoopContext) WriteString

func (t *NoopContext) WriteString(s string, args ...any) error

type Noscript

type Noscript []Component

type Object

type Object []Component

type Ol

type Ol []Component

type Optgroup

type Optgroup []Component

type Option

type Option []Component

type Output

type Output []Component

type P

type P []Component

type Param

type Param []Component

func (Param) SelfClosing

func (t Param) SelfClosing()

type PhrasingContent

type PhrasingContent interface {
	Component
	PhrasingContent()
}

type Picture

type Picture []Component

type Placeholder

type Placeholder []string

func (Placeholder) Attribute

func (t Placeholder) Attribute()

func (Placeholder) Render

func (t Placeholder) Render(c Context) error

type Pre

type Pre []Component

type Progress

type Progress []Component

type Q

type Q []Component

type RawHTML

type RawHTML []string

func (RawHTML) Render

func (t RawHTML) Render(c Context) error

type Rel

type Rel []string

func (Rel) Attribute

func (t Rel) Attribute()

func (Rel) Render

func (t Rel) Render(c Context) error

type RenderFunc

type RenderFunc []func(c Context) error

func (RenderFunc) Render

func (t RenderFunc) Render(c Context) error

type Route

type Route struct {
	Path   string
	Handle Component
}

func (Route) Render

func (t Route) Render(c Context) error

type Rp

type Rp []Component

type Rt

type Rt []Component

type Ruby

type Ruby []Component

type S

type S []Component

func (S) Render

func (t S) Render(c Context) error

type Samp

type Samp []Component

type Script

type Script []Component

func (Script) Render

func (t Script) Render(c Context) error

type Section

type Section []Component

func (Section) Render

func (t Section) Render(c Context) error

type Select

type Select []Component

type SelfClosing

type SelfClosing interface {
	Component
	SelfClosing()
}

type Small

type Small []Component

type Source

type Source []Component

func (Source) SelfClosing

func (t Source) SelfClosing()

type Span

type Span []Component

type Src

type Src []string

func (Src) Attribute

func (t Src) Attribute()

func (Src) Render

func (t Src) Render(c Context) error

type Strike

type Strike []Component

type Strong

type Strong []Component

type Style

type Style []CSSComponent

func (Style) Render

func (t Style) Render(c Context) error

type StyleAttr

type StyleAttr []string

func (StyleAttr) Attribute

func (t StyleAttr) Attribute()

func (StyleAttr) Render

func (t StyleAttr) Render(c Context) error

type Sub

type Sub []Component

type Summary

type Summary []Component

type Sup

type Sup []Component

type Svg

type Svg []Component

type Table

type Table []Component

type Target

type Target []string

func (Target) Attribute

func (t Target) Attribute()

func (Target) Render

func (t Target) Render(c Context) error

type Tbody

type Tbody []Component

type Td

type Td []Component

type Template

type Template []Component

type Text

type Text []string

func (Text) CSSComponent

func (t Text) CSSComponent()

func (Text) Render

func (t Text) Render(c Context) error

type Textarea

type Textarea []Component

func (Textarea) Render

func (t Textarea) Render(c Context) error

type Tfoot

type Tfoot []Component

type Th

type Th []Component

type Thead

type Thead []Component

type Time

type Time []Component

type Title

type Title []Component

type Tr

type Tr []Component

type Track

type Track []Component

func (Track) SelfClosing

func (t Track) SelfClosing()

type Tt

type Tt []Component

type Type

type Type []string

func (Type) Attribute

func (t Type) Attribute()

func (Type) Render

func (t Type) Render(c Context) error

type U

type U []Component

type Ul

type Ul []Component

func (Ul) Render

func (t Ul) Render(c Context) error

type Value

type Value []string

func (Value) AttrValueMerge

func (t Value) AttrValueMerge()

func (Value) Attribute

func (t Value) Attribute()

func (Value) Render

func (t Value) Render(c Context) error

type Var

type Var []Component

type Video

type Video []Component

type Wbr

type Wbr []Component

func (Wbr) SelfClosing

func (t Wbr) SelfClosing()

Directories

Path Synopsis
examples
hello-world Module

Jump to

Keyboard shortcuts

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