Documentation ¶
Index ¶
- Constants
- Variables
- func I18nFilter(c *Controller)
- func ParamsFilter(c *Controller)
- func SessionFilter(c *Controller)
- type Config
- type Controller
- func (c *Controller) Redirect(url string)
- func (c *Controller) Render(args ...interface{})
- func (c *Controller) RenderError(status int, msg string)
- func (c *Controller) RenderHTML(htm string)
- func (c *Controller) RenderJson(obj interface{})
- func (c *Controller) RenderJsonIndent(obj interface{}, indent string)
- func (c *Controller) RenderString(v string)
- func (c *Controller) Translate(msg string, args ...interface{}) string
- func (c *Controller) UrlBase(path string) string
- func (c *Controller) UrlModuleBase(path string) string
- type Filter
- type Logger
- type Module
- func (m *Module) RegisterController(args ...interface{})
- func (m *Module) RegisterFileServer(pattern, path string, fs http.FileSystem)
- func (m *Module) SetRoute(pattern string, params map[string]string)
- func (m *Module) SetTemplateFileSystem(fss ...http.FileSystem)
- func (m *Module) SetTemplatePath(paths ...string)
- type Params
- type Request
- type Response
- type Service
- type Session
- type TemplateLoader
Constants ¶
View Source
const Version = "0.12.0"
Variables ¶
View Source
var ( DefaultModule = &Module{ idxHandlers: make(map[string]*regHandler), routes: make(map[string]*regRouter), } DefaultModules = []*Module{} )
View Source
var DefaultConfig = Config{
HttpAddr: "0.0.0.0",
HttpPort: 8080,
HttpTimeout: 30,
CookieKeyLocale: "lang",
CookieKeySession: "access_token",
}
View Source
var DefaultFilters = []Filter{ ParamsFilter, SessionFilter, I18nFilter, }
Filters is the default set of global filters. It may be set by the application on initialization.
View Source
var (
DefaultService = NewService()
)
View Source
var TemplateFuncs = map[string]interface{}{ "eq": tfEqual, "raw": func(text string) template.HTML { return template.HTML(text) }, "replace": func(s, old, new string) string { return strings.Replace(s, old, new, -1) }, "date": func(t time.Time) string { return t.Format("2006-01-02") }, "datetime": func(t time.Time) string { return t.Format("2006-01-02 15:04") }, "upper": func(s string) string { return strings.ToUpper(s) }, "lower": func(s string) string { return strings.ToLower(s) }, "T": func(lang map[string]interface{}, msg string, args ...interface{}) string { return i18nTranslate(lang["LANG"].(string), msg, args...) }, }
Functions ¶
func I18nFilter ¶
func I18nFilter(c *Controller)
func ParamsFilter ¶
func ParamsFilter(c *Controller)
func SessionFilter ¶
func SessionFilter(c *Controller)
Types ¶
type Config ¶
type Config struct { // e.g. "127.0.0.1", "unix:/tmp/app.sock" HttpAddr string `json:"http_addr,omitempty" toml:"http_addr,omitempty"` // e.g. 8080 HttpPort uint16 `json:"http_port,omitempty" toml:"http_port,omitempty"` HttpTimeout uint16 `json:"http_timeout,omitempty" toml:"http_timeout,omitempty"` UrlBasePath string `json:"url_base_path,omitempty" toml:"url_base_path,omitempty"` CookieKeyLocale string `json:"cookie_key_locale,omitempty" toml:"cookie_key_locale,omitempty"` CookieKeySession string `json:"cookie_key_session,omitempty" toml:"cookie_key_session,omitempty"` CompressResponse bool `json:"compress_response,omitempty" toml:"compress_response,omitempty"` }
func (*Config) RegisterTemplateFunc ¶ added in v0.12.2
type Controller ¶
type Controller struct { Name string // The controller name, e.g. "App" ActionName string // The action name, e.g. "Index" Request *Request Response *Response Params *Params // Parameters from URL and form (including multipart). Session *Session // Session, stored in cookie, signed. AutoRender bool Data map[string]interface{} // contains filtered or unexported fields }
func (*Controller) Redirect ¶
func (c *Controller) Redirect(url string)
func (*Controller) Render ¶
func (c *Controller) Render(args ...interface{})
func (*Controller) RenderError ¶
func (c *Controller) RenderError(status int, msg string)
func (*Controller) RenderHTML ¶ added in v0.12.5
func (c *Controller) RenderHTML(htm string)
func (*Controller) RenderJson ¶
func (c *Controller) RenderJson(obj interface{})
func (*Controller) RenderJsonIndent ¶
func (c *Controller) RenderJsonIndent(obj interface{}, indent string)
func (*Controller) RenderString ¶
func (c *Controller) RenderString(v string)
func (*Controller) Translate ¶
func (c *Controller) Translate(msg string, args ...interface{}) string
func (*Controller) UrlBase ¶
func (c *Controller) UrlBase(path string) string
func (*Controller) UrlModuleBase ¶
func (c *Controller) UrlModuleBase(path string) string
type Filter ¶
type Filter func(c *Controller)
type Logger ¶ added in v0.12.0
type Logger interface { Debugf(format string, v ...interface{}) Infof(format string, v ...interface{}) Warnf(format string, v ...interface{}) Errorf(format string, v ...interface{}) Fatalf(format string, v ...interface{}) }
func NewEmptyLogger ¶ added in v0.12.0
func NewEmptyLogger() Logger
func NewRawLogger ¶ added in v0.12.0
func NewRawLogger() Logger
type Module ¶
type Module struct { Path string // contains filtered or unexported fields }
func (*Module) RegisterController ¶ added in v0.12.0
func (m *Module) RegisterController(args ...interface{})
func (*Module) RegisterFileServer ¶ added in v0.12.2
func (m *Module) RegisterFileServer(pattern, path string, fs http.FileSystem)
func (*Module) SetTemplateFileSystem ¶ added in v0.12.0
func (m *Module) SetTemplateFileSystem(fss ...http.FileSystem)
func (*Module) SetTemplatePath ¶ added in v0.12.0
type Params ¶
type Params struct {
// contains filtered or unexported fields
}
func (*Params) FloatValue ¶ added in v0.12.2
type Request ¶
type Request struct { *http.Request Time time.Time ContentType string Locale string // contains filtered or unexported fields }
func (*Request) JsonDecode ¶
func (*Request) UrlRoutePath ¶ added in v0.12.1
type Response ¶
type Response struct { Status int Out http.ResponseWriter // contains filtered or unexported fields }
func (*Response) WriteHeader ¶
type Service ¶
type Service struct { Config Config Filters []Filter TemplateLoader *TemplateLoader // contains filtered or unexported fields }
func NewService ¶
func NewService() *Service
func (*Service) HandleFunc ¶ added in v0.12.0
func (*Service) HandleModule ¶ added in v0.12.0
type TemplateLoader ¶
type TemplateLoader struct {
// contains filtered or unexported fields
}
This object handles loading and parsing of templates. Everything below the application's views directory is treated as a template.
func (*TemplateLoader) Clean ¶
func (it *TemplateLoader) Clean(modUrlBase string)
func (*TemplateLoader) Render ¶
func (it *TemplateLoader) Render(wr io.Writer, modUrlBase, tplPath string, arg interface{}) error
func (*TemplateLoader) Set ¶
func (it *TemplateLoader) Set(modUrlBase string, viewpaths []string, viewfss []http.FileSystem)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.