xweb

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2014 License: MIT Imports: 42 Imported by: 0

README

xweb

xweb是一个强大的Go语言web框架。

English

Build Status Go Walker Bitdeli Badge

技术支持

QQ群:369240307

更新日志

  • v0.2.1 : 自动Binding新增对jquery对象,map和array的支持。
  • v0.2 : 新增 validation 子包,从 https://github.com/astaxie/beego/tree/master/validation 拷贝过来。
  • v0.1.2 : 采用 github.com/go-xweb/httpsession 作为session组件,API保持兼容;Action现在必须从*Action继承,这个改变与以前的版本不兼容,必须更改代码;新增两个模板函数{{session "key"}} 和 {{cookie "key"}};Action新增函数MapForm
  • v0.1.1 : App新增AutoAction方法;Action新增AddTmplVar方法;Render方法的模版渲染方法中可以通过T混合传入函数和变量,更新了快速入门
  • v0.1.0 : 初始版本

特性

  • 在一个可执行程序中多Server(http,tls,scgi,fcgi),多App的支持
  • 简单好用的路由映射方式
  • 静态文件及版本支持,并支持自动加载,默认开启
  • 改进的模版支持,并支持自动加载,动态新增模板函数
  • session支持
  • validation支持

安装

在安装之前确认你已经安装了Go语言. Go语言安装请访问 install instructions.

安装 xweb:

go get github.com/go-xweb/xweb

Examples

请访问 examples folder

案例

文档

快速入门

源码文档请访问 GoWalker

License

BSD License http://creativecommons.org/licenses/BSD/

Documentation

Overview

Package xweb is a simple and powerful web framework for Go.

Installation

Make sure you have installed Go 1.1+ and then:

go get github.com/go-xweb/xweb

More usage, please visit https://github.com/go-xweb/xweb/

*********************** [钩子引擎 (version 0.3)] @author:S.W.H @E-mail:swh@admpub.com @update:2014-01-18 ***********************

Package web is a lightweight web framework for Go. It's ideal for writing simple, performant backend web services.

Index

Constants

View Source
const (
	Debug = iota + 1
	Product
)
View Source
const (
	Version = "0.2.1"
)
View Source
const (
	XSRF_TAG string = "_xsrf"
)

Variables

View Source
var ServerNumber uint = 0

Functions

func Abort

func Abort(code int, content ...string) error

func Add

func Add(left interface{}, right interface{}) interface{}

func AddAction

func AddAction(c ...interface{})

func AddApp

func AddApp(a *App)

func AddConfig

func AddConfig(name string, value interface{})

func AddFilter

func AddFilter(filter Filter)

func AddHook

func AddHook(name string, fns ...interface{})

func AddRouter

func AddRouter(url string, c interface{})

func AddTmplVar

func AddTmplVar(name string, varOrFun interface{})

func AddTmplVars

func AddTmplVars(t *T)

func AutoAction

func AutoAction(c ...interface{})

func AvgTime

func AvgTime(items []time.Duration) time.Duration

func Close

func Close()

Close stops the main server.

func CloseZWriter

func CloseZWriter(zwriter io.Writer)

CloseZWriter closes the io.Writer after compressing static file.

func Download

func Download(w http.ResponseWriter, fpath string) error

func Eq

func Eq(left interface{}, right interface{}) bool

func Error

func Error(w http.ResponseWriter, status int, content string) error

func Forbidden

func Forbidden(content ...string) error

func FormatDate

func FormatDate(t time.Time, format string) string

func FriendlyBytes

func FriendlyBytes(bytes uint64) string

format bytes number friendly

func FriendlyTime

func FriendlyTime(d time.Duration) string

short string format

func GetAcceptEncodingZip

func GetAcceptEncodingZip(r *http.Request) string

GetAcceptEncodingZip returns accept encoding format in http header. zip is first, then deflate if both accepted. If no accepted, return empty string.

func Html

func Html(raw string) template.HTML

func InternalServerError

func InternalServerError(content ...string) error

func IsNil

func IsNil(a interface{}) bool

func JoinPath

func JoinPath(paths ...string) string

func Js

func Js(raw string) template.JS

func NewCookie

func NewCookie(name string, value string, age int64) *http.Cookie

NewCookie is a helper method that returns a new http.Cookie object. Duration is specified in seconds. If the duration is zero, the cookie is permanent. This can be used in conjunction with ctx.SetCookie.

func NotFound

func NotFound(content ...string) error

func NotSupported

func NotSupported(content ...string) error

func Now

func Now() time.Time

func PageSize

func PageSize(total, limit int) int

func PrintGCSummary

func PrintGCSummary(w io.Writer)

print gc information to io.Writer

func Process

func Process(c http.ResponseWriter, req *http.Request)

Process invokes the main server's routing system.

func Run

func Run(addr string)

Run starts the web application and serves HTTP requests for the main server.

func RunFcgi

func RunFcgi(addr string)

RunFcgi starts the web application and serves FastCGI requests for the main server.

func RunScgi

func RunScgi(addr string)

RunScgi starts the web application and serves SCGI requests for the main server.

func RunTLS

func RunTLS(addr string, config *tls.Config)

RunTLS starts the web application and serves HTTPS requests for the main server.

func SetLogger

func SetLogger(logger *log.Logger)

SetLogger sets the logger for the main server.

func SetStaticDir

func SetStaticDir(dir string)

func SetTemplateDir

func SetTemplateDir(dir string)

func SimpleParse

func SimpleParse(data string) map[string]string

func SimpleTLSConfig

func SimpleTLSConfig(certFile, keyFile string) (*tls.Config, error)

func Slug

func Slug(s string, sep string) string

Slug is a helper function that returns the URL slug for string s. It's used to return clean, URL-friendly strings that can be used in routing.

func SplitJson

func SplitJson(s string) ([]string, error)

user[name][test]

func StartCPUProfile

func StartCPUProfile()

start cpu profile monitor

func StopCPUProfile

func StopCPUProfile()

stop cpu profile monitor

func Subtract

func Subtract(left interface{}, right interface{}) interface{}

func Ternary

func Ternary(express bool, trueVal interface{}, falseVal interface{}) interface{}

the func is the same as condition ? true : false

func UnTitle

func UnTitle(s string) string

func Unauthorized

func Unauthorized(content ...string) error

func UrlFor

func UrlFor(args ...string) string

Usage:UrlFor("main:root:/user/login") or UrlFor("root:/user/login") or UrlFor("/user/login") or UrlFor()

func Urlencode

func Urlencode(data map[string]string) string

Urlencode is a helper method that converts a map into URL-encoded form data. It is a useful when constructing HTTP POST requests.

func XsrfName

func XsrfName() string

Types

type AbortError

type AbortError struct {
	Code    int
	Content string
}

func (*AbortError) Error

func (a *AbortError) Error() string

type Action

type Action struct {
	Request *http.Request
	App     *App
	Option  *ActionOption
	http.ResponseWriter
	C reflect.Value

	T T

	RootTemplate *template.Template
	RequestBody  []byte
	StatusCode   int
	// contains filtered or unexported fields
}

An Action object or it's substruct is created for every incoming HTTP request. It provides information about the request, including the http.Request object, the GET and POST params, and acts as a Writer for the response.

func (*Action) Abort

func (c *Action) Abort(status int, body string) error

Abort is a helper method that sends an HTTP header and an optional body. It is useful for returning 4xx or 5xx errors. Once it has been called, any return value from the handler will not be written to the response.

func (*Action) AddTmplVar

func (c *Action) AddTmplVar(name string, varOrFunc interface{})

add a name value for template

func (*Action) AddTmplVars

func (c *Action) AddTmplVars(t *T)

add names and values for template

func (*Action) BasePath

func (c *Action) BasePath() string

func (*Action) Body

func (c *Action) Body() []byte

Body returns the raw request body data as bytes.

func (*Action) Cookie

func (c *Action) Cookie(key string) string

Cookie returns request cookie item string by a given key. if non-existed, return empty string.

func (*Action) Debug

func (c *Action) Debug(params ...interface{})

func (*Action) Debugf

func (c *Action) Debugf(format string, params ...interface{})

func (*Action) DelSession

func (c *Action) DelSession(key string)

func (*Action) DisableHttpCache

func (c *Action) DisableHttpCache()

func (*Action) Domain

func (c *Action) Domain() string

Domain returns host name. Alias of Host method.

func (*Action) Error

func (c *Action) Error(params ...interface{})

func (*Action) Errorf

func (c *Action) Errorf(format string, params ...interface{})

func (*Action) Fatal

func (c *Action) Fatal(params ...interface{})

func (*Action) Fatalf

func (c *Action) Fatalf(format string, params ...interface{})

func (*Action) Flush

func (c *Action) Flush()

func (*Action) GetBool

func (c *Action) GetBool(key string) (bool, error)

func (*Action) GetConfig

func (c *Action) GetConfig(name string) interface{}

func (*Action) GetCookie

func (c *Action) GetCookie(cookieName string) (*http.Cookie, error)

func (*Action) GetFile

func (c *Action) GetFile(key string) (multipart.File, *multipart.FileHeader, error)

func (*Action) GetFloat

func (c *Action) GetFloat(key string) (float64, error)

func (*Action) GetForm

func (c *Action) GetForm() url.Values

func (*Action) GetFuncs

func (c *Action) GetFuncs() template.FuncMap

func (*Action) GetInt

func (c *Action) GetInt(key string) (int64, error)

func (*Action) GetLogger

func (c *Action) GetLogger() *log.Logger

func (*Action) GetSecureCookie

func (c *Action) GetSecureCookie(name string) (string, bool)

func (*Action) GetSession

func (c *Action) GetSession(key string) interface{}

func (*Action) GetSlice

func (c *Action) GetSlice(key string) []string

func (*Action) GetString

func (c *Action) GetString(key string) string

func (*Action) Go

func (c *Action) Go(m string, anotherc ...interface{}) error

func (*Action) Header

func (c *Action) Header(key string) string

Header returns request header item string by a given string.

func (*Action) Host

func (c *Action) Host() string

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

func (*Action) HttpCache

func (c *Action) HttpCache(content []byte) bool

func (*Action) IP

func (c *Action) IP() string

IP returns request client ip. if in proxy, return first proxy id. if error, return 127.0.0.1.

func (*Action) Include

func (c *Action) Include(tmplName string) interface{}

Include method provide to template for {{include "xx.tmpl"}}

func (*Action) Info

func (c *Action) Info(params ...interface{})

func (*Action) Infof

func (c *Action) Infof(format string, params ...interface{})

func (*Action) Is

func (c *Action) Is(method string) bool

Is returns boolean of this request is on given method, such as Is("POST").

func (*Action) IsAjax

func (c *Action) IsAjax() bool

IsAjax returns boolean of this request is generated by ajax.

func (*Action) IsSecure

func (c *Action) IsSecure() bool

IsSecure returns boolean of this request is in https.

func (*Action) IsUpload

func (c *Action) IsUpload() bool

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

func (*Action) IsWebsocket

func (c *Action) IsWebsocket() bool

IsSecure returns boolean of this request is in webSocket.

func (*Action) MapForm

func (c *Action) MapForm(st 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 := action.MapForm(&user)

func (*Action) Method

func (c *Action) Method() string

func (*Action) NamedRender

func (c *Action) NamedRender(name, content string, params ...*T) error

render the template with vars map, you can have zero or one map

func (*Action) Namespace

func (c *Action) Namespace() string

func (*Action) NotFound

func (c *Action) NotFound(message string) error

NotFound writes a 404 HTTP response

func (*Action) NotModified

func (c *Action) NotModified()

Notmodified writes a 304 HTTP response

func (*Action) Panic

func (c *Action) Panic(params ...interface{})

func (*Action) Panicf

func (c *Action) Panicf(format string, params ...interface{})

func (*Action) Port

func (c *Action) Port() int

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

func (*Action) Protocol

func (c *Action) Protocol() string

[SWH|+]: Protocol returns request protocol name, such as HTTP/1.1 .

func (*Action) Proxy

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

Proxy returns proxy client ips slice.

func (*Action) Query

func (c *Action) Query(key string) string

Query returns input data item string by a given string.

func (*Action) Redirect

func (c *Action) Redirect(url string, status ...int) error

Redirect is a helper method for 3xx redirects.

func (*Action) Refer

func (c *Action) Refer() string

Refer returns http referer header.

func (*Action) Render

func (c *Action) Render(tmpl string, params ...*T) error

render the template with vars map, you can have zero or one map

func (*Action) RenderString

func (c *Action) RenderString(content string, params ...*T) error

func (*Action) SaveToFile

func (c *Action) SaveToFile(fromfile, tofile string) error

func (*Action) Scheme

func (c *Action) Scheme() string

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

func (*Action) ServeFile

func (c *Action) ServeFile(fpath string)

func (*Action) ServeJson

func (c *Action) ServeJson(obj interface{})

func (*Action) ServeXml

func (c *Action) ServeXml(obj interface{})

func (*Action) Session

func (c *Action) Session() *httpsession.Session

func (*Action) SetBody

func (c *Action) SetBody(content []byte) error

Body sets response body content. if EnableGzip, compress content string. it sends out response body directly.

func (*Action) SetConfig

func (c *Action) SetConfig(name string, value interface{})

func (*Action) SetContentType

func (c *Action) SetContentType(val string) string

ContentType sets the Content-Type header for an HTTP response. For example, c.ContentType("json") sets the content-type to "application/json" If the supplied value contains a slash (/) it is set as the Content-Type verbatim. The return value is the content type as it was set, or an empty string if none was found.

func (*Action) SetCookie

func (c *Action) SetCookie(cookie *http.Cookie)

SetCookie adds a cookie header to the response.

func (*Action) SetHeader

func (c *Action) SetHeader(key string, value string)

SetHeader sets a response header. the current value of that header will be overwritten .

func (*Action) SetSecureCookie

func (c *Action) SetSecureCookie(name string, val string, age int64)

func (*Action) SetSession

func (c *Action) SetSession(key string, value interface{})

func (*Action) Site

func (c *Action) Site() string

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

func (*Action) SubDomains

func (c *Action) SubDomains() string

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

func (*Action) Uri

func (c *Action) Uri() string

Uri returns full request url with query string, fragment.

func (*Action) Url

func (c *Action) Url() string

Url returns request url path (without query string, fragment).

func (*Action) UserAgent

func (c *Action) UserAgent() string

UserAgent returns request client user agent string.

func (*Action) Warn

func (c *Action) Warn(params ...interface{})

func (*Action) Warnf

func (c *Action) Warnf(format string, params ...interface{})

func (*Action) Write

func (c *Action) Write(content string, values ...interface{}) error

func (*Action) WriteBytes

func (c *Action) WriteBytes(bytes []byte) error

WriteString writes string data into the response object.

func (*Action) XsrfFormHtml

func (c *Action) XsrfFormHtml() template.HTML

func (*Action) XsrfValue

func (c *Action) XsrfValue() string

type ActionOption

type ActionOption struct {
	AutoMapForm bool
	CheckXsrf   bool
}

type App

type App struct {
	BasePath string
	Name     string //[SWH|+]
	Routes   []Route
	RoutesEq map[string]map[string]Route

	Server          *Server
	AppConfig       *AppConfig
	Config          map[string]interface{}
	Actions         map[string]interface{}
	ActionsPath     map[reflect.Type]string
	ActionsNamePath map[string]string
	FuncMaps        template.FuncMap
	Logger          *log.Logger
	VarMaps         T
	SessionManager  *httpsession.Manager //Session manager
	RootTemplate    *template.Template
	ErrorTemplate   *template.Template
	StaticVerMgr    *StaticVerMgr
	TemplateMgr     *TemplateMgr
	ContentEncoding string
	// contains filtered or unexported fields
}

func NewApp

func NewApp(args ...string) *App

func RootApp

func RootApp() *App

func (*App) Action

func (app *App) Action(name string) interface{}

func (*App) AddAction

func (app *App) AddAction(cs ...interface{})

func (*App) AddFilter

func (app *App) AddFilter(filter Filter)

func (*App) AddRouter

func (app *App) AddRouter(url string, c interface{})

func (*App) AddTmplVar

func (app *App) AddTmplVar(name string, varOrFun interface{})

func (*App) AddTmplVars

func (app *App) AddTmplVars(t *T)

func (*App) AutoAction

func (app *App) AutoAction(cs ...interface{})

func (*App) Debug

func (app *App) Debug(params ...interface{})

func (*App) Debugf

func (app *App) Debugf(format string, params ...interface{})

func (*App) Error

func (app *App) Error(params ...interface{})

func (*App) Errorf

func (app *App) Errorf(format string, params ...interface{})

func (*App) Fatal

func (app *App) Fatal(params ...interface{})

func (*App) Fatalf

func (app *App) Fatalf(format string, params ...interface{})

func (*App) GetConfig

func (app *App) GetConfig(name string) interface{}

func (*App) Info

func (app *App) Info(params ...interface{})

func (*App) Infof

func (app *App) Infof(format string, params ...interface{})

func (*App) InitHeadContent

func (a *App) InitHeadContent(w http.ResponseWriter, contentLength int64)

Init content-length header.

func (*App) Nodes

func (app *App) Nodes() (r map[string]map[string][]string)

example:

{
	"AdminAction":{
		"Index":["GET","POST"],
		"Add":	["GET","POST"],
		"Edit":	["GET","POST"]
	}
}

func (*App) Panic

func (app *App) Panic(params ...interface{})

func (*App) Panicf

func (app *App) Panicf(format string, params ...interface{})

func (*App) Redirect

func (app *App) Redirect(w http.ResponseWriter, requestPath, url string, status ...int) error

func (*App) SafelyCall

func (a *App) SafelyCall(vc reflect.Value, method string, args []reflect.Value) (resp []reflect.Value, err error)

safelyCall invokes `function` in recover block

func (*App) SetConfig

func (app *App) SetConfig(name string, val interface{})

func (*App) SetStaticDir

func (a *App) SetStaticDir(dir string)

func (*App) SetTemplateDir

func (a *App) SetTemplateDir(path string)

func (*App) StaticUrl

func (a *App) StaticUrl(url string) string

func (*App) StructMap

func (a *App) StructMap(vc reflect.Value, r *http.Request) error

StructMap function mapping params to controller's properties

func (*App) TryServingFile

func (a *App) TryServingFile(name string, req *http.Request, w http.ResponseWriter) bool

tryServingFile attempts to serve a static file, and returns whether or not the operation is successful.

func (*App) Warn

func (app *App) Warn(params ...interface{})

func (*App) Warnf

func (app *App) Warnf(format string, params ...interface{})

type AppConfig

type AppConfig struct {
	Mode              int
	StaticDir         string
	TemplateDir       string
	SessionOn         bool
	MaxUploadSize     int64
	CookieSecret      string
	StaticFileVersion bool
	CacheTemplates    bool
	ReloadTemplates   bool
	CheckXsrf         bool
	SessionTimeout    time.Duration
	FormMapToStruct   bool //[SWH|+]
	EnableHttpCache   bool //[SWH|+]
}

type Filter

type Filter interface {
	Do(http.ResponseWriter, *http.Request) bool
}

type FromConversion

type FromConversion interface {
	FromString(content string) error
}

a struct implements this interface can be convert from request param to a struct

type Hook

type Hook []reflect.Value

type HookEngine

type HookEngine struct {
	Hooks map[string]Hook
	Index map[string]uint
	// contains filtered or unexported fields
}
var (
	ErrParamsNotAdapted             = errors.New("The number of params is not adapted.")
	XHook               *HookEngine = NewHookEngine(10)
)

func NewHookEngine

func NewHookEngine(size int) *HookEngine

func (*HookEngine) Bind

func (f *HookEngine) Bind(name string, fns ...interface{}) (err error)

func (*HookEngine) Call

func (f *HookEngine) Call(name string, params ...interface{}) (result []reflect.Value, err error)

func (*HookEngine) String

func (f *HookEngine) String(c reflect.Value) string

func (*HookEngine) Value

func (f *HookEngine) Value(c []reflect.Value, index int) (r interface{})

type LoginFilter

type LoginFilter struct {
	App           *App
	SessionName   string
	AnonymousUrls []*regexp.Regexp
	AskLoginUrls  []*regexp.Regexp
	Redirect      string
	OriUrlName    string
}

func NewLoginFilter

func NewLoginFilter(app *App, name string, redirect string) *LoginFilter

func (*LoginFilter) AddAnonymousUrls

func (s *LoginFilter) AddAnonymousUrls(urls ...string)

func (*LoginFilter) AddAskLoginUrls

func (s *LoginFilter) AddAskLoginUrls(urls ...string)

func (*LoginFilter) Do

type Mapper

type Mapper struct {
}

type MemFile

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

MemFile contains MemFileInfo and bytes offset when reading. it implements io.Reader,io.ReadCloser and io.Seeker.

func OpenMemZipFile

func OpenMemZipFile(path string, zip string) (*MemFile, error)

OpenMemZipFile returns MemFile object with a compressed static file. it's used for serve static file if gzip enable.

func (*MemFile) Close

func (f *MemFile) Close() error

Close memfile.

func (*MemFile) Read

func (f *MemFile) Read(p []byte) (n int, err error)

Read bytes from the compressed file bytes.

func (*MemFile) Readdir

func (f *MemFile) Readdir(count int) ([]os.FileInfo, error)

read os.FileInfo of files in directory of memfile. it returns empty slice.

func (*MemFile) Seek

func (f *MemFile) Seek(offset int64, whence int) (ret int64, err error)

Read bytes from the compressed file bytes by seeker.

func (*MemFile) Stat

func (f *MemFile) Stat() (os.FileInfo, error)

Get os.FileInfo of memfile.

type MemFileInfo

type MemFileInfo struct {
	os.FileInfo
	// contains filtered or unexported fields
}

MemFileInfo contains a compressed file bytes and file information. it implements os.FileInfo interface.

func (*MemFileInfo) IsDir

func (fi *MemFileInfo) IsDir() bool

IsDir returns the compressing file is a directory or not.

func (*MemFileInfo) ModTime

func (fi *MemFileInfo) ModTime() time.Time

ModTime returns the last modified time of raw file.

func (*MemFileInfo) Mode

func (fi *MemFileInfo) Mode() os.FileMode

Mode returns file mode.

func (*MemFileInfo) Name

func (fi *MemFileInfo) Name() string

Name returns the compressed filename.

func (*MemFileInfo) Size

func (fi *MemFileInfo) Size() int64

Size returns the raw file content size, not compressed size.

func (*MemFileInfo) Sys

func (fi *MemFileInfo) Sys() interface{}

return nil. implement the os.FileInfo interface method.

type Route

type Route struct {
	Path           string          //path string
	CompiledRegexp *regexp.Regexp  //path regexp
	HttpMethods    map[string]bool //GET POST HEAD DELETE etc.
	HandlerMethod  string          //struct method name
	HandlerElement reflect.Type    //handler element
}

type Server

type Server struct {
	Config         *ServerConfig
	Apps           map[string]*App
	AppsNamePath   map[string]string
	Name           string
	SessionManager *httpsession.Manager
	RootApp        *App
	Logger         *log.Logger
	Env            map[string]interface{}
	// contains filtered or unexported fields
}

Server represents a xweb server.

func MainServer

func MainServer() *Server

func NewServer

func NewServer(args ...string) *Server

func Serv

func Serv(name string) *Server

func (*Server) AddAction

func (s *Server) AddAction(cs ...interface{})

func (*Server) AddApp

func (s *Server) AddApp(a *App)

func (*Server) AddConfig

func (s *Server) AddConfig(name string, value interface{})

func (*Server) AddFilter

func (s *Server) AddFilter(filter Filter)

func (*Server) AddRouter

func (s *Server) AddRouter(url string, c interface{})

func (*Server) AddTmplVar

func (s *Server) AddTmplVar(name string, varOrFun interface{})

func (*Server) AddTmplVars

func (s *Server) AddTmplVars(t *T)

func (*Server) App

func (s *Server) App(name string) *App

func (*Server) AutoAction

func (s *Server) AutoAction(c ...interface{})

func (*Server) Close

func (s *Server) Close()

Close stops server s.

func (*Server) GetConfig

func (s *Server) GetConfig(name string) interface{}

func (*Server) InitSession

func (s *Server) InitSession()

func (*Server) Process

func (s *Server) Process(w http.ResponseWriter, req *http.Request)

Process invokes the routing system for server s non-root app's route will override root app's if there is same path

func (*Server) Run

func (s *Server) Run(addr string)

Run starts the web application and serves HTTP requests for s

func (*Server) RunFcgi

func (s *Server) RunFcgi(addr string)

RunFcgi starts the web application and serves FastCGI requests for s.

func (*Server) RunScgi

func (s *Server) RunScgi(addr string)

RunScgi starts the web application and serves SCGI requests for s.

func (*Server) RunTLS

func (s *Server) RunTLS(addr string, config *tls.Config) error

RunTLS starts the web application and serves HTTPS requests for s.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(c http.ResponseWriter, req *http.Request)

ServeHTTP is the interface method for Go's http server package

func (*Server) SetConfig

func (s *Server) SetConfig(name string, value interface{})

func (*Server) SetLogger

func (s *Server) SetLogger(logger *log.Logger)

SetLogger sets the logger for server s

func (*Server) SetStaticDir

func (s *Server) SetStaticDir(path string)

func (*Server) SetTemplateDir

func (s *Server) SetTemplateDir(path string)

type ServerConfig

type ServerConfig struct {
	Addr                   string
	Port                   int
	RecoverPanic           bool
	Profiler               bool
	EnableGzip             bool
	StaticExtensionsToGzip []string
	Url                    string
	UrlPrefix              string
	UrlSuffix              string
	StaticHtmlDir          string
	SessionTimeout         time.Duration
}

ServerConfig is configuration for server objects.

var (
	Config *ServerConfig = &ServerConfig{
		RecoverPanic: true,
		EnableGzip:   true,

		StaticExtensionsToGzip: []string{".css", ".js"},
	}
	Servers map[string]*Server = make(map[string]*Server) //[SWH|+]

)

Config is the configuration of the main server.

type StaticVerMgr

type StaticVerMgr struct {
	Caches map[string]string

	Path    string
	Ignores map[string]bool
	// contains filtered or unexported fields
}

func (*StaticVerMgr) CacheAll

func (self *StaticVerMgr) CacheAll(staticPath string) error

func (*StaticVerMgr) CacheDelete

func (self *StaticVerMgr) CacheDelete(url string)

func (*StaticVerMgr) CacheItem

func (self *StaticVerMgr) CacheItem(url string)

func (*StaticVerMgr) GetVersion

func (self *StaticVerMgr) GetVersion(url string) string

func (*StaticVerMgr) Init

func (self *StaticVerMgr) Init(app *App, staticPath string) error

func (*StaticVerMgr) Moniter

func (self *StaticVerMgr) Moniter(staticPath string) error

type T

type T map[string]interface{}

type TemplateMgr

type TemplateMgr struct {
	Caches map[string][]byte

	RootDir  string
	Ignores  map[string]bool
	IsReload bool

	Preprocessor func([]byte) []byte
	// contains filtered or unexported fields
}

func (*TemplateMgr) CacheAll

func (self *TemplateMgr) CacheAll(rootDir string) error

func (*TemplateMgr) CacheDelete

func (self *TemplateMgr) CacheDelete(tmpl string)

func (*TemplateMgr) CacheTemplate

func (self *TemplateMgr) CacheTemplate(tmpl string, content []byte)

func (*TemplateMgr) GetTemplate

func (self *TemplateMgr) GetTemplate(tmpl string) ([]byte, error)

func (*TemplateMgr) Init

func (self *TemplateMgr) Init(app *App, rootDir string, reload bool) error

func (*TemplateMgr) Moniter

func (self *TemplateMgr) Moniter(rootDir string) error

type ToConversion

type ToConversion interface {
	ToString() string
}

a struct implements this interface can be convert from struct to template variable Not Implemented

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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