webx

package module
v0.0.0-...-800783e Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2016 License: Apache-2.0 Imports: 26 Imported by: 5

README

webx

webx framework based on echo micro-framework

Documentation

Overview

Copyright 2016 Wenhui Shen <www.webx.top>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2016 Wenhui Shen <www.webx.top>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2016 Wenhui Shen <www.webx.top>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2016 Wenhui Shen <www.webx.top>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2016 Wenhui Shen <www.webx.top>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2016 Wenhui Shen <www.webx.top>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2016 Wenhui Shen <www.webx.top>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2016 Wenhui Shen <www.webx.top>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	NO_PERM = -2 //无权限
	NO_AUTH = -1 //未登录
	FAILURE = 0  //操作失败
	SUCCESS = 1  //操作成功
)
View Source
const VERSION = `1.0.0`

Variables

This section is empty.

Functions

func MustBool

func MustBool(c echo.Context, k string) (r bool)

func MustFloat32

func MustFloat32(c echo.Context, k string) (r float32)

func MustFloat64

func MustFloat64(c echo.Context, k string) (r float64)

func MustInt

func MustInt(c echo.Context, k string) (r int)

func MustInt32

func MustInt32(c echo.Context, k string) (r int32)

func MustInt64

func MustInt64(c echo.Context, k string) (r int64)

func MustString

func MustString(c echo.Context, k string) (r string)

func MustUint

func MustUint(c echo.Context, k string) (r uint)

func MustUint32

func MustUint32(c echo.Context, k string) (r uint32)

func MustUint64

func MustUint64(c echo.Context, k string) (r uint64)

func MustUint8

func MustUint8(c echo.Context, k string) (r uint8)

Types

type After

type After interface {
	After() error
}

动态实例中的后置行为

type AfterHandler

type AfterHandler interface {
	After(*Context) error
}

静态实例中的后置行为

type App

type App struct {
	*Server
	*echo.Group            //没有指定域名时有效
	Handler     *echo.Echo //指定域名时有效
	Renderer    echo.Renderer
	Name        string
	Domain      string

	Url string
	Dir string
	// contains filtered or unexported fields
}

func NewApp

func NewApp(name string, domain string, s *Server, middlewares ...echo.Middleware) (a *App)

func (*App) Ctl

func (a *App) Ctl(name string) (c interface{})

获取控制器

func (*App) E

func (a *App) E() *echo.Echo

func (*App) G

func (a *App) G() *echo.Group

func (*App) R

func (a *App) R(path string, h HandlerFunc, methods ...string) *App

注册路由:app.R(`/index`,Index.Index,"GET","POST")

func (*App) Reg

func (a *App) Reg(c interface{}) *Wrapper

登记控制器

func (*App) Webx

func (a *App) Webx() Webxer

type Before

type Before interface {
	Before() error
}

动态实例中的前置行为

type BeforeHandler

type BeforeHandler interface {
	Before(*Context) error
}

静态实例中的前置行为

type Context

type Context struct {
	echo.Context
	*Server
	*App
	*Output

	C              interface{}
	ControllerName string
	ActionName     string
	Language       string
	Code           int
	Tmpl           string
	Format         string
	Exit           bool
	// contains filtered or unexported fields
}

func NewContext

func NewContext(s *Server, c echo.Context) *Context

func X

func X(c echo.Context) *Context

func (*Context) AppUrl

func (c *Context) AppUrl(app string, ctl string, act string, args ...interface{}) string

func (*Context) AppUrlFor

func (c *Context) AppUrlFor(path string, args ...map[string]interface{}) string

func (*Context) Assign

func (c *Context) Assign(key string, val interface{}) *Context

func (*Context) AssignX

func (c *Context) AssignX(values *map[string]interface{}) *Context

func (*Context) Body

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

func (*Context) Cookie

func (c *Context) Cookie(key string, value string) *cookie.Cookie

func (*Context) Display

func (c *Context) Display(args ...interface{}) error

func (*Context) DisplayError

func (c *Context) DisplayError(msg string, args ...int) error

func (*Context) Domain

func (c *Context) Domain() string

Domain returns host name. Alias of Host method.

func (*Context) Errno

func (c *Context) Errno(code int, args ...string) *echo.HTTPError

func (*Context) Flash

func (c *Context) Flash(name string) (r interface{})

func (*Context) Form

func (c *Context) Form(name string) string

Form returns form parameter by name.

func (*Context) GetCookie

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

func (*Context) GetSecCookie

func (c *Context) GetSecCookie(key string) (value string)

func (*Context) Header

func (c *Context) Header(name string) string

func (*Context) Host

func (c *Context) Host() string

Host returns host name. if no host info in request, return localhost.

func (*Context) IP

func (c *Context) IP() string

func (*Context) Init

func (c *Context) Init(app *App, ctl interface{}, ctlName string, actName string) error

func (*Context) InitSession

func (c *Context) InitSession(sess ssi.Session)

func (*Context) IsAjax

func (c *Context) IsAjax() bool

func (*Context) IsDel

func (c *Context) IsDel() bool

DELETE:从服务器删除资源

func (*Context) IsGet

func (c *Context) IsGet() bool

SELECT:从服务器取出资源(一项或多项)

func (*Context) IsHead

func (c *Context) IsHead() bool

获取资源的元数据

func (*Context) IsOptions

func (c *Context) IsOptions() bool

获取信息,关于资源的哪些属性是客户端可以改变的

func (*Context) IsPatch

func (c *Context) IsPatch() bool

UPDATE:在服务器更新资源(客户端提供改变的属性)

func (*Context) IsPjax

func (c *Context) IsPjax() bool

func (*Context) IsPost

func (c *Context) IsPost() bool

CREATE:在服务器新建一个资源

func (*Context) IsPut

func (c *Context) IsPut() bool

UPDATE:在服务器更新资源(客户端提供改变后的完整资源)

func (*Context) IsSecure

func (c *Context) IsSecure() bool

func (*Context) IsUpload

func (c *Context) IsUpload() bool

IsUpload returns boolean of whether file uploads in this request or not..

func (*Context) IsWebsocket

func (c *Context) IsWebsocket() bool

IsWebsocket returns boolean of this request is in webSocket.

func (*Context) MapForm

func (c *Context) MapForm(i interface{}, names ...string) error

ParseStruct mapping forms' name and values to struct's field For example:

<form>
	<input name="user.id"/>
	<input name="user.name"/>
	<input name="user.age"/>
</form>

type User struct {
	Id int64
	Name string
	Age string
}

var user User
err := c.MapForm(&user,"user")

func (*Context) Method

func (c *Context) Method() string

func (*Context) OnlyAjax

func (c *Context) OnlyAjax() bool

func (*Context) PjaxContainer

func (c *Context) PjaxContainer() string

func (*Context) Port

func (c *Context) Port() int

Port returns request client port. when error or empty, return 80.

func (*Context) Protocol

func (c *Context) Protocol() string

Protocol returns request protocol name, such as HTTP/1.1 .

func (*Context) Proxy

func (c *Context) Proxy() []string

Proxy returns proxy client ips slice.

func (*Context) Refer

func (c *Context) Refer() string

Refer returns http referer header.

func (*Context) Referer

func (c *Context) Referer() string

Referer returns http referer header.

func (*Context) Reset

func (c *Context) Reset(req engine.Request, resp engine.Response)

func (*Context) ResolveContentType

func (c *Context) ResolveContentType() string

Get the content type. e.g. From "multipart/form-data; boundary=--" to "multipart/form-data" If none is specified, returns "text/html" by default.

func (*Context) ResolveFormat

func (c *Context) ResolveFormat() string

ResolveFormat maps the request's Accept MIME type declaration to a Request.Format attribute, specifically "html", "xml", "json", or "txt", returning a default of "html" when Accept header cannot be mapped to a value above.

func (*Context) Scheme

func (c *Context) Scheme() string

Scheme returns request scheme as "http" or "https".

func (*Context) SecCookie

func (c *Context) SecCookie(key string, value interface{})

func (*Context) Session

func (c *Context) Session() ssi.Session

func (*Context) SetCookie

func (c *Context) SetCookie(key, val string, args ...interface{})

func (*Context) SetErr

func (c *Context) SetErr(args ...interface{}) *Context

func (*Context) SetNoAuth

func (c *Context) SetNoAuth(args ...interface{}) *Context

func (*Context) SetNoPerm

func (c *Context) SetNoPerm(args ...interface{}) *Context

func (*Context) SetOutput

func (c *Context) SetOutput(code int, args ...interface{}) *Context

func (*Context) SetSecCookie

func (c *Context) SetSecCookie(key string, value interface{})

func (*Context) SetSuc

func (c *Context) SetSuc(args ...interface{}) *Context

func (*Context) Site

func (c *Context) Site() string

Site returns base site url as scheme://domain type.

func (*Context) SubDomains

func (c *Context) SubDomains() string

SubDomains returns sub domain string. if aa.bb.domain.com, returns aa.bb .

func (*Context) TmplPath

func (c *Context) TmplPath(args ...string) string

args: ActionName,ControllerName,AppName

func (*Context) Url

func (c *Context) Url(ctl string, act string, args ...interface{}) string

func (*Context) UrlFor

func (c *Context) UrlFor(path string, args ...map[string]interface{}) string

func (*Context) Use

func (c *Context) Use(i ...func(IniterFunc) IniterFunc)

type Controller

type Controller struct {
	*Context
}

func NewController

func NewController(c *Context) *Controller

func (*Controller) Init

func (a *Controller) Init(c *Context) error

func (*Controller) NotFound

func (a *Controller) NotFound(args ...string) error

func (*Controller) Redirect

func (a *Controller) Redirect(url string, args ...interface{}) error

func (*Controller) X

func (a *Controller) X(c echo.Context) *Context

type HandlerFunc

type HandlerFunc func(*Context) error

type Initer

type Initer interface {
	Init(*Context) error
}

动态实例中的初始化行为

type IniterFunc

type IniterFunc func(interface{}) error

type Mapper

type Mapper struct{}

结构体中定义路由的字段类型

type Output

type Output struct {
	Status  int
	Message interface{}
	Data    interface{}
}

type Server

type Server struct {
	Core *echo.Echo
	Name string
	Apps map[string]*App //域名关联

	DefaultMiddlewares []echo.Middleware
	TemplateEngine     tplex.TemplateEx
	TemplateDir        string
	MaxUploadSize      int64
	CookiePrefix       string
	CookieHttpOnly     bool
	CookieAuthKey      string
	CookieBlockKey     string
	CookieExpires      int64
	CookieDomain       string
	SessionStoreEngine string
	SessionStoreConfig interface{}
	codec.Codec
	Url string
	*URL
	InitContext func(*echo.Echo) interface{}
	// contains filtered or unexported fields
}

func NewServer

func NewServer(name string, middlewares ...echo.Middleware) (s *Server)

func Serv

func Serv(args ...string) *Server

func (*Server) App

func (s *Server) App(args ...string) (a *App)

已创建app实例

func (*Server) Debug

func (s *Server) Debug(on bool) *Server

开关debug模式

func (*Server) FuncMap

func (s *Server) FuncMap() (f map[string]interface{})

可用全局模板函数

func (*Server) InitCodec

func (s *Server) InitCodec(hashKey []byte, blockKey []byte)

初始化 加密/解密 接口

func (*Server) InitTmpl

func (s *Server) InitTmpl(args ...interface{}) (tmplEng tplex.TemplateEx)

初始化模板引擎

func (*Server) NewApp

func (s *Server) NewApp(name string, middlewares ...echo.Middleware) *App

创建新app

func (*Server) Pprof

func (s *Server) Pprof() *Server

启用pprof

func (*Server) ResetTmpl

func (s *Server) ResetTmpl(args ...interface{}) *Server

重置模板引擎

func (*Server) Run

func (s *Server) Run(args ...interface{})

运行服务

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(r engine.Request, w engine.Response)

HTTP服务执行入口

func (*Server) Static

func (s *Server) Static(absPath string, urlPath string, f ...*map[string]interface{}) *tplfunc.Static

静态资源文件管理器

type Servers

type Servers map[string]*Server

func (Servers) Get

func (s Servers) Get(name string) (sv *Server)

func (Servers) Set

func (s Servers) Set(name string, sv *Server)

type URL

type URL struct {
	*Server
	// contains filtered or unexported fields
}

func NewURL

func NewURL(project string, serv *Server) *URL

func (*URL) Build

func (a *URL) Build(app string, ctl string, act string, params ...interface{}) (r string)

func (*URL) BuildByPath

func (a *URL) BuildByPath(path string, args ...map[string]interface{}) (r string)

func (*URL) FuncPath

func (a *URL) FuncPath(h interface{}) string

func (*URL) Get

func (a *URL) Get(key string) (u *Url)

func (*URL) Set

func (a *URL) Set(route string, h interface{}, memo ...string) (pkg string, ctl string, act string)

func (*URL) SetByKey

func (a *URL) SetByKey(route string, key string, memo ...string) *Url

func (*URL) SetProjectPath

func (a *URL) SetProjectPath(projectPath string)

func (*URL) Urls

func (a *URL) Urls() map[string]*Url

type Url

type Url struct {
	Route  string
	Format string
	Params []string
	Memo   string
	// contains filtered or unexported fields
}

func NewUrl

func NewUrl() *Url

func (*Url) Gen

func (m *Url) Gen(vals interface{}) (r string)

func (*Url) Set

func (m *Url) Set(route string, memo ...string)

func (*Url) SetExts

func (m *Url) SetExts(exts []string)

func (*Url) ValidExt

func (m *Url) ValidExt(ext string) (ok bool)

type Webxer

type Webxer interface {
	URL(echo.Handler, ...interface{}) string
	SetRenderer(echo.Renderer)
	Use(...echo.Middleware)
	PreUse(...echo.Middleware)
	Any(string, echo.Handler, ...echo.Middleware)
	Match([]string, string, echo.Handler, ...echo.Middleware)
	Trace(string, echo.Handler, ...echo.Middleware)
	Group(string, ...echo.Middleware) *echo.Group
}

type Wrapper

type Wrapper struct {
	//静态实例中的行为
	BeforeHandler HandlerFunc
	AfterHandler  HandlerFunc

	//动态实例中的行为状态
	HasBefore bool
	HasAfter  bool

	//实例对象
	Controller interface{}

	Webx Webxer
	*App
}

func (*Wrapper) Auto

func (a *Wrapper) Auto(args ...interface{})

自动注册动态实例的路由:Controller.Auto()

func (*Wrapper) R

func (a *Wrapper) R(path string, h HandlerFunc, methods ...string) *Wrapper

路由注册方案1:注册函数(可匿名)或静态实例的成员函数 例如:Controller.R(`/index`,Index.Index,"GET","POST")

func (*Wrapper) RouteMethods

func (a *Wrapper) RouteMethods()

路由注册方案3:自动注册动态实例内带HTTP方法名后缀的成员函数作为路由

func (*Wrapper) RouteTags

func (a *Wrapper) RouteTags()

路由注册方案2:从动态实例内Mapper类型字段标签中获取路由信息

func (*Wrapper) SafelyCall

func (a *Wrapper) SafelyCall(fn reflect.Value, args []reflect.Value) (resp []reflect.Value, err error)

safelyCall invokes `function` in recover block

Directories

Path Synopsis
lib
cachestore/redigo/redis
Package redis is a client for the Redis database.
Package redis is a client for the Redis database.
cachestore/redigo/redisx
Package redisx contains experimental features for Redigo.
Package redisx contains experimental features for Redigo.
captcha
Package captcha implements generation and verification of image and audio CAPTCHAs.
Package captcha implements generation and verification of image and audio CAPTCHAs.
captcha/capexample
example of HTTP server that uses the captcha package.
example of HTTP server that uses the captcha package.
captcha/capgen
capgen is an utility to test captcha generation.
capgen is an utility to test captcha generation.
captcha/capgensounds
generate is a tool to generate sounds.go from WAVE files.
generate is a tool to generate sounds.go from WAVE files.
com
forms/common
This package provides basic constants used by go-form-it packages.
This package provides basic constants used by go-form-it packages.
forms/widgets
This package contains the base logic for the creation and rendering of field widgets.
This package contains the base logic for the creation and rendering of field widgets.
get
middleware/method
Method implements the ability to override HTTP methods This package was created from github.com/codegangsta/martini-contrib/method and modified to work with the echo framework
Method implements the ability to override HTTP methods This package was created from github.com/codegangsta/martini-contrib/method and modified to work with the echo framework
middleware/session
Session implements middleware for easily using github.com/gorilla/sessions within echo.
Session implements middleware for easily using github.com/gorilla/sessions within echo.
minify
Package cssmin minifies CSS.
Package cssmin minifies CSS.
tplex
* * 模板扩展 * @author swh <swh@admpub.com> Copyright 2016 Wenhui Shen <www.webx.top> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* * 模板扩展 * @author swh <swh@admpub.com> Copyright 2016 Wenhui Shen <www.webx.top> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
uuid
The uuid package generates and inspects UUIDs.
The uuid package generates and inspects UUIDs.

Jump to

Keyboard shortcuts

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