Documentation ¶
Index ¶
- Constants
- Variables
- func Filter(pattern string, f func(*Context))
- func Handle404(f func(http.ResponseWriter, *http.Request))
- func HandleGet(pattern string, f func(*Context))
- func HandleGetPost(pattern string, f func(*Context))
- func HandleMethod(pattern string, f func(*Context), method string)
- func HandlePost(pattern string, f func(*Context))
- func ParseTemplateFiles(templateFunc map[string]interface{}, filenames ...string) (*template.Template, error)
- func Run()
- func Set404View(viewPath string)
- type Context
- func (ctx *Context) AddResponseHeader(key string, value string)
- func (ctx *Context) Cleanup()
- func (ctx *Context) ClearSession()
- func (ctx *Context) DeleteCookie(key string)
- func (ctx *Context) Get(key string) (interface{}, bool)
- func (ctx *Context) GetBool(key string) (bool, bool)
- func (ctx *Context) GetBrowserAgent() string
- func (ctx *Context) GetCookie(key string) string
- func (ctx *Context) GetInt(key string) (int, bool)
- func (ctx *Context) GetRequestForwardedIP() string
- func (ctx *Context) GetRequestIP() string
- func (ctx *Context) GetSessionFlash(key string) interface{}
- func (ctx *Context) GetString(key string) (string, bool)
- func (ctx *Context) GetUploadFile(inputName string) (*FormFile, error)
- func (ctx *Context) LoadCache(key string, object interface{}) error
- func (ctx *Context) NewSession()
- func (ctx *Context) Redirect(path string)
- func (ctx *Context) RedirectPermanently(path string)
- func (ctx *Context) SaveCache(key string, object interface{}, secondTimeout int) error
- func (ctx *Context) ServeStaticFile(filePath string, isAttachment bool)
- func (ctx *Context) Set(key string, value interface{})
- func (ctx *Context) SetCookie(key string, value string)
- func (ctx *Context) SetPersistentCookie(key string, value string, duration time.Duration)
- func (ctx *Context) SetSessionFlash(key string, value interface{})
- func (ctx *Context) Write(data []byte) (int, error)
- func (ctx *Context) WriteHttpStatus(httpStatus int)
- func (ctx *Context) WriteS(output string)
- func (ctx *Context) Writef(format string, content ...interface{})
- type Form
- func (this *Form) Array(key string) []string
- func (this *Form) ArrayNoEscape(key string) []string
- func (this *Form) Bool(key string) bool
- func (this *Form) Exist(key string) bool
- func (this *Form) File(key string) *FormFile
- func (this *Form) Float32(key string) float32
- func (this *Form) Float64(key string) float64
- func (this *Form) Int(key string) int
- func (this *Form) Int32(key string) int32
- func (this *Form) Int64(key string) int64
- func (this *Form) IsArray(key string) bool
- func (this *Form) ReadStruct(obj interface{})
- func (this *Form) String(key string) string
- func (this *Form) StringNoEscape(key string) string
- type FormFile
- type NullCloseWriter
Constants ¶
View Source
const ( CFG_KEY_SERVER_STATIC_DIR = "Server.StaticDir" CFG_KEY_SERVER_STATIC_MAX_CACHE_FZ = "Server.StaticMaxCacheFileSize" CFG_KEY_SERVER_VIEW_DIR = "Server.ViewDir" CFG_KEY_SERVER_STATIC_WEB_PATH = "Server.StaticWebPath" CFG_KEY_SERVER_ADDR = "Server.Addr" CFG_KEY_SERVER_READ_TIMEOUT = "Server.ReadTimeout" CFG_KEY_SERVER_WRITE_TIMEOUT = "Server.WriteTimeout" CFG_KEY_SERVER_MAX_HEADER_BYTES = "Server.MaxHeaderBytes" CFG_KEY_SERVER_MAX_CONTENT_LENGTH = "Server.MaxContentLength" CFG_KEY_COOKIE_SECRET = "Server.CookieSecret" CFG_KEY_SESSION_STORE_DIR = "Server.SessionStoreDir" CFG_KEY_CACHE_STORE_DIR = "Server.CacheStoreDir" CFG_KEY_SERVER_ENABLE_HTTP = "Server.EnableHttp" CFG_KEY_SERVER_ENABLE_HTTPS = "Server.EnableHttps" CFG_KEY_SERVER_ADDR_HTTPS = "Server.AddrHttps" CFG_KEY_SERVER_CERT_FILE = "Server.CertFile" CFG_KEY_SERVER_KEY_FILE = "Server.KeyFile" CFG_KEY_SERVER_ENABLE_GZIP = "Server.EnableGzip" CFG_KEY_SERVER_ENABLE_MINIFY = "Server.EnableMinify" CFG_KEY_SERVER_FORCE_HTTPS = "Server.ForceHttps" CFG_KEY_SERVER_ENABLE_CSRF_PROTECT = "Server.EnableCsrfProtect" CFG_KEY_SERVER_IP_REQUEST_LIMIT = "Server.IPRequestLimit" //Limit request per IP per second (except static file requests), over limit will be reject with "429 Too Many Requests" CFG_KEY_DATABASE_DRIVER = "Database.Driver" CFG_KEY_DATABASE_HOST = "Database.Host" CFG_KEY_DATABASE_PORT = "Database.Port" CFG_KEY_DATABASE_SERVER = "Database.Server" CFG_KEY_DATABASE_USER = "Database.User" CFG_KEY_DATABASE_PWD = "Database.Pwd" CFG_KEY_DATABASE_SCHEMA = "Database.DatabaseName" )
View Source
const ( DEFAULT_HTTP_PORT = ":80" DEFAULT_HTTPS_PORT = ":443" DEFAULT_SERVER_CONFIG_FILE = "./server.cfg" DEFAULT_SERVER_STATIC_DIR = "./static" DEFAULT_SERVER_STATIC_MAX_CACHE_FZ = 512 * 1024 //512KB DEFAULT_SERVER_STATIC_WEB_PATH = "/static" DEFAULT_SERVER_VIEW_DIR = "./view" DEFAULT_SERVER_ADDR = ":8026" DEFAULT_SERVER_ADDR_HTTPS = ":44326" DEFAULT_SERVER_CERT_FILE = "./cert.pem" DEFAULT_SERVER_KEY_FILE = "./key.pem" DEFAULT_SERVER_READ_TIMEOUT = 120 //120s DEFAULT_SERVER_WRITE_TIMEOUT = 120 //120s DEFAULT_SERVER_MAX_HEADER_BYTES = 16 * 1024 //16KB DEFAULT_SERVER_MAX_CONTENT_LENGTH = 10 * 1024 * 1024 //10MB DEFAULT_SERVER_ENABLE_GZIP = true DEFAULT_SERVER_ENABLE_MINIFY = false DEFAULT_SERVER_FORCE_HTTPS = false DEFAULT_SERVER_ENABLE_CSRF_PROTECT = true DEFAULT_SERVER_IP_REQUEST_LIMIT = 100 //100 request per second per IP DEFAULT_COOKIE_SECRET = "COOKIE_SECRET" DEFAULT_SESSION_STORE_DIR = "./session_store" DEFAULT_CACHE_STORE_DIR = "./cache_store" DEFAULT_SERVER_ENABLE_HTTP = true DEFAULT_SERVER_ENABLE_HTTPS = false DEFAULT_SERVER_ENABLE_HTTP2 = true )
View Source
const ( SERVER_SESSION_ID = "session_id" SERVER_SESSION_MAX_LENGTH = 128 * 1024 //128KB SERVER_SESSION_KEEP_DAY = 7 // 1 week METHOD_GET = "GET" METHOD_POST = "POST" )
View Source
const ( MAX_URL_PATH_LENGTH = 2048 MAX_HTTP_METHOD_LENGTH = 7 //method OPTIONS )
View Source
const FORM_TAG = "form"
View Source
const MAX_MULTIPART_MEMORY = 1024 * 1024 * 5
Variables ¶
View Source
var SqlScanStruct = db.SqlScanStruct
deprecated, use db.SqlScanStruct instead
Functions ¶
func Filter ¶
Filter add a filter to request handler, - pattern used wildcard matching with ? and * - all request methods (GET/POST/PUT/HEAD/...) will be applied
func HandleGetPost ¶
func HandleMethod ¶
func HandlePost ¶
func ParseTemplateFiles ¶
func Set404View ¶
func Set404View(viewPath string)
Types ¶
type Context ¶
type Context struct { Config *cfg.Cfg RouteVars map[string]ext.Var FinishFilter bool RedirectPath string RedirectStatus int Session *sessions.Session ViewBases []string View string ViewData map[string]interface{} JsonResponse interface{} UrlPath string Method string IsGetMethod bool IsPostMethod bool IsUsingTSL bool Form Form Host string TemplateFunc map[string]interface{} DB *sql.DB // contains filtered or unexported fields }
func (*Context) AddResponseHeader ¶
func (*Context) ClearSession ¶
func (ctx *Context) ClearSession()
func (*Context) GetBrowserAgent ¶
func (*Context) GetRequestForwardedIP ¶
func (*Context) GetRequestIP ¶
func (*Context) GetSessionFlash ¶
func (*Context) GetUploadFile ¶
func (*Context) NewSession ¶
func (ctx *Context) NewSession()
func (*Context) RedirectPermanently ¶
func (*Context) ServeStaticFile ¶
func (*Context) SetPersistentCookie ¶
Set persistent cookie
func (*Context) SetSessionFlash ¶
func (*Context) WriteHttpStatus ¶
type Form ¶
type Form struct {
// contains filtered or unexported fields
}
func (*Form) ArrayNoEscape ¶
func (*Form) ReadStruct ¶
func (this *Form) ReadStruct(obj interface{})
Read form values and set to a struct Ex:
Call: ctx.Form.ReadStruct(&formABCVar) Struct define: type FormABC struct { FieldA int `form:"this_is_a"` // read from input name="this_is_a" FieldB float `this_is_b` // read from input name="this_is_b" FieldC string // read from input name="FieldC" privateField string // will not read this field ArrayVar [] `list_abc` // read string array from input name="list_abc" }
func (*Form) StringNoEscape ¶
type NullCloseWriter ¶
type NullCloseWriter struct {
// contains filtered or unexported fields
}
func (*NullCloseWriter) Close ¶
func (w *NullCloseWriter) Close() error
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package context stores values shared during a request lifetime.
|
Package context stores values shared during a request lifetime. |
Package csrf (gorilla/csrf) provides Cross Site Request Forgery (CSRF) prevention middleware for Go web applications & services.
|
Package csrf (gorilla/csrf) provides Cross Site Request Forgery (CSRF) prevention middleware for Go web applications & services. |
html
|
|
template
Package template (gf/html/template) implements data-driven templates for generating HTML output safe against code injection.
|
Package template (gf/html/template) implements data-driven templates for generating HTML output safe against code injection. |
Package gorilla/securecookie encodes and decodes authenticated and optionally encrypted cookie values.
|
Package gorilla/securecookie encodes and decodes authenticated and optionally encrypted cookie values. |
Package gorilla/sessions provides cookie and filesystem sessions and infrastructure for custom session backends.
|
Package gorilla/sessions provides cookie and filesystem sessions and infrastructure for custom session backends. |
text
|
|
template
Package template implements data-driven templates for generating textual output.
|
Package template implements data-driven templates for generating textual output. |
template/parse
Package parse builds parse trees for templates as defined by gf/text/template and gf/html/template.
|
Package parse builds parse trees for templates as defined by gf/text/template and gf/html/template. |
Click to show internal directories.
Click to hide internal directories.