lates

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

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 11 Imported by: 0

README

Lates

[riːt]

lates is a simple tool for templ.

install

install github.com/a-h/templ

first, visit templ, and install templ.

go install github.com/a-h/templ/cmd/templ@latest

and, install visual studio extension templ from the marketplace.

https://marketplace.visualstudio.com/items?itemName=a-h.templ

go get github.com/snowmerak/lates
go get github.com/snowmerak/lates

usage

how to use templ

read the readme.md of templ.

link

lates example
// templates/index/helloworld.templ
package index

templ HelloWorld() {
    <h1>Hello, world!</h1>
}
// templates/index/param.templ
package index

templ Param(param string) {
    <h1>{param}</h1>
}

run templ generate.

// main.go
package main

import (
	"example/templates/index"

	"github.com/a-h/templ"
	"github.com/snowmerak/lates"
)

func main() {
	late := lates.New()

	late.Get("/", func(c *lates.Context) templ.Component {
		return index.HelloWorld()
	})

	late.Get("/:param", func(c *lates.Context) templ.Component {
		return index.Param(c.GetPathVariable("param"))
	})

	if err := late.ListenAndServe(":8080"); err != nil {
		panic(err)
	}
}

simple signup page
package main

import (
	"fmt"

	"github.com/a-h/templ"
	"github.com/snowmerak/lates"
	"github.com/snowmerak/lates/made"
)

func main() {
	l := lates.New()

	l.ApplySakuraDark()

	l.Get("/signup", func(c *lates.Context) templ.Component {
		return made.Form("form", "/", "post",
			made.Label("input your name", "name"),
			made.Input("name", "input your name", "text"),
			made.Break(),
			made.Label("input your email", "email"),
			made.Input("email", "input your email", "text"),
			made.Break(),
			made.Label("input your password", "password"),
			made.Input("password", "input your password", "text"),
			made.Break(),
			made.Input("submnit", "submit", "submit"),
			made.Space(),
			made.Input("reset", "reset", "reset"),
		)
	})

	l.Post("/signup", func(c *lates.Context) templ.Component {
		name := c.GetFormData("name")
		email := c.GetFormData("email")
		password := c.GetFormData("password")
		return made.Paragraph(fmt.Sprintf("name: %s, email: %s, password: %s\n", name, email, password))
	})

	if err := l.ListenAndServe(":8080"); err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

View Source
const SakuraDarkCSS = `` /* 4209-byte string literal not displayed */

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

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

func (*Context) GetBody

func (c *Context) GetBody() ([]byte, error)

func (*Context) GetBodyReader

func (c *Context) GetBodyReader() io.ReadCloser

func (*Context) GetCookie

func (c *Context) GetCookie(key string) string

func (*Context) GetFormData

func (c *Context) GetFormData(key string) string

func (*Context) GetFormFile

func (c *Context) GetFormFile(key string) (multipart.File, *multipart.FileHeader, error)

func (*Context) GetMultipartFile

func (c *Context) GetMultipartFile(name string, maxMemoryBytes int64) ([]*multipart.FileHeader, error)

func (*Context) GetPathVariable

func (c *Context) GetPathVariable(key string) string

func (*Context) GetRemoteAddress

func (c *Context) GetRemoteAddress() string

func (*Context) GetRemoteIpPort

func (c *Context) GetRemoteIpPort() (string, string, error)

func (*Context) GetURLQuery

func (c *Context) GetURLQuery(key string) string

func (*Context) Redirect

func (c *Context) Redirect(url string, statusCode int)

func (*Context) SaveFile

func (c *Context) SaveFile(name, path string) error

func (*Context) SaveMultipartFile

func (c *Context) SaveMultipartFile(name string, maxMemoryBytes int64, path string) error

func (*Context) SetStatusCode

func (c *Context) SetStatusCode(statusCode int)

type Lates

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

func New

func New() *Lates

func (*Lates) AddCssPath

func (l *Lates) AddCssPath(pathes ...string)

func (*Lates) AddRouter

func (l *Lates) AddRouter(method string, path string, handler func(c *Context) templ.Component) error

func (*Lates) ApplySakuraDark

func (l *Lates) ApplySakuraDark()

func (*Lates) Delete

func (l *Lates) Delete(path string, handler func(c *Context) templ.Component)

func (*Lates) Get

func (l *Lates) Get(path string, handler func(c *Context) templ.Component)

func (*Lates) ListenAndServe

func (l *Lates) ListenAndServe(addr string) error

func (*Lates) ListenAndServe2

func (l *Lates) ListenAndServe2(addr string) error

func (*Lates) Patch

func (l *Lates) Patch(path string, handler func(c *Context) templ.Component)

func (*Lates) Post

func (l *Lates) Post(path string, handler func(c *Context) templ.Component)

func (*Lates) Put

func (l *Lates) Put(path string, handler func(c *Context) templ.Component)

func (*Lates) SetHttpServer

func (l *Lates) SetHttpServer(server *http.Server)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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