Documentation
¶
Overview ¶
Package orivil organize all of the server components to be one runnable server, and provides some useful methods.
Index ¶
- Constants
- Variables
- func CoverError(w http.ResponseWriter, r *http.Request, call func())
- func GetIp(r *http.Request) string
- func Redirect(url string)
- func RedirectCode(url string, code int)
- func Return()
- func SendEmail(to string, title, body string) error
- type App
- func (app *App) AddCache(name string, service interface{})
- func (app *App) Danger(msg string)
- func (app *App) FilterI18n(msg string) (i18nMsg string)
- func (app *App) Flash()
- func (app *App) Form() url.Values
- func (app *App) FormFile(key string) (multipart.File, *multipart.FileHeader, error)
- func (app *App) Get(service string) interface{}
- func (app *App) GetCache(service string) interface{}
- func (app *App) GetNew(service string) interface{}
- func (app *App) Info(msg string)
- func (app *App) IsGet() bool
- func (app *App) IsPost() bool
- func (app *App) JsonEncode(data interface{})
- func (app *App) PSession() PSession
- func (app *App) Query() url.Values
- func (app *App) Redirect(url string)
- func (app *App) Return()
- func (app *App) Session() Session
- func (app *App) SessionContainer() *service.Container
- func (app *App) SetCookie(key, value string, maxAge int)
- func (app *App) Success(msg string)
- func (app *App) View(file ...string) *App
- func (app *App) Warning(msg string)
- func (app *App) With(name string, data interface{})
- func (app *App) WriteString(str string)
- type BaseRegister
- type CloseAble
- type FileHandler
- type I18nFilter
- type MiddlewareConfigure
- type NotFoundHandler
- type PSession
- type Register
- type RegisterListener
- type RequestHandler
- type RouteFilter
- type Server
- func (s *Server) AddServerListener(ls ...event.Listener)
- func (s *Server) Close()
- func (s *Server) HandleFile(r *http.Request) bool
- func (s *Server) NotFound(w http.ResponseWriter, r *http.Request)
- func (s *Server) PrintMsg()
- func (s *Server) RegisterBundle(app ...Register)
- func (s *Server) Run()
- func (s *Server) ServeFile(w http.ResponseWriter, r *http.Request, name string)
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) SetFileHandler(h FileHandler)
- func (s *Server) SetNotFoundHandler(h NotFoundHandler)
- type ServerEventListener
- type ServerListener
- func (this *ServerListener) BootProvider(server *Server)
- func (this *ServerListener) ConfigServer(s *Server)
- func (this *ServerListener) GetSubscribe() (name string, subscribes []event.Subscribe)
- func (this *ServerListener) RegisterMiddle(server *Server)
- func (this *ServerListener) RegisterRoute(server *Server)
- func (this *ServerListener) RegisterService(server *Server)
- type Session
- type TerminateHandler
Constants ¶
const ( SvcMemorySession = "session.MemorySession" SvcPermanentSession = "session.PermanentSession" SvcSessionContainer = "orivil.SessionContainer" SessionContainerKey = "orivil.SessionContainerKey" )
const ( EvtRegisterService = "event_register_service" EvtRegisterRoute = "event_register_Route" EvtRegisterMiddle = "event_register_Middle" EvtBootProvider = "event_boot_Provider" EvtConfigProvider = "event_Config_Provider" )
const (
LsnServer = "orivil.ServerListener"
)
const (
SvcApp = "orivil.App"
)
const SvcI18nFilter = "orivil.I18nFilter"
Variables ¶
var ( DirBase = getBaseDir() DirStaticFile = filepath.Join(DirBase, "public") DirBundle = filepath.Join(DirBase, "bundle") DirConfig = filepath.Join(DirBase, "config") DirCache = filepath.Join(DirBase, "cache") )
dirs
var ( // the unique key for server, Orivil will read the value from config file "app.yml" Key string // Err for handle errors, every one could used it to handle error, and // this method can be re-defined by customers Err = func(e error) { log.Println(e) } // this func is no need to re-defined Errf = func(format string, args ...interface{}) { Err(fmt.Errorf(format, args...)) } Emer = func(e error) { log.Println(e) } Emerf = func(format string, args ...interface{}) { Emer(fmt.Errorf(format, args...)) } Warn = func(e error) { log.Println(e) } Warnf = func(format string, args ...interface{}) { Warn(fmt.Errorf(format, args...)) } )
var Cfg = config.NewConfig(DirConfig)
var CfgApp = &struct { Debug bool Key string View_file_ext string Memory_session_key string Memory_session_max_age int // minute Memory_GC_check_num int Permanent_session_key string Permanent_session_max_age int // minute Permanent_GC_check_num int Timeout int // second }{ Debug: true, Key: "--------------------------------------", View_file_ext: ".tmpl", Memory_session_key: "orivil-memory-session", Permanent_session_key: "orivil-permanent-session", Memory_GC_check_num: 3, Memory_session_max_age: 45, Permanent_session_max_age: 45, Permanent_GC_check_num: 3, Timeout: 10, }
server config
Functions ¶
func CoverError ¶
func CoverError(w http.ResponseWriter, r *http.Request, call func())
func RedirectCode ¶
Types ¶
type App ¶
type App struct { Response http.ResponseWriter Request *http.Request Container *service.Container // private container VContainer *view.Container Params router.Param Action string // action full name like "package.controller.index" // contains filtered or unexported fields }
func (*App) FilterI18n ¶
func (*App) Flash ¶
func (app *App) Flash()
Flash could send the file or api data to client immediately, view files can be sent multiple times, but api data can only be sent once
func (*App) JsonEncode ¶
func (app *App) JsonEncode(data interface{})
func (*App) Return ¶
func (app *App) Return()
Return will flash data to client and block current http goroutine continue to execute
func (*App) SessionContainer ¶
func (app *App) SessionContainer() *service.Container
func (*App) View ¶
View for store the view filename, if use default action name, it will set the action name's first letter to lowercase
func (*App) WriteString ¶
type BaseRegister ¶
type BaseRegister struct{}
func (*BaseRegister) Boot ¶
func (*BaseRegister) Boot(c *service.Container)
func (*BaseRegister) RegisterMiddle ¶
func (*BaseRegister) RegisterMiddle(c *middle.Container)
func (*BaseRegister) RegisterRoute ¶
func (*BaseRegister) RegisterRoute(c *router.Container)
func (*BaseRegister) RegisterService ¶
func (*BaseRegister) RegisterService(c *service.Container)
type FileHandler ¶
type I18nFilter ¶
type MiddlewareConfigure ¶
type MiddlewareConfigure interface {
SetMiddle(bag *middle.Bag)
}
type NotFoundHandler ¶
type NotFoundHandler interface {
NotFound(w http.ResponseWriter, r *http.Request)
}
type Register ¶
type Register interface { RegisterRoute(c *router.Container) RegisterService(c *service.Container) RegisterMiddle(c *middle.Container) Boot(c *service.Container) }
every bundle register should implement Register interface
type RegisterListener ¶
type RequestHandler ¶
type RequestHandler interface {
Handle(app *App)
}
type RouteFilter ¶
type RouteFilter struct {
// contains filtered or unexported fields
}
RouteFilter filter actions be registered to router
func NewRouteFilter ¶
func NewRouteFilter() *RouteFilter
func (*RouteFilter) AddActions ¶
func (f *RouteFilter) AddActions(actions []string)
AddActions filter all actions
func (*RouteFilter) AddStructs ¶
func (f *RouteFilter) AddStructs(structs []interface{})
AddStructs filter all structs methods
func (*RouteFilter) FilterAction ¶
func (f *RouteFilter) FilterAction(action string) bool
implement router.ActionFilter interface for filter actions
type Server ¶
type Server struct { SContainer *service.Container MContainer *middle.Container RContainer *router.Container MiddleBag *middle.Bag VContainer *view.Container Dispatcher *event.Dispatcher Registers []Register *gracehttp.Server // contains filtered or unexported fields }
func (*Server) AddServerListener ¶
func (s *Server) AddServerListener(ls ...event.Listener)
AddServerListener for add server event listeners
func (*Server) Close ¶
func (s *Server) Close()
Close for close bundle registers, this function will be auto executed
func (*Server) HandleFile ¶
HandleFile for judge the client whether or not to request a static file, this function could be replaced by customers
func (*Server) NotFound ¶
func (s *Server) NotFound(w http.ResponseWriter, r *http.Request)
implement NotFoundHandler interface
func (*Server) RegisterBundle ¶
RegisterBundle for add bundle register to the server
func (*Server) ServeFile ¶
ServeFile for serve static file, this function could be replaced by customers
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP for serve http request, every request goes through the function, include static file request
func (*Server) SetFileHandler ¶
func (s *Server) SetFileHandler(h FileHandler)
SetFileHandler for set customer file handler
func (*Server) SetNotFoundHandler ¶
func (s *Server) SetNotFoundHandler(h NotFoundHandler)
SetNotFoundHandler for handle 404 not found
type ServerEventListener ¶
type ServerEventListener interface {
AddServerListener(d *event.Dispatcher)
}
type ServerListener ¶
type ServerListener struct{}
func (*ServerListener) BootProvider ¶
func (this *ServerListener) BootProvider(server *Server)
func (*ServerListener) ConfigServer ¶
func (this *ServerListener) ConfigServer(s *Server)
func (*ServerListener) GetSubscribe ¶
func (this *ServerListener) GetSubscribe() (name string, subscribes []event.Subscribe)
func (*ServerListener) RegisterMiddle ¶
func (this *ServerListener) RegisterMiddle(server *Server)
func (*ServerListener) RegisterRoute ¶
func (this *ServerListener) RegisterRoute(server *Server)
func (*ServerListener) RegisterService ¶
func (this *ServerListener) RegisterService(server *Server)
type TerminateHandler ¶
type TerminateHandler interface {
Terminate(app *App)
}