leafveingo

package module
v0.0.0-...-6aeb21f Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2015 License: Apache-2.0 Imports: 34 Imported by: 0

README

Leafveingo web framework

框架架构与概念
Leafveingo是一个轻量级的MVC web框架,帮助快速简洁的完成一个web或api项目。
Leafveingo是以模块组件进行开发,要求的是高效耦合度,将特殊的模块进行划分,分开进行调用与设置。

特点:
	1. 多项目集成,同一个端口可运行多个项目或使用不同端口运行。
	2. 灵活的路由接口,可自定义实现路由,只需要根据规则进行即可。
	3. 待续..

目前只是一个基础框架,有很多功能都没有实现,后续会继续实现更多便捷实用的功能模块。
开发项目组织结构
  $GOPATH
	└─src
	   └─samplebuild 		// 项目的编译目录(以build为结尾)
	      ├─sample			// app项目名称目录,需要与编译文件同一个目录,这样编译文件就会根据设置的App名称查找到所需要的文件操作文件
	      │  ├─template     // 存放模板文件目录
	      │  ├─webRoot 	  // web工作主目录,主要存放静态文件js、css、html...等公共访问文件,webRoot目录下都可以自定义分配安排,以下只是建议的项目规划
	      │  │  ├─images 			// (可选) 一些网站所使用的公用图片目录
	      │  │  ├─js 				// (可选) javascript 文件目录
	      │  │  └─themes 			// (可选) css主题存放目录,这样做的目的主要是可以方便切换皮肤
	      │  │     ├─core 			// (可选) css核心文件目录
	      │  │     │  └─core.css 	  // (可选) css核心文件
	      │  │     └─default 		// (可选) 默认css皮肤主题目录
	      │  │        ├─css 		// (可选) 默认皮肤主题的css存放目录
	      │  │        │  ├─images   // (可选) 默认皮肤主题所使用的图片目录,这样style.css访问图片路径时更好操作。
	      │  │        │  └─style.css// (可选) 默认皮肤主题的css文件
	      │  │        └─js 			// (可选) 默认皮肤主题所使用的javascript文件目录
	      │  │           └─init.js 	// (可选) 默认皮肤主题所需要初始化的javascript函数或布局所使用的文件
 	      │  └─config 		// 配置文件存放目录
	      ├─src 			  // 存放源代码的文件夹分类(src只是为了区分源代码文件和其他资源文件)
	      │  ├─controllers 	// 控制器源代码文件目录
	      │  └─models 		// 模型目录
	      └─main.go 		  // 项目主文件

安装与使用

使用go命令

1.安装核心组件
go get github.com/slowfei/gosfcore
2.由于session使用了UUID也需要进行安装
go get github.com/slowfei/gosfuuid
3.安装Leafveingo
go get github.com/slowfei/leafveingo
简单实例

默认使用8080端口

main.go

package main

import (
	"github.com/slowfei/leafveingo"
	router "github.com/slowfei/leafveingo/router"
)

type MainController struct {
	tag string
}

//	控制器的默认请求访问的函数(Index),URL结尾检测为"/"( http://localhost:8080/ )
func (m *MainController) Index() string {
	return "Hello world, Leafvingo web framework"
}

func main() {
	//	创建服务
	server := leafveingo.NewLeafveinServer("sample", leafveingo.DefaultOption())

	//	添加控制器
	server.AddRouter(router.CreateReflectController("/", MainController{}))
	
	//	启动
	leafveingo.Start()
}

go build 编译可执行文件(samplebuild)

可选择开发模式运行(加上参数-devel):./samplebuild -devel

然后在浏览器中打开:http://localhost:8080/ 这样就会默认进入到MainController的Index函数中。

然后浏览器中会输出:Hello world, Leafvingo web framework

出现的错误信息

can't find import: "github.com/slowfei/gosfcore/*..."
can't find import: "github.com/slowfei/gosfuuid"

直接在需要编译的项目路径中用go install命令来安装gosfcore和gosfuuid

进入Leafveingo基础入门 (注意:Leafveingo整改后文档还未整改完成,可以先查看sample案例)

框架功能

  1. 路由器机制
  2. 静态文件解析
  3. 控制器
  4. HttpSession
  5. HttpContext
  6. 模板
  7. 日志工具
  8. 配置文件
  9. 状态页

使用协议 LICENSE

Leafveingo All source code is licensed under the Apache License, Version 2.0 (the "License");

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

Documentation

Overview

leafveingo config handle

web request context

controller handle

error info manager

Leafveingo web framework

web form params pack struct

response body result out

router manager

web status page manager

golang system some private functions implement

Index

Constants

View Source
const (
	//	default web root dir name
	DEFAULT_WEBROOT_DIR_NAME = "webRoot"
	//	default template dir name
	DEFAULT_TEMPLATE_DIR_NAME = "template"

	//	file size default upload  32M
	DEFAULT_FILE_UPLOAD_SIZE int64 = 32 << 20
	//	server time out default 0
	DEFAULT_SERVER_TIMEOUT = 0
	//	default template suffix
	DEFAULT_TEMPLATE_SUFFIX = ".tpl"
	//	default html charset
	DEFAULT_HTML_CHARSET = "utf-8"
	//	default response write compress
	DEFAULT_RESPONSE_WRITE_COMPRESS = true
	//	default session max life time 1800 seconds
	DEFAULT_SESSION_MAX_LIFE_TIME = 1800
	//	default log channel size
	DEFAULT_LOG_CHANNEL_SIZE = 5000

	//	default KeepAlivePeriod
	DEFAULT_KEEP_ALIVE_PERIOD = 3 * time.Minute
)
View Source
const (

	//	leafveingo version
	VERSION string = "0.0.2.000"

	// template func key
	TEMPLATE_FUNC_KEY_VERSION     = "Leafveingo_version"
	TEMPLATE_FUNC_KEY_APP_VERSION = "Leafveingo_app_version"
	TEMPLATE_FUNC_KEY_APP_NAME    = "Leafveingo_app_name"
	TEMPLATE_FUNC_KEY_IS_DEVEL    = "Leafveingo_devel"

	//	不知道为什么golang使用http.ServeFile判断为此结尾就重定向到/index.html中。
	//	这里定义主要用来解决这个问题的处理
	INDEX_PAGE = "/index.html"

	//
	FAVICON_PATH = "/favicon.ico"

	//	url params host key
	URL_HOST_KEY = "host"

	//	hosts www
	URL_HOST_WWW     = "www."
	URL_HOST_WWW_LEN = 4

	//	uri schemes
	URI_SCHEME_HTTP  = URIScheme(1) // http
	URI_SCHEME_HTTPS = URIScheme(2) // https
)
View Source
const (
	HttpStartTemplate = `` /* 1314-byte string literal not displayed */

	Status301Msg = "Moved Permanently"
	Status302Msg = "Moved Temporarily"
	Status307Msg = "Temporary Redirect"
	Status400Msg = "Bad Request"
	Status403Msg = "Forbidden The server understood the request"
	Status404Msg = "Page Not Found"
	Status500Msg = "Internal Server Error"
	Status503Msg = "Service Unavailable"
)
View Source
const (
	HTML_FORM_TOKEN_NAME = "formToken"
)

Variables

View Source
var (
	// controller reflect type
	RefTypeBeforeAfterController = reflect.TypeOf((*BeforeAfterController)(nil)).Elem()
	RefTypeAdeRouterController   = reflect.TypeOf((*AdeRouterController)(nil)).Elem()
)
View Source
var (
	//	http session manager close status
	ErrHttpSessionManagerClosed = NewLeafveinError("HttpSession manager has been closed or not started.")

	ErrControllerReturnParam    = NewLeafveinError("controllers return type parameter error.")
	ErrControllerReturnParamNum = NewLeafveinError("controller returns the number of type parameters allowed only one.")

	// 转发找不到控制器
	ErrControllerDispatcherNotFound    = NewLeafveinError("dispatcher: controller not found.")
	ErrControllerDispatcherFuncNameNil = NewLeafveinError("dispatcher: func name is nil.")

	//	Leafvein app name repeat
	ErrLeafveinAppNameRepeat = NewLeafveinError("Leafvein server app name repeat.")

	//	Leafveingo 配置对象未初始化
	ErrLeafveinInitLoadConfig    = NewLeafveinError("Leafvein initialized load config error.")
	ErrLeafveinLoadDefaultConfig = NewLeafveinError("Leafvein load default config error.")

	//	host nil
	ErrLeafveinSetHostNil = NewLeafveinError("Leafvein set host len()==0 or nil.")

	//	template path pase is nil
	ErrTemplatePathParseNil = NewLeafveinError("template path parse is nil.")

	//	form params
	ErrParampackParseFormParams = NewLeafveinError("form params parse error.")
	ErrParampackNewStruct       = NewLeafveinError("form params new struct error.")
)
View Source
var (
	//	http status support code
	//	http://zh.wikipedia.org/wiki/HTTP%E7%8A%B6%E6%80%81%E7%A0%81
	Status200 = HttpStatus(200)
	Status301 = HttpStatus(301)
	Status302 = HttpStatus(302)
	Status307 = HttpStatus(307)
	Status400 = HttpStatus(400)
	Status403 = HttpStatus(403)
	Status404 = HttpStatus(404)
	Status500 = HttpStatus(500)
	Status503 = HttpStatus(503)
	StatusNil = HttpStatus(-100)
)
View Source
var (
	//	开发模式命令
	FlagDeveloper bool
)

Functions

func AddRouter

func AddRouter(appName string, router IRouter)

*

  • global add router *
  • @param appName
  • @param routerKey
  • @param router

func BodyJson

func BodyJson(value interface{}) SFJson.Json

out json text, application/json

func BodyTemplate

func BodyTemplate(data interface{}) LVTemplate.TemplateValue

*

  • by template out html, text/html *
  • default template path by IRouter interface implementation definition *
  • @param data
  • @return TemplateValue

func BodyTemplateByTplName

func BodyTemplateByTplName(tplName string, data interface{}) LVTemplate.TemplateValue

*

  • by cache template name out content *
  • @param tplName
  • @param data
  • @return TemplateValue

func BodyTemplateByTplPath

func BodyTemplateByTplPath(tplPath string, data interface{}) LVTemplate.TemplateValue

*

  • by template out content
  • custom template path: (templateDir)/(tplPath).tpl
  • e.g.: tplPath = "custom/base.tpl"
  • templatePath = (templateDir)/custom/base.tpl *
  • @param tplPath custom template path
  • @param data
  • @return TemplateValue

func BodyText

func BodyText(text string) string

out text text/plain

func Close

func Close()

*

  • global close all leafvein server *

func SetLogManager

func SetLogManager(channelSize int)

func Start

func Start()

*

  • global start all leafvein server *

func StatusCodeToString

func StatusCodeToString(status HttpStatus) string

*

  • status code convert string *
  • @param status
  • @return

func StatusMsg

func StatusMsg(status HttpStatus) string

*

  • 根据状态获取相应的字符串信息 *
  • @status
  • @return

func Version

func Version() string

*

  • leafveion version info *
  • @return

Types

type AdeRouterController

type AdeRouterController interface {

	/**
	 *	路由函数解析,解析工作完全交由现实对象进行。
	 *
	 *	@param option router params option
	 *	@return funcName	is "" jump 404 page, other by name call controller
	 *	@return params		add to request form param, use set Request.URL.Query()
	 */
	RouterMethodParse(option *RouterOption) (funcName string, params map[string]string)
}

高级路由器控制器接口,实现高级路由器机制的控制器需要实现该接口 特别注意,指针添加控制器和值添加的控制器的实现区别 指针控制器的实现: func (c *XxxController) RouterMethodParse...

值控制器的实现:func (c XxxController) RouterMethodParse...

type BeforeAfterController

type BeforeAfterController interface {

	/**
	 *  before the call controller func
	 *
	 *	@param context
	 *	@param option
	 *	@return Status200 pass, StatusNil stop Next to proceed, other status jump relevant status page
	 *
	 */
	Before(context *HttpContext, option *RouterOption) HttpStatus

	/**
	 *	after the call controller func
	 *
	 * 	@param context
	 *	@param option
	 */
	After(context *HttpContext, option *RouterOption)
}

before after interface

type ByteOut

type ByteOut struct {
	Body        []byte            // out content
	ContentType string            // content type "text/plain; charset=utf-8" || "image/png" ...
	Headers     map[string]string // 可以为空,看是否需要设置其他头部信息
}

body out

func BodyByte

func BodyByte(content []byte, contentType string, headers map[string]string) ByteOut

*

  • out []byte *
  • @param content body content
  • @param contentType 内容类型,"" = "text/plain; charset=utf-8"
  • @param headers 需要添加头部的其他信息
  • @return ByteOut

type Config

type Config struct {
	AppVersion          string   // app version.
	FileUploadSize      int64    // file size upload
	Charset             string   // html encode type
	StaticFileSuffixes  []string // supported static file suffixes
	ServerTimeout       int64    // server time out, default 0
	SessionMaxlifeTime  int32    // http session maxlife time, unit second. use session set
	IPHeaderKey         string   // proxy to http headers set ip key, default ""
	IsReqPathIgnoreCase bool     // request url path ignore case
	MultiProjectHosts   []string // setting integrated multi-project hosts,default nil

	TemplateSuffix string // template suffix
	IsCompactHTML  bool   // is Compact HTML, default true

	LogConfigPath string // log config path, relative or absolute path, relative path from execute file root directory
	LogGroup      string // log group name

	TLSCertPath string // tls cert.pem, relative or absolute path, relative path from execute file root directory
	TLSKeyPath  string // tls key.pem
	TLSPort     int    // tls run prot, default server port+1
	TLSAloneRun bool   // are leafveingo alone run tls server, default false

	// is ResponseWriter writer compress gizp...
	// According Accept-Encoding select compress type
	// default true
	IsRespWriteCompress bool

	UserData map[string]string // user custom config other info
}

*

  • leafveingo config
  • default see _defaultConfigJson

type ControllerOption

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

func (*ControllerOption) Checked

func (c *ControllerOption) Checked()

*

  • checked params

func (ControllerOption) Host

func (c ControllerOption) Host() string

*

  • get host *
  • @return

func (ControllerOption) Scheme

func (c ControllerOption) Scheme() URIScheme

*

  • get sheme *
  • @return

func (*ControllerOption) SetHost

func (c *ControllerOption) SetHost(host string)

*

  • set host
  • "svn.slowfei.com" || "wwww.slowfei.com" || ""(wildcard)

func (*ControllerOption) SetScheme

func (c *ControllerOption) SetScheme(scheme URIScheme)

*

  • set the support scheme *
  • URI_SCHEME_HTTPS | URI_SCHEME_HTTP

type Dispatcher

type Dispatcher struct {
	RouterKey string
	FuncName  string
	Headers   map[string]string
}

dispatcher controller struct

func BodyCallController

func BodyCallController(routerKey, funcName string) Dispatcher

*

  • dispatcher controller *
  • @param routerKey router key
  • @param funcName controller call func name
  • @return Dispatcher

func BodyCallControllerByHeaders

func BodyCallControllerByHeaders(routerKey, funcName string, setHeaders map[string]string) Dispatcher

*

  • dispatcher controller, set headers info *
  • @param routerKey router key
  • @param funcName controller call func name
  • @param setHeaders header info
  • @return Dispatcher

type HtmlOut

type HtmlOut string

body out HTML string

func BodyHtml

func BodyHtml(html string) HtmlOut

out html text/html

type HttpContext

type HttpContext struct {
	RespWrite http.ResponseWriter
	Request   *http.Request
	// contains filtered or unexported fields
}

request context

func (*HttpContext) Application

func (ctx *HttpContext) Application() *SFHelper.Map

*

  • get global info storage map *
  • @return SFHelper.Map

func (*HttpContext) CheckFormToken

func (ctx *HttpContext) CheckFormToken() bool

*

  • check form token *
  • @return true is pass

func (*HttpContext) CheckFormTokenByString

func (ctx *HttpContext) CheckFormTokenByString(token string) bool

*

  • custom check form token *
  • @param true is pass

func (*HttpContext) ComperssWriter

func (ctx *HttpContext) ComperssWriter() io.Writer

*

  • get comperss writer *
  • @return

func (*HttpContext) FormTokenHTML

func (ctx *HttpContext) FormTokenHTML() string

*

  • get html input form token
  • Note: each access will change *
  • @return

func (*HttpContext) FormTokenJavascript

func (ctx *HttpContext) FormTokenJavascript() string

*

  • get javascript the out form token, (主要防止页面抓取)
  • Note: each access will change *
  • @return

func (*HttpContext) FormTokenString

func (ctx *HttpContext) FormTokenString() string

*

  • get string form token
  • Note: each access will change *
  • @return

func (*HttpContext) FuncNames

func (ctx *HttpContext) FuncNames() []string

*

  • request controller methods *
  • @return

func (*HttpContext) GetIRouter

func (ctx *HttpContext) GetIRouter(routerKey string) (IRouter, bool)

*

  • get router list element *
  • @return *RouterElement

func (*HttpContext) LVServer

func (ctx *HttpContext) LVServer() *LeafveinServer

*

  • get current leafvein server *
  • @return *LeafveinServer

func (*HttpContext) PackStructForm

func (ctx *HttpContext) PackStructForm(nilStruct interface{}) (ptrStruct interface{}, err error)

*

  • pack stauct form params *
  • @param nilStruct (*TestStruct)(nil)
  • @return new pointer struct by Type

func (*HttpContext) PackStructFormByRefType

func (ctx *HttpContext) PackStructFormByRefType(structType reflect.Type) (refVal reflect.Value, err error)

*

  • pack stauct form params by reflect type *
  • @param structType
  • @return refVal
  • @return err

func (*HttpContext) RequestBody

func (ctx *HttpContext) RequestBody() []byte

*

  • get request body content *
  • @return

func (*HttpContext) RequestHost

func (ctx *HttpContext) RequestHost() string

*

  • request host *
  • @return lowercase string

func (*HttpContext) RequestScheme

func (ctx *HttpContext) RequestScheme() URIScheme

*

  • request uri scheme *
  • @return URIScheme

func (*HttpContext) RespBodyWrite

func (ctx *HttpContext) RespBodyWrite(body []byte, code HttpStatus)

*

  • response comperss write
  • 会根据Accept-Encoding支持的格式进行压缩,优先gzip *
  • @param body write content
  • @param code status code

func (*HttpContext) RespBodyWriteNotComperss

func (ctx *HttpContext) RespBodyWriteNotComperss(body []byte, code HttpStatus)

*

  • response not comperss write Content-Encoding = none *
  • @param body
  • @param code

func (*HttpContext) RouterKeys

func (ctx *HttpContext) RouterKeys() []string

*

  • requset router keys *
  • @return

func (*HttpContext) Session

func (ctx *HttpContext) Session(resetToken bool) (LVSession.HttpSession, error)

*

  • get session, context the only session *
  • @param resetToken is reset session token
  • @return HttpSession
  • @return error

func (*HttpContext) StatusPageWrite

func (ctx *HttpContext) StatusPageWrite(status HttpStatus, msg, error, stack string) error

*

  • status page write
  • 指定模版的几个参数值,在模板中信息信息的输出
  • 模版的默认map key: {{.msg}} {{.status}} {{.error}} {{.stack}} *
  • @param status status code
  • @param msg
  • @param error
  • @param stack
  • @return

func (*HttpContext) StatusPageWriteByValue

func (ctx *HttpContext) StatusPageWriteByValue(value HttpStatusValue) error

*

  • status page write
  • 可以自定义指定模版的参数 *
  • @param value
  • @return

type HttpStatus

type HttpStatus int16

http status code

type HttpStatusValue

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

数据的封装

func BodyStatusPage

func BodyStatusPage(status HttpStatus, msg, error, stack string) HttpStatusValue

*

  • out status page *
  • @param status Status404...
  • @param msg
  • @param error
  • @param stack
  • @return HttpStatusValue

func BodyStatusPageByData

func BodyStatusPageByData(status HttpStatus, data map[string]string) HttpStatusValue

*

  • out status pata custom data map *
  • @param status
  • @param data
  • @return HttpStatusValue

func NewHttpStatusValue

func NewHttpStatusValue(status HttpStatus, msg, error, stack string) HttpStatusValue

new status value

type IRouter

type IRouter interface {

	/**
	 *	1. after router parse
	 *
	 *	@param context
	 *	@param option
	 *	@return HttpStatus  200 pass
	 */
	AfterRouterParse(context *HttpContext, option *RouterOption) HttpStatus

	/**
	 *	2. parse func name
	 *
	 *	@param context			http context
	 *	@param option			router option
	 *	@return funcName 		function name specifies call
	 *	@return statusCode		http status code, 200 pass, other to status page
	 */
	ParseFuncName(context *HttpContext, option *RouterOption) (funcName string, statusCode HttpStatus, err error)

	/**
	 *	3. before call func
	 *
	 *	@param context
	 *	@param option
	 *	@return HttpStatus
	 */
	CallFuncBefore(context *HttpContext, option *RouterOption) HttpStatus

	/**
	 *	4. request func
	 *
	 *	@param context			http content
	 *	@param funcName			call controller func name
	 *	@param option			router option
	 *	@return returnValue		controller func return value
	 *	@return statusCode		http status code, 200 pass, other to status page
	 */
	CallFunc(context *HttpContext, funcName string, option *RouterOption) (returnValue interface{}, statusCode HttpStatus, err error)

	/**
	 *	5. parse template path
	 *	no need to add the suffix
	 *
	 *	@param context
	 *	@param funcName	 controller call func name
	 *	@param option	 router option
	 *	@return template path, suggest "[routerKey]/[funcName]"
	 */
	ParseTemplatePath(context *HttpContext, funcName string, option *RouterOption) string

	/**
	 *	6. after call func
	 *
	 *	@param context
	 *	@param option
	 */
	CallFuncAfter(context *HttpContext, option *RouterOption)

	/**
	 *	@return router key
	 */
	RouterKey() string

	/**
	 *	@return controller option
	 */
	ControllerOption() ControllerOption

	/**
	 *	@return controller info
	 */
	Info() string
}

router interface

type LeafveinError

type LeafveinError struct {
	Message  string
	UserInfo string
}

leafveingo error

func NewLeafveinError

func NewLeafveinError(format string, args ...interface{}) *LeafveinError

new error info

func (*LeafveinError) Equal

func (err *LeafveinError) Equal(eqErr *LeafveinError) bool

*

  • equal error *
  • @param
  • @return

func (*LeafveinError) Error

func (err *LeafveinError) Error() string

*

  • error string *
  • @return

type LeafveinServer

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

Leafvein Http Server

func GetServer

func GetServer(appName string) *LeafveinServer

*

  • by app name get leafvein server *
  • @param appName
  • @return

func NewLeafveinServer

func NewLeafveinServer(appName string, option ServerOption) *LeafveinServer

*

  • new http server *
  • @param appName application name not is null
  • @param option server other option

func (*LeafveinServer) AddCacheTemplate

func (lv *LeafveinServer) AddCacheTemplate(tplName, src string) error

*

  • add cache template *
  • @param tplName template unique name
  • @param src template content
  • @return error info

func (*LeafveinServer) AddRouter

func (lv *LeafveinServer) AddRouter(router IRouter)

*

  • add router
  • leafvein interface implement RESTfulRouter ReflectRouter *
  • match rules:
  • (keys sort of long to short)
  • keys =[
  • "/admin/user/"
  • "/admin/"
  • "/user/"
  • "/"
  • ] *
  • e.g.: *
  • [urlPath] = [key]; $host = "http://localhost:8080"
  • $host/admin/user/manager = "/admin/user/"
  • $host/admin/index = "/admin/"
  • $host/user/index = "/user/"
  • $host/admin = "/"
  • $host/index = "/" *
  • @param router *

func (*LeafveinServer) AddTemplateFunc

func (lv *LeafveinServer) AddTemplateFunc(key string, methodFunc interface{})

*

  • add template function *
  • @param `key` the template use func key, please ignore repeated system
  • @param `methodFunc`

func (*LeafveinServer) Addr

func (lv *LeafveinServer) Addr() string

*

  • get addr *
  • @return

func (*LeafveinServer) AppName

func (lv *LeafveinServer) AppName() string

*

  • get application name *
  • @return

func (*LeafveinServer) AppVersion

func (lv *LeafveinServer) AppVersion() string

*

  • get application version *
  • @return

func (*LeafveinServer) Application

func (lv *LeafveinServer) Application() *SFHelper.Map

*

  • web application map *
  • @return

func (*LeafveinServer) Charset

func (lv *LeafveinServer) Charset() string

*

  • get html encoding type *
  • @return

func (*LeafveinServer) Close

func (lv *LeafveinServer) Close()

*

  • close Leafvein server *
  • TODO Temporarily invalid, keep extension

func (*LeafveinServer) FileUploadSize

func (lv *LeafveinServer) FileUploadSize() int64

*

  • get file size upload *
  • @return

func (*LeafveinServer) GetHandlerFunc

func (lv *LeafveinServer) GetHandlerFunc(prefix string) (handler http.Handler, err error)

*

  • 获取leafveingo的一个Handler, 方便在其他应用进行扩展leafveingo
  • get leafveingo handler, Easily be extended to other applications *
  • @prefix url prefix

func (*LeafveinServer) HttpSessionManager

func (lv *LeafveinServer) HttpSessionManager() *LVSession.HttpSessionManager

*

  • http session manager

func (*LeafveinServer) IsCompactHTML

func (lv *LeafveinServer) IsCompactHTML() bool

*

  • get is compact HTML

func (*LeafveinServer) IsDevel

func (lv *LeafveinServer) IsDevel() bool

*

  • developer mode *
  • @return true is developer mode

func (*LeafveinServer) IsReqPathIgnoreCase

func (lv *LeafveinServer) IsReqPathIgnoreCase() bool

*

  • get is request path ignore case *
  • @return

func (*LeafveinServer) IsRespWriteCompress

func (lv *LeafveinServer) IsRespWriteCompress() bool

*

  • RespWriteCompress *
  • @return

func (*LeafveinServer) IsStart

func (lv *LeafveinServer) IsStart() bool

*

  • is starting *
  • @return

func (*LeafveinServer) Log

func (lv *LeafveinServer) Log() *SFLog.SFLogger

*

  • get log object *
  • @return

func (*LeafveinServer) LogConfPath

func (lv *LeafveinServer) LogConfPath() string

*

  • get log config path

func (*LeafveinServer) LogGroup

func (lv *LeafveinServer) LogGroup() string

*

  • get log group name *
  • @return

func (*LeafveinServer) MultiProjectHosts

func (lv *LeafveinServer) MultiProjectHosts() []string

*

  • get project hosts *
  • @return

func (*LeafveinServer) OperatingDir

func (lv *LeafveinServer) OperatingDir() string

*

  • current leafveingo the file operation directory
  • OperatingDir() path is created based on AppName *
  • @return

func (*LeafveinServer) Port

func (lv *LeafveinServer) Port() int

*

  • get port *
  • @return

func (*LeafveinServer) ServeHTTP

func (lv *LeafveinServer) ServeHTTP(rw http.ResponseWriter, req *http.Request)

*

  • ServeHTTP *
  • @param rw
  • @param req

func (*LeafveinServer) ServerTimeout

func (lv *LeafveinServer) ServerTimeout() int64

*

  • get server time out *
  • @return

func (*LeafveinServer) SessionMaxlifeTime

func (lv *LeafveinServer) SessionMaxlifeTime() int32

*

  • get http session maxlife time, unit second

func (*LeafveinServer) SetAppVersion

func (lv *LeafveinServer) SetAppVersion(version string)

*

  • set application version *
  • @param version

func (*LeafveinServer) SetCharset

func (lv *LeafveinServer) SetCharset(encode string)

*

  • set html encoding type *
  • @param encode default utf-8

func (*LeafveinServer) SetCompactHTML

func (lv *LeafveinServer) SetCompactHTML(compact bool)

*

  • out html is compact remove (\t \n space) sign
  • only template file out use *
  • Note: need to restart Leafvein Server *
  • @param compact default true

func (*LeafveinServer) SetCorrectRequestFunc

func (l *LeafveinServer) SetCorrectRequestFunc(f func(req *http.Request))

*

  • 修正Requset的设置函数,由于在使用不同的http代理转发操作时解析的参数可能与golang操作的不符合。
  • 所以建立此函数在请求前可根据使用的代理转发进行Request的修改。 *
  • @param `f` func(req *http.Request)

func (*LeafveinServer) SetFileUploadSize

func (lv *LeafveinServer) SetFileUploadSize(maxSize int64)

*

  • set file size upload *
  • @param maxSize default 32M

func (*LeafveinServer) SetHttpSessionManager

func (lv *LeafveinServer) SetHttpSessionManager(sessionManager *LVSession.HttpSessionManager)

*

  • custom set session manager *
  • @param sessionManager nil == stop use session

func (*LeafveinServer) SetHttpTLS

func (lv *LeafveinServer) SetHttpTLS(cretpath, keypath string, port int, aloneRun bool)

*

  • set tls run params cert.pem and key.pem
  • Note: need to restart Leafvein Server *
  • @param cretpath relative or absolute path, relative path from execute file root directory
  • @param keypath
  • @param port tls run port
  • @param aloneRun true is alone run tls server

func (*LeafveinServer) SetIPHeaderKey

func (lv *LeafveinServer) SetIPHeaderKey(key string)

*

  • use reverse proxy set header ip key *
  • @param key

func (*LeafveinServer) SetLogConfigPath

func (lv *LeafveinServer) SetLogConfigPath(path string)

*

  • set log config path *
  • Note: need to restart Leafvein Server *
  • @param path relative or absolute path, relative path from execute file root directory

func (*LeafveinServer) SetLogGroup

func (lv *LeafveinServer) SetLogGroup(groupName string)

*

  • set log group name *
  • Note: need to restart Leafvein Server *
  • @param groupName

func (*LeafveinServer) SetMultiProjectHosts

func (lv *LeafveinServer) SetMultiProjectHosts(hosts ...string)

*

  • set multi-project hosts access *
  • @param hosts "slowfei.com"(www.slwofei.com) || "svn.slowfei.com"

func (*LeafveinServer) SetReqPathIgnoreCase

func (lv *LeafveinServer) SetReqPathIgnoreCase(ignoreCase bool)

*

  • set request path ignore case *
  • @param ignoreCase default true

func (*LeafveinServer) SetRespWriteCompress

func (lv *LeafveinServer) SetRespWriteCompress(b bool)

*

  • is ResponseWriter writer compress gizp...
  • According Accept-Encoding select compress type *
  • @param b default true

func (*LeafveinServer) SetServerTimeout

func (lv *LeafveinServer) SetServerTimeout(seconds int64)

*

  • set server time out *
  • Note: need to restart Leafvein Server *
  • @param seconds default 0. seconds = 10 = 10s

func (*LeafveinServer) SetSessionMaxlifeTime

func (lv *LeafveinServer) SetSessionMaxlifeTime(second int32)

*

  • set http session maxlife time, unit second *
  • @param second default 1800 second(30 minute), must be greater than 60 seconds

func (*LeafveinServer) SetStaticFileSuffixes

func (lv *LeafveinServer) SetStaticFileSuffixes(suffixes ...string)

*

  • set static resource file suffixes *
  • @param suffixes default ".js", ".css", ".png", ".jpg", ".gif", ".ico", ".html"

func (*LeafveinServer) SetTemplateSuffix

func (lv *LeafveinServer) SetTemplateSuffix(suffix string)

*

  • set template suffix, *
  • @param suffix default ".tpl"

func (*LeafveinServer) Start

func (lv *LeafveinServer) Start(goroutine bool)

*

  • start leafvein server *
  • @param goroutine true is go func(){ // run serve }(), 关键保留一些操作在主线程来运行, 不知道的可以false

func (*LeafveinServer) StaticFileSuffixes

func (lv *LeafveinServer) StaticFileSuffixes() []string

*

  • get static resource file suffixs *
  • @return

func (*LeafveinServer) TLSCertPath

func (lv *LeafveinServer) TLSCertPath() string

*

  • get tls cert.pem file path *
  • @return

func (*LeafveinServer) TLSKeyPath

func (lv *LeafveinServer) TLSKeyPath() string

*

  • get tls key.pem file path *
  • @return

func (*LeafveinServer) TLSPort

func (lv *LeafveinServer) TLSPort() int

*

  • get tls run port *
  • @return

func (*LeafveinServer) TemplateDir

func (lv *LeafveinServer) TemplateDir() string

*

  • template directory, primary storage template file
  • OperatingDir() created under the directory *
  • ../sample(AppName)/template

func (*LeafveinServer) TemplateSuffix

func (lv *LeafveinServer) TemplateSuffix() string

*

  • get template suffix *
  • @return

func (*LeafveinServer) TestStart

func (lv *LeafveinServer) TestStart() bool

*

  • testing use *
  • @param parse router result

func (*LeafveinServer) UserData

func (lv *LeafveinServer) UserData(key string) string

*

  • user custom config other info *
  • @param key
  • @return

func (*LeafveinServer) WebRootDir

func (lv *LeafveinServer) WebRootDir() string

*

  • web directory, can read and write to the directory
  • primary storage html, css, js, image, zip the file
  • OperatingDir() created under the directory *
  • ../sample(AppName)/webRoot

type Redirect

type Redirect struct {
	URLPath string
	Code    HttpStatus
}

redirect url

func BodyRedirect

func BodyRedirect(url string) Redirect

*

  • redirect url *
  • status code default 302 *
  • @param url
  • @return Redirect

func BodyRedirectByStatusCode

func BodyRedirectByStatusCode(url string, code HttpStatus) Redirect

*

  • redirect url by status code *
  • @param url
  • @param code
  • @return Redirect

type RouterElement

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

router element

type RouterOption

type RouterOption struct {
	RouterData       interface{}   // custom storage data
	RouterDataRefVal reflect.Value // reflect value data

	RouterKey     string //
	RouterPath    string // have been converted to lowercase
	RequestMethod string // lowercase get post ...
	UrlSuffix     string // lowercase

	AppName string // application name
}

router option

type ServeFilePath

type ServeFilePath string

body out file to path

func BodyServeFile

func BodyServeFile(path string) ServeFilePath

*

  • out file *
  • @param parh WebRootDir() path start
  • @return ServeFilePath

type ServerOption

type ServerOption struct {
	//  ip access 	"127.0.0.1" localhost access
	// 	all address access
	//  "192.168.?.?" 	specify access
	//	default "127.0.0.1"
	Addr string

	Port       int    // ip port. default 8080
	SMGCTime   int64  // session manager gc operate time. 0 is not run session, minimum 60 second. default 300
	ConfigPath string // relative or absolute path, relative path from execute file root directory, can set empty. default ""
}

*

  • Leafvein Server option *
  • use DefaultOption() see default value

func DefaultOption

func DefaultOption() ServerOption

*

  • default server option value

func (*ServerOption) Checked

func (s *ServerOption) Checked()

*

  • checked params

func (ServerOption) SetAddr

func (s ServerOption) SetAddr(addr string) ServerOption

*

  • set addr

func (ServerOption) SetConfigPath

func (s ServerOption) SetConfigPath(path string) ServerOption

*

  • set config file path

func (ServerOption) SetPort

func (s ServerOption) SetPort(port int) ServerOption

*

  • set port

func (ServerOption) SetSMGCTime

func (s ServerOption) SetSMGCTime(second int64) ServerOption

*

  • set session manager operate gc

type URIScheme

type URIScheme int

uri scheme

func (URIScheme) String

func (u URIScheme) String() string

*

  • scheme string *
  • @return string tag

Directories

Path Synopsis
example
reflect router RESTful router
reflect router RESTful router
leafveingo web http session 的封装 功能简介: session高并发获取 自动清除session session id 可选随机数生成或IPUUID 自动统计session生成数量、删除数量和有效数量 session token
leafveingo web http session 的封装 功能简介: session高并发获取 自动清除session session id 可选随机数生成或IPUUID 自动统计session生成数量、删除数量和有效数量 session token
leafveingo web 模板操作模块 leafveingo web 模板使用函数模块
leafveingo web 模板操作模块 leafveingo web 模板使用函数模块

Jump to

Keyboard shortcuts

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