xweb

package module
v0.1.2-0...-24de50e Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2014 License: MIT Imports: 41 Imported by: 0

README

xweb

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

English

Build Status Go Walker Bitdeli Badge

技术支持

QQ群:369240307

更新日志

  • v0.2 : 新增 validation 子包,从 https://github.com/astaxie/beego/tree/master/validation 拷贝过来。
  • v0.1.2 : 采用 github.com/lunny/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/lunny/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/lunny/xweb

More usage, please visit https://github.com/lunny/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 (
	ForeBlack  = iota + 30 //30         40         黑色
	ForeRed                //31         41         紅色
	ForeGreen              //32         42         綠色
	ForeYellow             //33         43         黃色
	ForeBlue               //34         44         藍色
	ForePurple             //35         45         紫紅色
	ForeCyan               //36         46         青藍色
	ForeWhite              //37         47         白色
)
View Source
const (
	LevelTrace = iota + 1
	LevelDebug
	LevelInfo
	LevelWarn
	LevelError
	LevelCritical
)
View Source
const (
	Version = "0.2"
)
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 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 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) Critical

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

func (*Action) Debug

func (c *Action) Debug(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(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(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) 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) 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) 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) Trace

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

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(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
	CheckXrsf   bool
}

type App

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

	Server          *Server
	AppConfig       *AppConfig
	Config          map[string]interface{}
	Actions         map[reflect.Type]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) 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) Critical

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

func (*App) Debug

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

func (*App) Error

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

func (*App) GetConfig

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

func (*App) Info

func (app *App) Info(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][]string)

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) Trace

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

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(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
	CheckXrsf         bool
	SessionTimeout    int64
	FormMapToStruct   bool //[SWH|+]
	EnableHttpCache   bool //[SWH|+]

	//[SWH|+] On/Off Log
	EnableTraceLog    bool
	EnableDebugLog    bool
	EnableInfoLog     bool
	EnableWarnLog     bool
	EnableErrorLog    bool
	EnableCriticalLog bool
}

type AutoResponse

type AutoResponse struct {
}

func (*AutoResponse) Do

func (s *AutoResponse) Do(c *Action, ret []reflect.Value) error

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
}
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 JSONResponse

type JSONResponse struct {
}

func (*JSONResponse) Do

func (j *JSONResponse) Do(c *Action, ret []reflect.Value) error

type LoginFilter

type LoginFilter struct {
	App           *App
	SessionName   string
	AnonymousUrls []*regexp.Regexp
	AskLoginUrls  []*regexp.Regexp
	Redirect      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 Response

type Response interface {
	Do(ret []reflect.Value)
}

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
	AppName map[string]string //[SWH|+]
	Name    string            //[SWH|+]
	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) Critical

func (s *Server) Critical(format string, params ...interface{})

func (*Server) Debug

func (s *Server) Debug(format string, params ...interface{})

func (*Server) Error

func (s *Server) Error(format string, params ...interface{})

func (*Server) Info

func (s *Server) Info(format string, params ...interface{})

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) 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)

func (*Server) Trace

func (s *Server) Trace(format string, params ...interface{})

func (*Server) Warn

func (s *Server) Warn(format string, params ...interface{})

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
}

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) 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
	// 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

type XMLResponse

type XMLResponse struct {
}

func (*XMLResponse) Do

func (x *XMLResponse) Do(c *Action, ret []reflect.Value) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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