app

package
v0.0.0-...-ec8cf66 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CONTEXT_RENDERED = "context_rendered"
	CONTEXT_END      = "context_end"
	CONTEXT_SEND     = "context_send"
)
View Source
const (
	ROUTER_METHOD_GET    = "GET"
	ROUTER_METHOD_POST   = "POST"
	ROUTER_METHOD_PUT    = "PUT"
	ROUTER_METHOD_DELETE = "DELETE"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

func NewApp

func NewApp() *App

func (*App) Config

func (this *App) Config() *ConfigFile

func (*App) Delete

func (this *App) Delete(method string, fn ...Handler)

func (*App) Get

func (this *App) Get(method string, fn ...Handler)

func (*App) GetString

func (this *App) GetString(key string) string

func (*App) NotFound

func (this *App) NotFound(h Handler)

func (*App) Post

func (this *App) Post(method string, fn ...Handler)

func (*App) Put

func (this *App) Put(method string, fn ...Handler)

func (*App) Route

func (this *App) Route(method, key string, fn ...Handler)

func (*App) Run

func (this *App) Run()

func (*App) ServeHTTP

func (this *App) ServeHTTP(res http.ResponseWriter, req *http.Request)

func (*App) Static

func (this *App) Static(h Handler)

type ConfigFile

type ConfigFile struct {
	BlockMode bool
	// contains filtered or unexported fields
}

func LoadConfigFile

func LoadConfigFile(fileName string, moreFiles ...string) *ConfigFile

*

  • 加载配置文件初始化函数 *
  • @author Vckai.
  • @date 2014-04-03

func (*ConfigFile) Bool

func (this *ConfigFile) Bool(key string) (bool, error)

*

  • 获取bool类型的配置值

func (*ConfigFile) Float64

func (this *ConfigFile) Float64(key string) (float64, error)

*

  • 获取配置值, 并转换为浮点型

func (*ConfigFile) GetValue

func (this *ConfigFile) GetValue(key string) (string, error)

*

  • 获取配置

func (*ConfigFile) Int

func (this *ConfigFile) Int(key string) (int, error)

*

  • 获取配置值, 并转换为整型

func (*ConfigFile) Int64

func (this *ConfigFile) Int64(key string) (int64, error)

*

  • 获取配置值, 并转换为64位整型

func (*ConfigFile) MustBool

func (this *ConfigFile) MustBool(key string, defaultValue ...bool) bool

func (*ConfigFile) MustFloat64

func (this *ConfigFile) MustFloat64(key string, defaultValue ...float64) float64

func (*ConfigFile) MustInt

func (this *ConfigFile) MustInt(key string, defaultValue ...int) int

func (*ConfigFile) MustInt64

func (this *ConfigFile) MustInt64(key string, defaultValue ...int64) int64

func (*ConfigFile) MustValue

func (this *ConfigFile) MustValue(key string, defaultValue ...string) string

*

  • 获取配置值, 字符串类型, 可传入默认值, 如果不存在则返回默认值

func (*ConfigFile) SetData

func (this *ConfigFile) SetData(key, val string)

*

  • 设置配置项

type Context

type Context struct {
	Request    *http.Request
	BaseUrl    string
	Url        string
	RequestUrl string
	Method     string
	Ip         string
	UserAgent  string
	Referer    string
	Host       string
	Ext        string
	IsSSH      bool
	IsAjax     bool

	Response http.ResponseWriter
	Status   int
	Header   map[string]string
	Body     []byte

	RouteParams map[string]string

	IsSend bool
	IsEnd  bool
	// contains filtered or unexported fields
}

func NewContext

func NewContext(app *App, res http.ResponseWriter, req *http.Request) *Context

func (*Context) App

func (this *Context) App() *App

App returns *App instance in this context.

func (*Context) ContentType

func (this *Context) ContentType(contentType string)

ContentType sets content-type string.

func (*Context) Cookie

func (this *Context) Cookie(key string, value ...string) string

*

  • 获取或者设置cookie

func (*Context) Do

func (this *Context) Do(e string, args ...interface{}) [][]interface{}

func (*Context) Download

func (this *Context) Download(file string)

Download sends file download response by file path.

func (*Context) End

func (this *Context) End()

func (*Context) Func

func (this *Context) Func(name string, fn interface{})

Func adds template function to view. It will affect global *View instance.

func (*Context) GetHeader

func (this *Context) GetHeader(key string) string

GetHeader returns header string by given key.

func (*Context) Json

func (this *Context) Json(data interface{})

Json set json response with data and proper header.

func (*Context) MustString

func (this *Context) MustString(key, def string) string

func (*Context) On

func (this *Context) On(e string, fn interface{})

On registers event function to event name string.

func (*Context) Redirect

func (this *Context) Redirect(url string, status ...int)

Redirect does redirection response to url string and status int optional.

func (*Context) Render

func (this *Context) Render(tpl string, data map[string]interface{})

Render does template and layout rendering with data. The result bytes are assigned to context.Body. If error, panic.

func (*Context) Send

func (this *Context) Send()

Send does response sending. If response is sent, do not sent again.

func (*Context) String

func (this *Context) String(key string) string

func (*Context) Strings

func (this *Context) Strings(key string) []string

func (*Context) Throw

func (this *Context) Throw(status int, message ...interface{})

Throw throws http status error and error message. It call event named as status. The context will be end.

func (*Context) Tpl

func (this *Context) Tpl(tpl string, data map[string]interface{}) string

Tpl returns string of rendering template with data. If error, panic.

type Handler

type Handler func(context *Context)

type Route

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

type Router

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

func NewRouter

func NewRouter() *Router

func (*Router) Delete

func (this *Router) Delete(pattern string, fn ...Handler)

func (*Router) Find

func (this *Router) Find(url, method string) (params map[string]string, fn []Handler)

func (*Router) Get

func (this *Router) Get(pattern string, fn ...Handler)

func (*Router) Post

func (this *Router) Post(pattern string, fn ...Handler)

func (*Router) Put

func (this *Router) Put(pattern string, fn ...Handler)

func (*Router) Router

func (this *Router) Router(method, pattern string, fn ...Handler)

type View

type View struct {
	Dir     string
	FuncMap template.FuncMap
	IsCache bool
	// contains filtered or unexported fields
}

func NewView

func NewView(dir string) *View

func (*View) Render

func (this *View) Render(tpl string, data map[string]interface{}) ([]byte, error)

Jump to

Keyboard shortcuts

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