gweb

package module
v0.0.0-...-8a4771f Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2021 License: MIT Imports: 19 Imported by: 3

Documentation

Index

Constants

View Source
const (
	GET  = "GET"
	POST = "POST"
	PUT  = "PUT"
	DEL  = "DELETE"
)

Variables

This section is empty.

Functions

func GetFuncArgs

func GetFuncArgs(t reflect.Type) []reflect.Type

Types

type App

type App struct {
	Root INode
	di.Container
	Name string
	*Cfg
	ServHttp  *http.Server
	ServHttps *http.Server
	*Router
	*Tmpl
	Sessions ISessions
	*Log
	ValidAuth      func(*Ctx) (httpStatus int, stauts IStatus, uid GUID)
	NotFoundHandle func(*Ctx)
}

func NewApp

func NewApp(name string) *App

func NewAppWithCfg

func NewAppWithCfg(c *Cfg) *App

func (*App) NewCtx

func (p *App) NewCtx(r *http.Request, rw http.ResponseWriter) *Ctx

func (*App) Start

func (p *App) Start()

type Cfg

type Cfg struct {
	Http       bool
	HttpPort   int
	Https      bool
	HttpsPort  int
	CertFile   string
	KeyFile    string
	ServeFiles []string
	UseTmpl    bool
}

type Ctx

type Ctx struct {
	*App
	di.Container
	*Req
	*Resp
	Scope M

	Handled bool
	// contains filtered or unexported fields
}

func (Ctx) CurPart

func (p Ctx) CurPart() *urlPart

func (*Ctx) Error

func (p *Ctx) Error(code int) *Ctx

func (*Ctx) ErrorJson

func (p *Ctx) ErrorJson(code int, m T) *Ctx

func (*Ctx) Forbidden

func (p *Ctx) Forbidden()

func (*Ctx) Get

func (p *Ctx) Get(k string) string

func (*Ctx) GetId

func (p *Ctx) GetId() GUID

func (*Ctx) HandleStatusJson

func (p *Ctx) HandleStatusJson(s IStatus)

func (Ctx) IsAuth

func (p Ctx) IsAuth() bool

func (*Ctx) IsDEL

func (p *Ctx) IsDEL() bool

func (*Ctx) IsErr

func (p *Ctx) IsErr() bool

func (*Ctx) IsGET

func (p *Ctx) IsGET() bool

func (*Ctx) IsPOST

func (p *Ctx) IsPOST() bool

func (*Ctx) IsPUT

func (p *Ctx) IsPUT() bool

func (*Ctx) Json

func (p *Ctx) Json(m T) *Ctx

func (Ctx) NextPart

func (p Ctx) NextPart() *urlPart

func (*Ctx) NotFound

func (p *Ctx) NotFound()

func (*Ctx) OK

func (p *Ctx) OK()

func (*Ctx) Redirect

func (p *Ctx) Redirect(url string)

func (*Ctx) ReqIp

func (p *Ctx) ReqIp() string

func (*Ctx) ServeFile

func (p *Ctx) ServeFile() bool

func (*Ctx) Set

func (p *Ctx) Set(k string, v T)

func (*Ctx) SetCookie

func (p *Ctx) SetCookie(c http.Cookie)

func (*Ctx) SetHandled

func (p *Ctx) SetHandled()

func (*Ctx) SetUid

func (p *Ctx) SetUid(uid GUID)

func (*Ctx) Text

func (p *Ctx) Text(str string)

func (*Ctx) Tmpl

func (p *Ctx) Tmpl(tpl string, o T)

func (*Ctx) Tmpl2

func (p *Ctx) Tmpl2(tpl string, o T)

func (*Ctx) Uid

func (p *Ctx) Uid() GUID

type HandleNode

type HandleNode struct {
	*Node
	// contains filtered or unexported fields
}

func NewHandleNode

func NewHandleNode(path string, handle func(*Ctx), auth bool) *HandleNode

func (*HandleNode) Handle

func (p *HandleNode) Handle(c *Ctx)

type Handler

type Handler func(c *Ctx)

type INode

type INode interface {
	AddNode(n INode) INode
	NewParamNode(path string, auth bool) INode
	NewRegexNode(path, regex string, auth bool) INode
	NewSubNode(path string, auth bool) INode
	NewHandleNode(path string, handle func(*Ctx), auth bool) INode
	CanRoute(test string, c *Ctx) bool
	Handle(c *Ctx)
	CheckHttpMethod(n INode)
	RunInterceptors(c *Ctx) INode
	GetNodes() []INode
	NeedAuth() bool
	Actions() map[string]NodeAction
}

type ISessions

type ISessions interface {
	HasSess(sid string) bool
	DelSess(sid string) error
	GetSessUid(sid string) (string, error)
}

type Interceptor

type Interceptor struct {
	Before Handler
	After  Handler
}

type Log

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

func NewLog

func NewLog(path string) *Log

func (*Log) Log

func (p *Log) Log(r *Req)

type Node

type Node struct {
	Path         string
	Interceptors []*Interceptor
	Nodes        []INode
	// contains filtered or unexported fields
}

func NewNode

func NewNode(path string, auth bool) (pn *Node)

func (*Node) Actions

func (p *Node) Actions() map[string]NodeAction

func (*Node) AddNode

func (p *Node) AddNode(n INode) INode

func (*Node) CanRoute

func (p *Node) CanRoute(test string, c *Ctx) bool

func (*Node) CheckHttpMethod

func (p *Node) CheckHttpMethod(n INode)

func (*Node) GetNodes

func (p *Node) GetNodes() []INode

func (*Node) Handle

func (p *Node) Handle(c *Ctx)

func (*Node) Interceptor

func (p *Node) Interceptor(m *Interceptor) *Node

func (*Node) NeedAuth

func (p *Node) NeedAuth() bool

func (*Node) NewHandleNode

func (p *Node) NewHandleNode(path string, handle func(*Ctx), auth bool) INode

func (*Node) NewParamNode

func (p *Node) NewParamNode(path string, auth bool) INode

func (*Node) NewRegexNode

func (p *Node) NewRegexNode(path, regex string, auth bool) INode

func (*Node) NewSubNode

func (p *Node) NewSubNode(path string, auth bool) INode

func (*Node) RunInterceptors

func (p *Node) RunInterceptors(c *Ctx) INode

type NodeAction

type NodeAction struct {
	Name string
	Type reflect.Type
}

type ParamNode

type ParamNode struct {
	*Node
}

func NewParamNode

func NewParamNode(path string, auth bool) *ParamNode

func (*ParamNode) CanRoute

func (p *ParamNode) CanRoute(test string, c *Ctx) bool

type RegexNode

type RegexNode struct {
	*Node
	// contains filtered or unexported fields
}

func NewRegexNode

func NewRegexNode(path, regex string, auth bool) *RegexNode

func (*RegexNode) CanRoute

func (p *RegexNode) CanRoute(test string, c *Ctx) bool

type Req

type Req struct {
	*http.Request

	Token string
	// contains filtered or unexported fields
}

func NewReq

func NewReq(r *http.Request) *Req

func (Req) CurPart

func (p Req) CurPart() *urlPart

func (*Req) HasToken

func (p *Req) HasToken() bool

func (*Req) IsAcceptJson

func (p *Req) IsAcceptJson() bool

func (*Req) IsJList

func (p *Req) IsJList() bool

func (*Req) IsJPage

func (p *Req) IsJPage() bool

func (*Req) IsJsonContent

func (p *Req) IsJsonContent() bool

func (*Req) JMethod

func (p *Req) JMethod() string

func (*Req) JPage

func (p *Req) JPage() *filter.PageFilter

func (*Req) JsonBody

func (p *Req) JsonBody(m T) bool

func (Req) NextPart

func (p Req) NextPart() *urlPart

func (*Req) Url

func (p *Req) Url() string

type Resp

type Resp struct {
	http.ResponseWriter
}

type Router

type Router struct {
}

func (*Router) Route

func (p *Router) Route(n INode, c *Ctx)

func (*Router) RouteSubNodes

func (p *Router) RouteSubNodes(n INode, c *Ctx)

type Tmpl

type Tmpl struct {
	Templates *template.Template
}

func (*Tmpl) Execute

func (p *Tmpl) Execute(wr io.Writer, name string, data interface{}) error

func (*Tmpl) Execute2

func (p *Tmpl) Execute2(wr io.Writer, name string, data interface{}) error

func (*Tmpl) Load

func (p *Tmpl) Load()

Jump to

Keyboard shortcuts

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