orivil

package module
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2016 License: MIT Imports: 26 Imported by: 4

README

Orivil Web Framework

Fast & Simple & Powerful Go Web Framework. Inspired by Symfony and Laravel.


Version

v1.0

Feature

  • Use service container to manage services.
  • Fantastic view file compiler.
  • Semantic management of middleware.
  • Auto generate controller routes.
  • Could cache view file, cache services, support memory session.
  • Made up of components, every user could be a contributor.
  • Auto generate I18n files, including view file and configuration file.

Install

go get -v gopkg.in/orivil/orivil.v1

Run Example

cd $GOPATH/src/gopkg.in/orivil/orivil.v1/example_server/base_server

go run main.go

Test Example

Browser visit: http://localhost:8080

ApacheBench Test

Env
  • OS: ubuntu 14.04 LTS
  • CPU: Intel® Core™ i7-2600K
  • GO: go1.6 linux/amd64
  • DEBUG: false
Without Session

ab -c 1000 -n 100000 http://localhost:8080/

Requests per second:    18693.95 [#/sec] (mean)
With Memory Session

ab -c 1000 -n 100000 http://localhost:8080/set-session/ooorivil

Requests per second:    18150.50 [#/sec] (mean)

Community


Contributors

https://github.com/orivil/orivil/graphs/contributors


License

Released under the MIT License.


Documentation

Overview

Package orivil organize all of the server components to be one runnable server, and provides some useful methods.

Index

Constants

View Source
const (
	SvcMemorySession    = "session.MemorySession"
	SvcPermanentSession = "session.PermanentSession"
	SvcSessionContainer = "orivil.SessionContainer"
	SessionContainerKey = "orivil.SessionContainerKey"
)
View Source
const (
	EvtRegisterService = "event_register_service"
	EvtRegisterRoute   = "event_register_Route"
	EvtRegisterMiddle  = "event_register_Middle"
	EvtBootProvider    = "event_boot_Provider"
	EvtConfigProvider  = "event_Config_Provider"
)
View Source
const (
	LsnServer = "orivil.ServerListener"
)
View Source
const (
	SvcApp = "orivil.App"
)
View Source
const SvcI18nFilter = "orivil.I18nFilter"

Variables

View Source
var (
	DirBase       = getBaseDir()
	DirStaticFile = filepath.Join(DirBase, "public")
	DirBundle     = filepath.Join(DirBase, "bundle")
	DirConfig     = filepath.Join(DirBase, "config")
	DirCache      = filepath.Join(DirBase, "cache")
)

dirs

View Source
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...))
	}
)
View Source
var Cfg = config.NewConfig(DirConfig)
View Source
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 GetIp

func GetIp(r *http.Request) string

func Redirect

func Redirect(url string)

func RedirectCode

func RedirectCode(url string, code int)

func Return

func Return()

func SendEmail

func SendEmail(to string, title, body string) error

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

func (app *App) AddCache(name string, service interface{})

func (*App) Danger

func (app *App) Danger(msg string)

func (*App) FilterI18n

func (app *App) FilterI18n(msg string) (i18nMsg string)

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

func (app *App) Form() url.Values

func (*App) FormFile

func (app *App) FormFile(key string) (multipart.File, *multipart.FileHeader, error)

func (*App) Get

func (app *App) Get(service string) interface{}

func (*App) GetCache

func (app *App) GetCache(service string) interface{}

func (*App) GetNew

func (app *App) GetNew(service string) interface{}

func (*App) Info

func (app *App) Info(msg string)

func (*App) IsGet

func (app *App) IsGet() bool

func (*App) IsPost

func (app *App) IsPost() bool

func (*App) JsonEncode

func (app *App) JsonEncode(data interface{})

func (*App) PSession

func (app *App) PSession() PSession

func (*App) Query

func (app *App) Query() url.Values

func (*App) Redirect

func (app *App) Redirect(url string)

func (*App) Return

func (app *App) Return()

Return will flash data to client and block current http goroutine continue to execute

func (*App) Session

func (app *App) Session() Session

func (*App) SessionContainer

func (app *App) SessionContainer() *service.Container

func (*App) SetCookie

func (app *App) SetCookie(key, value string, maxAge int)

func (*App) Success

func (app *App) Success(msg string)

func (*App) View

func (app *App) View(file ...string) *App

View for store the view filename, if use default action name, it will set the action name's first letter to lowercase

func (*App) Warning

func (app *App) Warning(msg string)

func (*App) With

func (app *App) With(name string, data interface{})

func (*App) WriteString

func (app *App) WriteString(str string)

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 CloseAble

type CloseAble interface {
	Close()
}

CloseAble

type FileHandler

type FileHandler interface {
	// HandleFile to check if handle the url as static file
	HandleFile(*http.Request) bool
	// ServeFile for serve static file
	ServeFile(w http.ResponseWriter, r *http.Request, fileName string)
}

type I18nFilter

type I18nFilter interface {
	FilterMsg(src string) (dst string)

	ViewSubDir() (dir string)
}

type MiddlewareConfigure

type MiddlewareConfigure interface {
	SetMiddle(bag *middle.Bag)
}

type NotFoundHandler

type NotFoundHandler interface {
	NotFound(w http.ResponseWriter, r *http.Request)
}

type PSession

type PSession interface {
	ID() string

	Set(key, value string)

	Get(key string) (value string)

	Flash(key string) (value string)

	Del(key string)
}

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 RegisterListener interface {
	RegisterService(s *Server)

	RegisterRoute(s *Server)

	RegisterMiddle(s *Server)

	BootProvider(s *Server)

	ConfigServer(s *Server)
}

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 NewServer

func NewServer(addr string) *Server

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

func (s *Server) HandleFile(r *http.Request) bool

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

func (s *Server) PrintMsg()

func (*Server) RegisterBundle

func (s *Server) RegisterBundle(app ...Register)

RegisterBundle for add bundle register to the server

func (*Server) Run

func (s *Server) Run()

func (*Server) ServeFile

func (s *Server) ServeFile(w http.ResponseWriter, r *http.Request, name string)

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 Session

type Session interface {
	ID() string

	SetData(key string, data interface{})

	GetData(key string) interface{}

	FlashData(key string) (data interface{})

	DelData(key string)

	Set(key, value string)

	Get(key string) (value string)

	Flash(key string) (value string)

	Del(key string)
}

type TerminateHandler

type TerminateHandler interface {
	Terminate(app *App)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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