server

package
v0.0.34 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2019 License: Apache-2.0 Imports: 25 Imported by: 17

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ResourceDir string

ResourceDir is the path to the resources directory. It is set on startup based on the configuration.

Functions

func LoadDataRecords

func LoadDataRecords(resourceDir string)

LoadDataRecords loads all the data records in the 'data' directory into the database. Data records are defined in CSV files.

func LoadDemoRecords

func LoadDemoRecords(resourceDir string)

LoadDemoRecords loads all the data records in the 'demo' directory into the database. Demo records are defined in CSV files.

func LoadInternalResources

func LoadInternalResources(resourceDir string)

LoadInternalResources loads all data in the 'resources' directory, that are - views, - actions, - menu items Internal resources are defined in XML files.

func LoadModuleTranslations

func LoadModuleTranslations(i18nDir string, langs []string)

LoadModuleTranslations loads the PO files in the given directory for the given languages

func LoadTranslations

func LoadTranslations(resourceDir string, langs []string)

LoadTranslations loads all translation data from the PO files in the 'i18n' directory into the translations registry.

func PostInit

func PostInit()

PostInit runs all actions that need to be done after all modules have been loaded. This is typically all actions that need to be done after bootstrapping the models. This function: - runs successively all PostInit() func of all modules,

func PostInitModules

func PostInitModules()

PostInitModules calls successively all PostInit functions of all installed modules

func PreInit

func PreInit()

PreInit runs all actions that need to be done after we get the configuration, but before bootstrap.

This function runs successively all PreInit() func of modules

func PreInitModules

func PreInitModules()

PreInitModules calls successively all PreInit functions of all installed modules

func RegisterModule

func RegisterModule(mod *Module)

RegisterModule registers the given module in the server This function should be called in the init() function of all Hexya Addons.

Types

type Context

type Context struct {
	*gin.Context
}

The Context allows to pass data across controller layers and middlewares.

func (*Context) BindRPCParams

func (c *Context) BindRPCParams(data interface{})

BindRPCParams binds the RPC parameters to the given data object.

func (*Context) HTML

func (c *Context) HTML(code int, name string, context hweb.Context)

HTML renders the HTTP template specified by its file name. It also updates the HTTP code and sets the Content-Type as "text/html". See http://golang.org/doc/articles/wiki/

func (*Context) HTTPGet

func (c *Context) HTTPGet(uri string) (*http.Response, error)

HTTPGet makes an http GET request to this server with the context's session cookie

func (*Context) RPC

func (c *Context) RPC(code int, obj interface{}, err ...error)

RPC serializes the given struct as JSON-RPC into the response body.

func (*Context) Session

func (c *Context) Session() sessions.Session

Session returns the current Session instance

func (*Context) Super

func (c *Context) Super()

Super calls the next middleware / handler layer It is an alias for Next

type HandlerFunc

type HandlerFunc func(*Context)

A HandlerFunc is a function that can be used for handling a given request or as a middleware

type JSONRPCError

type JSONRPCError struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

JSONRPCError is the format of an Error in a ResponseError

type JSONRPCErrorData

type JSONRPCErrorData struct {
	Arguments     []string `json:"arguments"`
	ExceptionType string   `json:"exception_type"`
	Debug         string   `json:"debug"`
}

JSONRPCErrorData is the format of the Data field of an Error Response

type Module

type Module struct {
	Name     string
	PreInit  func() // Function to be run before bootstrap but after all calls to init
	PostInit func() // Function to be run after initialisation is complete and before server starts
}

A Module is a go package that implements business features. This struct is used to register modules.

type ModulesList

type ModulesList []*Module

A ModulesList is a list of Module objects

var Modules ModulesList

Modules is the list of activated modules in the application

func (*ModulesList) Names

func (ml *ModulesList) Names() []string

Names returns a list of all module names in this ModuleList.

type RequestRPC

type RequestRPC struct {
	JsonRPC string          `json:"jsonrpc"`
	ID      int64           `json:"id"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params"`
}

A RequestRPC is the message format expected from a client

type ResponseError

type ResponseError struct {
	JsonRPC string       `json:"jsonrpc"`
	ID      int64        `json:"id"`
	Error   JSONRPCError `json:"error"`
}

A ResponseError is the message format sent back to a client in case of failure

type ResponseRPC

type ResponseRPC struct {
	JsonRPC string      `json:"jsonrpc"`
	ID      int64       `json:"id"`
	Result  interface{} `json:"result"`
}

A ResponseRPC is the message format sent back to a client in case of success

type RouterGroup

type RouterGroup struct {
	gin.RouterGroup
}

RouterGroup is used internally to configure router, a RouterGroup is associated with a prefix and an array of handlers (middleware)

func (*RouterGroup) Any

func (rg *RouterGroup) Any(relativePath string, handlers ...HandlerFunc) gin.IRoutes

Any registers a route that matches all the HTTP methods. GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE

func (*RouterGroup) DELETE

func (rg *RouterGroup) DELETE(relativePath string, handlers ...HandlerFunc) gin.IRoutes

DELETE is a shortcut for router.Handle("DELETE", path, handle)

func (*RouterGroup) GET

func (rg *RouterGroup) GET(relativePath string, handlers ...HandlerFunc) gin.IRoutes

GET is a shortcut for router.Handle("GET", path, handle)

func (*RouterGroup) Group

func (rg *RouterGroup) Group(relativePath string, handlers ...HandlerFunc) *RouterGroup

Group creates a new router group. You should add all the routes that have common middlwares or the same path prefix. For example, all the routes that use a common middlware for authorization could be grouped.

func (*RouterGroup) HEAD

func (rg *RouterGroup) HEAD(relativePath string, handlers ...HandlerFunc) gin.IRoutes

HEAD is a shortcut for router.Handle("HEAD", path, handle)

func (*RouterGroup) Handle

func (rg *RouterGroup) Handle(httpMethod, relativePath string, handlers ...HandlerFunc) gin.IRoutes

Handle registers a new request handle and middleware with the given path and method. The last handler should be the real handler, the other ones should be middleware that can and should be shared among different routes. See the example code in github.

For GET, POST, PUT, PATCH and DELETE requests the respective shortcut functions can be used.

This function is intended for bulk loading and to allow the usage of less frequently used, non-standardized or custom methods (e.g. for internal communication with a proxy).

func (*RouterGroup) OPTIONS

func (rg *RouterGroup) OPTIONS(relativePath string, handlers ...HandlerFunc) gin.IRoutes

OPTIONS is a shortcut for router.Handle("OPTIONS", path, handle)

func (*RouterGroup) PATCH

func (rg *RouterGroup) PATCH(relativePath string, handlers ...HandlerFunc) gin.IRoutes

PATCH is a shortcut for router.Handle("PATCH", path, handle)

func (*RouterGroup) POST

func (rg *RouterGroup) POST(relativePath string, handlers ...HandlerFunc) gin.IRoutes

POST is a shortcut for router.Handle("POST", path, handle)

func (*RouterGroup) PUT

func (rg *RouterGroup) PUT(relativePath string, handlers ...HandlerFunc) gin.IRoutes

PUT is a shortcut for router.Handle("PUT", path, handle)

func (*RouterGroup) Use

func (rg *RouterGroup) Use(middleware ...HandlerFunc) gin.IRoutes

Use adds middleware to the group.

type Server

type Server struct {
	*gin.Engine
}

A Server is the http server of the application It is internally a wrapper around a gin.Engine

func GetServer

func GetServer() *Server

GetServer return the http server instance

func (*Server) Group

func (s *Server) Group(relativePath string, handlers ...HandlerFunc) *RouterGroup

Group creates a new router group. You should add all the routes that have common middlwares or the same path prefix. For example, all the routes that use a common middlware for authorization could be grouped.

func (*Server) Run

func (s *Server) Run(addr string) (err error)

Run attaches the router to a http.Server and starts listening and serving HTTP requests. It is a shortcut for http.ListenAndServe(addr, router) Note: this method will block the calling goroutine indefinitely unless an error happens.

func (*Server) RunAutoTLS

func (s *Server) RunAutoTLS(domain string) (err error)

RunAutoTLS attaches the router to a http.Server and starts listening and serving HTTPS (secure) requests on port 443 for all interfaces. It automatically gets certificate for the given domain from Letsencrypt. Note: this method will block the calling goroutine indefinitely unless an error happens.

func (*Server) RunTLS

func (s *Server) RunTLS(addr string, certFile string, keyFile string) (err error)

RunTLS attaches the router to a http.Server and starts listening and serving HTTPS (secure) requests. It is a shortcut for http.ListenAndServeTLS(addr, certFile, keyFile, router) Note: this method will block the calling goroutine indefinitely unless an error happens.

Jump to

Keyboard shortcuts

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