miniweb

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 1, 2020 License: MIT Imports: 7 Imported by: 0

README

Golang Toolbox - Miniweb

Miniweb is a simple and small function for writing web application. It is not recommended to use it for large software projects. It is more designed to be a fast prototyping library.

It uses the golang http/template templating engine and the http server from the http package.

You simply define handlers, which contains:

  • The url, on which the handler will be called
  • A template, which should be loaded (optional)
  • A layout file, which should be loaded (optional)
  • A function, which is called (default is SendTemplate with nil)

Small example

This is a small example. You can find more examples in the example directory.

var indexHandler = miniweb.Handler{
	Url:     "/",
	TemplateFile: "index.gohtml",
	LayoutFile:   "layout.gohtml",
	Func: func(c *miniweb.Context) {
		c.SendTemplate("Hello World")
	},
}

func main() {
	miniweb.Register(indexHandler)
	log.Fatal(miniweb.Run(":8080"))
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TemplatePath    = "./templates"
	AdditionalFuncs template.FuncMap
	Dev             = false
)

Functions

func Proxy

func Proxy(basePath string, redirectUrl string)

func Register

func Register(handler Handler)

func Run

func Run(addr string) error

func StaticContent

func StaticContent(url, dirname string)

Types

type Context

type Context struct {
	Writer      http.ResponseWriter
	Request     *http.Request
	Template    *template.Template
	ContextData map[string]interface{}
}

func (*Context) ReadBytes added in v0.0.2

func (c *Context) ReadBytes() []byte

func (*Context) ReadForm added in v0.0.2

func (c *Context) ReadForm(data interface{})

func (*Context) ReadJson added in v0.0.2

func (c *Context) ReadJson(data interface{})

func (*Context) ReadString added in v0.0.2

func (c *Context) ReadString() string

func (*Context) SendJson

func (c *Context) SendJson(data interface{})

func (*Context) SendString

func (c *Context) SendString(data string)

func (*Context) SendTemplate

func (c *Context) SendTemplate(data interface{})

type Handler

type Handler struct {
	Url          string
	Func         HandlerFunc
	TemplateFile string
	LayoutFile   string
}

type HandlerFunc

type HandlerFunc func(c *Context)

type HandlerFuncSet

type HandlerFuncSet []HandlerFunc
var (
	PreHandlerFuncs  HandlerFuncSet
	PostHandlerFuncs HandlerFuncSet
)

func (*HandlerFuncSet) Add

func (h *HandlerFuncSet) Add(handler HandlerFunc)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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