lau

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2021 License: MIT Imports: 6 Imported by: 0

README

Lau Web Framework

A Simple Golang Web Framework

Installation

To install package

$ go get -u gitee.com/lauj/lau

Import it in your code:

import "gitee.com/lauj/lau"

Quick start

package main

import "gitee.com/lauj/lau"

func main() {
    l := lau.Default()
    l.Static("/static", "static")
    l.LoadHTMLGlob("views/*")
    l.GET("/hello/:one/:two/info", func(c *lau.Context) {
        c.HTML(200, "two.tmpl", nil)
    })
    l.GET("/hello", func(c *lau.Context) {
        c.String(200, "%v", "hello")
    })
    l.GET("/demo/*aaa", func(c *lau.Context) {
        c.JSON(200, lau.H{
            "info": "info",
        })
        fmt.Println(c.Params)
    })
    l.Use(func(c *lau.Context) {
        c.String(200, "%v\n", "middleware")
    })
    l.Run(":8000")
}

Documentation

Overview

Copyright (c) 2020 Lau All rights reserved. Use of this source code is governed by MIT License that can be found in the LICENSE file. Author: Lau <lauj@foxmail.com>

Copyright (c) 2020 Lau All rights reserved. Use of this source code is governed by MIT License that can be found in the LICENSE file. Author: Lau <lauj@foxmail.com>

Copyright (c) 2020 Lau All rights reserved. Use of this source code is governed by MIT License that can be found in the LICENSE file. Author: Lau <lauj@foxmail.com>

Copyright (c) 2020 Lau All rights reserved. Use of this source code is governed by MIT License that can be found in the LICENSE file. Author: Lau <lauj@foxmail.com>

Index

Constants

View Source
const (
	NODEDEFAULT  uint8 = iota // normal string
	NODEPARAM                 // bind param
	NODEWILDCARD              // wildcard
)

node type

Variables

This section is empty.

Functions

func Recovery

func Recovery() handleFunc

Types

type Context

type Context struct {
	W      http.ResponseWriter
	R      *http.Request
	Method string
	Path   string
	Code   int
	*Engine
	Params map[string]string
	// contains filtered or unexported fields
}

func NewContext

func NewContext(w http.ResponseWriter, r *http.Request) *Context

func (*Context) Error

func (c *Context) Error(code int, err interface{})

func (*Context) FormValue

func (c *Context) FormValue(k string) string

func (*Context) Get

func (c *Context) Get(k string) interface{}

func (*Context) HTML

func (c *Context) HTML(code int, filename string, obj interface{})

func (*Context) JSON

func (c *Context) JSON(code int, obj interface{})

func (*Context) Next

func (c *Context) Next()

func (*Context) Param

func (c *Context) Param(k string) string

get bind parameters by dynamic route

func (*Context) PostFormValue

func (c *Context) PostFormValue(k string) string

func (*Context) Set

func (c *Context) Set(k string, v interface{})

func (*Context) SetHeader

func (c *Context) SetHeader(k, v string)

func (*Context) SetStatus

func (c *Context) SetStatus(code int)

func (*Context) String

func (c *Context) String(code int, format string, val string)

type Engine

type Engine struct {
	*Route
	HTMLTemplate *template.Template
}

func Default

func Default() *Engine

func New

func New() *Engine

New returns a new initialized Engine

func (*Engine) LoadHTMLFiles

func (e *Engine) LoadHTMLFiles(filenames ...string)

ParseFiles from the named files

func (*Engine) LoadHTMLGlob

func (e *Engine) LoadHTMLGlob(pattern string)

ParseFiles with the list of files matched by the pattern

func (*Engine) Run

func (e *Engine) Run(addr string)

func (*Engine) ServeHTTP

func (e *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)

type H

type H map[string]interface{}

type Route

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

func NewRoute

func NewRoute() *Route

func (*Route) GET

func (r *Route) GET(path string, handler handleFunc)

func (*Route) POST

func (r *Route) POST(path string, handler handleFunc)

func (*Route) Static

func (r *Route) Static(prefix, root string)

FileServer returns a handler that serves HTTP requests with the contents of the file system rooted at root.

func (*Route) Use

func (r *Route) Use(f handleFunc)

middleware

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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