Documentation ¶
Overview ¶
Kwiscale is a framework that provides Handling System. That means that you will be able to create Handlers that handles HTTP Verbs methods. Kwiscale can handle basic HTTP Verbs as Get, Post, Delete, Patch, Head and Option.
Kwiscale can also serve Websockets.
Kwiscale provides a basic template system based on http/template from Go SDK and has got a plugin system to provides other template engines.
The built-in template allows to override templates. Example:
// templates/main.go <body> {{ template "CONTENT" .}} </body> // template/home/index.go (remove the "\" in override directive) {{/* override "main.go" *\/}} {{ define "CONTENT" }} <p>Hello workd</p> {{ end }}
Also, built-in template provides two functions:
- url: gives url of a handler with parameters
- static: gives static resource url
Example:
<link rel="stylesheet" href="{{static "/css/styles.css"}}" /> <a href="{{ url "home" }}">Home</a> <a href="{{ url "user" "id" 12345 }}">User</a> <a href="{{ url "handlers.UserHandler" "id" 12345 }}">User</a>
For "url" function, the first argument can be:
- alias for handler
- handler name
Others arguments are the pair "key value".
See http://gopkg.in/kwiscale/template-pongo2.v1 to use Pongo2.
To handle HTTP Verbs:
type HomeHandler struct {kwiscale.RequestHandler} func (home *HomeHandler) Get(){ // This will respond to GET call home.WriteString("Hello !") } func main(){ app := kwiscale.NewApp(nil) app.AddRoute("/home", &HomeHandler{}) // Default listening on 8000 port app.ListenAndServe() }
To be able to use configuration file (yaml), you MUST register handlers. The common way to do is to use "init()" function in you handlers package:
package handlers import "gopkg.in/kwiscale/framework.v1" func init(){ kwiscale.Register(&HomeHandler{}) } type HomeHandler struct {kwiscale.HomeHandler} //...
Note: if you're using kwiscale CLI, `kwiscale new handler` command create the register call for you.
Kwiscale provide a way to have method with parameter that are mapped from the given route.
Example:
app.AddRoute(`/user/{name:.+/}{id:\d+}/`, UserHandler{}) //... type UserHandler struct {kwiscale.RequestHandler} func (handler *UserHandler) Get(name string, id int) { // ... }
Note that parameters names for Get() method are not used to map url values. Kwiscale maps values repecting the order found in the route. So you may declare Get() method like this:
func (handler *UserHandler) Get(a string, b int) { // ... }
Anyway, you always may use "UserHandler.Vars": UserHandler.Vars["id"] and UserHandler.Vars["name"] that are `string` typed.
You may use Init() and Destroy() method that are called before and after HTTP verb invocation. You may, for example, open database connection in "Init" and close the connection in "Destroy".
Kwiscale provides a CLI:
go get gopkg.in/framework/kwiscale kwiscale --help NAME: kwiscale - tool to manage kwiscale application USAGE: kwiscale [global options] command [command options] [arguments...] VERSION: 0.0.1 COMMANDS: new Generate resources (application, handlers...) generate Parse configuration and generate handlers, main file... help, h Shows a list of commands or help for one command GLOBAL OPTIONS: --project "kwiscale-app" project name, will set $GOPATH/src/[projectname] [$KWISCALE_PROJECT] --handlers "handlers" handlers package name [$KWISCALE_HANDLERS] --help, -h show help --generate-bash-completion --version, -v print the version
Index ¶
- Variables
- func Error(v ...interface{})
- func Log(v ...interface{})
- func Register(h WebHandler)
- func RegisterSessionEngine(name string, engine SessionStore)
- func RegisterTemplateEngine(name string, tpl Template)
- func SetDebug(mode bool)
- type App
- func (app *App) AddNamedRoute(route string, handler WebHandler, name string)
- func (app *App) AddRoute(route string, handler WebHandler)
- func (app *App) Error(status int, w http.ResponseWriter, err error, details ...interface{})
- func (app *App) GetRoute(name string) *mux.Route
- func (app *App) GetRoutes(name string) []*mux.Route
- func (app *App) GetTemplate() Template
- func (app *App) ListenAndServe(port ...string)
- func (app *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (app *App) SetErrorHandler(h WebHandler)
- func (app *App) SetStatic(prefix string)
- func (app *App) SoftStop() chan int
- type BaseHandler
- func (b *BaseHandler) App() *App
- func (b *BaseHandler) CleanSession()
- func (b *BaseHandler) Destroy()
- func (b *BaseHandler) GetApp() *App
- func (b *BaseHandler) GetJSONPayload(v interface{}) error
- func (b *BaseHandler) GetPayload() []byte
- func (b *BaseHandler) GetPost(name string) string
- func (b *BaseHandler) GetPostFile(name string) (multipart.File, *multipart.FileHeader, error)
- func (b *BaseHandler) GetPostValues() url.Values
- func (b *BaseHandler) GetRequest() *http.Request
- func (b *BaseHandler) GetResponse() http.ResponseWriter
- func (b *BaseHandler) GetSession(key interface{}) (interface{}, error)
- func (b *BaseHandler) GetURL(s ...string) (*url.URL, error)
- func (b *BaseHandler) Init() (int, error)
- func (b *BaseHandler) JSONPayload(v interface{}) error
- func (b *BaseHandler) Payload() []byte
- func (b *BaseHandler) PostValue(name string, def ...string) string
- func (b *BaseHandler) PostValues() url.Values
- func (b *BaseHandler) Request() *http.Request
- func (b *BaseHandler) Response() http.ResponseWriter
- func (b *BaseHandler) SavePostFile(name, to string) error
- func (b *BaseHandler) SetSession(key interface{}, value interface{})
- func (b *BaseHandler) URL(s ...string) (*url.URL, error)
- type BuiltInTemplate
- type Config
- type CookieSessionStore
- func (s *CookieSessionStore) Clean(handler WebHandler)
- func (s *CookieSessionStore) Get(handler WebHandler, key interface{}) (interface{}, error)
- func (s *CookieSessionStore) Init()
- func (s *CookieSessionStore) Name(name string)
- func (s *CookieSessionStore) Set(handler WebHandler, key interface{}, val interface{})
- func (*CookieSessionStore) SetOptions(SessionEngineOptions)
- func (s *CookieSessionStore) SetSecret(secret []byte)
- type ErrorHandler
- type HTTPErrorHandler
- type HTTPRequestHandler
- type PayloadType
- type RequestHandler
- func (r *RequestHandler) Delete()
- func (r *RequestHandler) Error(status int, message string, details ...interface{})
- func (r *RequestHandler) Get()
- func (b *RequestHandler) GlobalCtx() map[string]interface{}deprecated
- func (r *RequestHandler) Head()
- func (r *RequestHandler) Options()
- func (r *RequestHandler) Patch()
- func (r *RequestHandler) Post()
- func (r *RequestHandler) Put()
- func (r *RequestHandler) Redirect(uri string)
- func (r *RequestHandler) RedirectWithStatus(uri string, status int)
- func (r *RequestHandler) Render(file string, ctx map[string]interface{}) error
- func (r *RequestHandler) Status(status int)
- func (r *RequestHandler) Trace()
- func (r *RequestHandler) Write(data []byte) (int, error)
- func (r *RequestHandler) WriteJSON(data interface{}) (int, error)
- func (r *RequestHandler) WriteString(data string) (int, error)
- type SessionEngineOptions
- type SessionStore
- type Template
- type TplOptions
- type WSHandler
- type WSJsonHandler
- type WSServerHandler
- type WSStringHandler
- type WebHandler
- type WebSocketHandler
- func (ws *WebSocketHandler) Close()
- func (ws *WebSocketHandler) GetConnection() *websocket.Conn
- func (ws *WebSocketHandler) OnClose() error
- func (ws *WebSocketHandler) OnConnect() error
- func (ws *WebSocketHandler) SendJSON(i interface{}) error
- func (ws *WebSocketHandler) SendJSONToAll(i interface{})
- func (ws *WebSocketHandler) SendJSONToRoom(room string, i interface{})
- func (ws *WebSocketHandler) SendJSONToThisRoom(i interface{})
- func (ws *WebSocketHandler) SendText(s string) error
- func (ws *WebSocketHandler) SendTextToAll(s string)
- func (ws *WebSocketHandler) SendTextToRoom(name, s string)
- func (ws *WebSocketHandler) SendTextToThisRoom(s string)
- func (ws *WebSocketHandler) Write(b []byte) error
- func (ws *WebSocketHandler) WriteJSON(i interface{}) error
- func (ws *WebSocketHandler) WriteString(m string) error
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Register ¶
func Register(h WebHandler)
Register takes webhandler and keep type in handlerRegistry. It can be called directly (to set handler accessible by configuration file), or implicitally by "AddRoute" and "AddNamedRoute()".
func RegisterSessionEngine ¶
func RegisterSessionEngine(name string, engine SessionStore)
RegisterSessionEngine can register session engine that implements ISessionStore. The name is used to let configuration to select it.
func RegisterTemplateEngine ¶
RegisterTemplateEngine records template engine that implements Template interface. The name is used to let config select the template engine.
Types ¶
type App ¶
type App struct { // configuration Config *Config // Global context shared to handlers Context map[string]interface{} // contains filtered or unexported fields }
App handles router and handlers.
func NewAppFromConfigFile ¶
NewAppFromConfigFile import config file and returns *App.
func (*App) AddNamedRoute ¶
func (app *App) AddNamedRoute(route string, handler WebHandler, name string)
AddNamedRoute does the same as AddRoute but set the route name instead of using the handler name. If the given name already exists or is empty, the method panics.
func (*App) AddRoute ¶
func (app *App) AddRoute(route string, handler WebHandler)
AddRoute appends route mapped to handler. Note that rh parameter should implement IRequestHandler (generally a struct composing RequestHandler or WebSocketHandler).
func (*App) Error ¶
func (app *App) Error(status int, w http.ResponseWriter, err error, details ...interface{})
Error displays an error page with details if any.
func (*App) GetTemplate ¶
GetTemplate returns a new instance of Template.
func (*App) ListenAndServe ¶
ListenAndServe calls http.ListenAndServe method
func (*App) ServeHTTP ¶
func (app *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
Implement http.Handler ServeHTTP method.
func (*App) SetErrorHandler ¶
func (app *App) SetErrorHandler(h WebHandler)
SetErrorHandler set error handler to replace the default ErrorHandler.
type BaseHandler ¶
BaseHandler is the parent struct of every Handler. Implement WebHandler.
func (*BaseHandler) CleanSession ¶
func (b *BaseHandler) CleanSession()
CleanSession remove every key/value of the current session.
func (*BaseHandler) Destroy ¶
func (b *BaseHandler) Destroy()
Destroy is called as defered function after response.
func (*BaseHandler) GetApp ¶
func (b *BaseHandler) GetApp() *App
GetApp returns the app that holds this handler.
DEPRECATED -- see App()
func (*BaseHandler) GetJSONPayload ¶
func (b *BaseHandler) GetJSONPayload(v interface{}) error
GetJSONPayload unmarshal body to the "v" interface.
DEPRECATED - see JSONPayload()
func (*BaseHandler) GetPayload ¶
func (b *BaseHandler) GetPayload() []byte
GetPayload returns the Body content.
DEPRECATED - see Payload()
func (*BaseHandler) GetPost ¶
func (b *BaseHandler) GetPost(name string) string
GetPost return the post data for the given "name" argument.
DEPRECATED -- see PostVar()
func (*BaseHandler) GetPostFile ¶
func (b *BaseHandler) GetPostFile(name string) (multipart.File, *multipart.FileHeader, error)
GetPostFile returns the "name" file pointer and information from the post data.
func (*BaseHandler) GetPostValues ¶
func (b *BaseHandler) GetPostValues() url.Values
GetPostValues returns the entire posted values.
DEPRECATED - see PostValues()
func (*BaseHandler) GetRequest ¶
func (b *BaseHandler) GetRequest() *http.Request
GetRequest returns the current request.
DEPRECATED -- see Request()
func (*BaseHandler) GetResponse ¶
func (b *BaseHandler) GetResponse() http.ResponseWriter
GetResponse returns the current response.
DEPRECATED -- see Response()
func (*BaseHandler) GetSession ¶
func (b *BaseHandler) GetSession(key interface{}) (interface{}, error)
GetSession return the session value of "key".
func (*BaseHandler) GetURL ¶
func (b *BaseHandler) GetURL(s ...string) (*url.URL, error)
GetURL return an url based on the declared route and given string pair.
DEPRECATED -- see URL()
func (*BaseHandler) Init ¶
func (b *BaseHandler) Init() (int, error)
Init is called before the begin of response (before Get, Post, and so on). If error is not nil, framework will write response with the second argument as http status.
func (*BaseHandler) JSONPayload ¶ added in v1.0.3
func (b *BaseHandler) JSONPayload(v interface{}) error
JSONPayload unmarshal body to the "v" interface.
func (*BaseHandler) Payload ¶ added in v1.0.3
func (b *BaseHandler) Payload() []byte
Payload returns the Body content.
func (*BaseHandler) PostValue ¶ added in v1.0.3
func (b *BaseHandler) PostValue(name string, def ...string) string
PostValue returns the post data for the given "name" argument. If POST value is empty, return "def" instead. If no "def" is provided, return an empty string by default.
func (*BaseHandler) PostValues ¶ added in v1.0.3
func (b *BaseHandler) PostValues() url.Values
PostValues returns the entire posted values.
func (*BaseHandler) Request ¶
func (b *BaseHandler) Request() *http.Request
Request returns the current request.
func (*BaseHandler) Response ¶
func (b *BaseHandler) Response() http.ResponseWriter
Response returns the current response.
func (*BaseHandler) SavePostFile ¶
func (b *BaseHandler) SavePostFile(name, to string) error
SavePostFile save the given "name" file to the "to" path.
func (*BaseHandler) SetSession ¶
func (b *BaseHandler) SetSession(key interface{}, value interface{})
SetSession set the "key" session to "value".
type BuiltInTemplate ¶
type BuiltInTemplate struct {
// contains filtered or unexported fields
}
BuiltInTemplate is Basic template engine that use html/template.
func (*BuiltInTemplate) Render ¶
func (tpl *BuiltInTemplate) Render(w io.Writer, file string, ctx interface{}) error
Render method for the basic Template system. Allow {{/* override "path.html" */}}, no cache, very basic.
func (*BuiltInTemplate) SetTemplateDir ¶
func (tpl *BuiltInTemplate) SetTemplateDir(path string)
SetTemplateDir set the directory where are found templates.
func (*BuiltInTemplate) SetTemplateOptions ¶
func (tpl *BuiltInTemplate) SetTemplateOptions(TplOptions)
SetTemplateOptions set needed options to template engine. For BuiltInTemplate there are no option at this time.
type Config ¶
type Config struct { // Root directory where TemplateEngine will get files TemplateDir string // Port to listen Port string // Number of handler to prepare NbHandlerCache int // TemplateEngine to use (default, pango2...) TemplateEngine string // Template engine options (some addons need options) TemplateEngineOptions TplOptions // SessionEngine (default is a file storage) SessionEngine string // SessionName is the name of session, eg. Cookie name, default is "kwiscale-session" SessionName string // A secret string to encrypt cookie SessionSecret []byte // Configuration for SessionEngine SessionEngineOptions SessionEngineOptions // Static directory (to put css, images, and so on...) StaticDir string // Activate static in memory cache StaticCacheEnabled bool // StrictSlash allows to match route that have trailing slashes StrictSlash bool }
Config structure that holds configuration
type CookieSessionStore ¶
type CookieSessionStore struct {
// contains filtered or unexported fields
}
CookieSessionStore is a basic cookie based on gorilla.session.
func (*CookieSessionStore) Clean ¶
func (s *CookieSessionStore) Clean(handler WebHandler)
Clean removes the entire session values for current session.
func (*CookieSessionStore) Get ¶
func (s *CookieSessionStore) Get(handler WebHandler, key interface{}) (interface{}, error)
Get a value from session by name.
func (*CookieSessionStore) Init ¶
func (s *CookieSessionStore) Init()
Init prepare the cookie storage.
func (*CookieSessionStore) Name ¶
func (s *CookieSessionStore) Name(name string)
Name set session name
func (*CookieSessionStore) Set ¶
func (s *CookieSessionStore) Set(handler WebHandler, key interface{}, val interface{})
Set a named value in sessionstore.
func (*CookieSessionStore) SetOptions ¶
func (*CookieSessionStore) SetOptions(SessionEngineOptions)
SetOptions does nothing for the engine
func (*CookieSessionStore) SetSecret ¶
func (s *CookieSessionStore) SetSecret(secret []byte)
SetSecret record a string to encode cookie
type ErrorHandler ¶
type ErrorHandler struct { RequestHandler // contains filtered or unexported fields }
ErrorHandler is a basic error handler that displays error in a basic webpage.
func (*ErrorHandler) Details ¶
func (dh *ErrorHandler) Details() interface{}
Details returns details or nil if none.
func (*ErrorHandler) GetError ¶
func (dh *ErrorHandler) GetError() error
GetError returns error that was set by handlers.
func (*ErrorHandler) Status ¶
func (dh *ErrorHandler) Status() int
Status returns the error HTTP Status set by handlers.
type HTTPErrorHandler ¶
type HTTPErrorHandler interface { // Error returns the error. GetError() error // Details returns some detail inteface. Details() interface{} // Status returns the http status code. Status() int // contains filtered or unexported methods }
HTTPErrorHandler interface.
type HTTPRequestHandler ¶
type HTTPRequestHandler interface { Get() Post() Put() Head() Patch() Delete() Options() Trace() Redirect(url string) RedirectWithStatus(url string, httpStatus int) GlobalCtx() map[string]interface{} Error(status int, message string, details ...interface{}) }
HTTPRequestHandler interface which declare HTTP verbs.
type PayloadType ¶ added in v1.0.3
type PayloadType int
PayloadType represents a payload type for Websocket.
const ( // JSON payload type in Websocket. JSON PayloadType = iota // BYTES payload type in Websocket. BYTES // STRING payload type in Websocket. STRING )
type RequestHandler ¶
type RequestHandler struct {
BaseHandler
}
RequestHandler that should be composed by users.
func (*RequestHandler) Delete ¶
func (r *RequestHandler) Delete()
Delete implements IRequestHandler Method - default "not found".
func (*RequestHandler) Error ¶
func (r *RequestHandler) Error(status int, message string, details ...interface{})
func (*RequestHandler) Get ¶
func (r *RequestHandler) Get()
Get implements IRequestHandler Method - default "not found".
func (*RequestHandler) GlobalCtx
deprecated
func (b *RequestHandler) GlobalCtx() map[string]interface{}
GlobalCtx Returns global template context.
Deprecated: use handler.App().Context instead
func (*RequestHandler) Head ¶
func (r *RequestHandler) Head()
Head implements IRequestHandler Method - default "not found".
func (*RequestHandler) Options ¶
func (r *RequestHandler) Options()
Options implements IRequestHandler Method - default "not found".
func (*RequestHandler) Patch ¶
func (r *RequestHandler) Patch()
Patch implements IRequestHandler Method - default "not found".
func (*RequestHandler) Post ¶
func (r *RequestHandler) Post()
Post implements IRequestHandler Method - default "not found".
func (*RequestHandler) Put ¶
func (r *RequestHandler) Put()
Put implements IRequestHandler Method - default "not found".
func (*RequestHandler) Redirect ¶
func (r *RequestHandler) Redirect(uri string)
Redirect will redirect client to uri using http.StatusSeeOther.
func (*RequestHandler) RedirectWithStatus ¶
func (r *RequestHandler) RedirectWithStatus(uri string, status int)
RedirectWithStatus will redirect client to uri using given status.
func (*RequestHandler) Render ¶
func (r *RequestHandler) Render(file string, ctx map[string]interface{}) error
Render calls assigned template engine Render method. This method copies globalCtx and write ctx inside. So, contexts are not overriden, it only merge 2 context in a new one that is passed to template.
func (*RequestHandler) Status ¶
func (r *RequestHandler) Status(status int)
Status write int status to header (use htt.StatusXXX as status).
func (*RequestHandler) Trace ¶
func (r *RequestHandler) Trace()
Trace implements IRequestHandler Method - default "not found".
func (*RequestHandler) Write ¶
func (r *RequestHandler) Write(data []byte) (int, error)
Write is an alias to RequestHandler.Request.Write. That implements io.Writer.
func (*RequestHandler) WriteJSON ¶
func (r *RequestHandler) WriteJSON(data interface{}) (int, error)
WriteJSON converts data to json then send bytes. This methods set content-type to application/json (RFC 4627)
func (*RequestHandler) WriteString ¶
func (r *RequestHandler) WriteString(data string) (int, error)
WriteString is converts param to []byte then use Write method.
type SessionEngineOptions ¶
type SessionEngineOptions map[string]interface{}
SessionEngineOptions set options for session engine.
type SessionStore ¶
type SessionStore interface { // Init is called when store is initialized while App is initialized Init() // Name should set the session name Name(string) // SetOptions set some optionnal values to session engine SetOptions(SessionEngineOptions) // SetSecret should register a string to encode cookie (not mandatory // but you should implement this to respect interface) SetSecret([]byte) // Get a value from storage , interface param is the key Get(WebHandler, interface{}) (interface{}, error) // Set a value in the storage, first interface param is the key, // second interface is the value to store Set(WebHandler, interface{}, interface{}) // Clean, should cleanup files Clean(WebHandler) }
SessionStore to implement to give a session storage
type Template ¶
type Template interface { // Render method to implement to compile and run template // then write to RequestHandler "w" that is a io.Writer. Render(w io.Writer, template string, ctx interface{}) error // SetTemplateDir should set the template base directory SetTemplateDir(string) // SetOptions pass TplOptions to template engine SetTemplateOptions(TplOptions) }
Template should be implemented by other template implementation to allow RequestHandlers to use Render() method
type TplOptions ¶
type TplOptions map[string]interface{}
TplOptions are template options to pass to template engines if needed
type WSHandler ¶
type WSHandler interface { OnConnect() error OnClose() error GetConnection() *websocket.Conn Close() // contains filtered or unexported methods }
WSHandler is the base interface to implement to be able to use Websocket.
type WSJsonHandler ¶
type WSJsonHandler interface {
OnJSON(interface{}, error)
}
WSJsonHandler interface, framework will read socket and call OnJSON each time a json message is received.
type WSServerHandler ¶
type WSServerHandler interface {
Serve()
}
WSServerHandler interface to serve continuously.
type WSStringHandler ¶
WSStringHandler interface, framework will read socket and call OnMessage() each time a string is received.
type WebHandler ¶
type WebHandler interface { App() *App Request() *http.Request Response() http.ResponseWriter GetSession(interface{}) (interface{}, error) SetSession(interface{}, interface{}) Init() (status int, message error) Destroy() URL(...string) (*url.URL, error) // contains filtered or unexported methods }
WebHandler is the main handler interface that every handler sould implement.
type WebSocketHandler ¶
type WebSocketHandler struct { BaseHandler // contains filtered or unexported fields }
WebSocketHandler type to compose a web socket handler. To use it, compose a handler with this type and implement one of OnJSON(), OnMessage() or Serve() method. Example:
type Example_WebSocketHandler struct{ WebSocketHandler } func (m *Example_WebSocketHandler) OnJSON(i interface{}, err error) { if err != nil { m.SendJSON(map[string]string{ "error": err.Error(), }) return } m.SendJSON(map[string]interface{}{ "greeting": "Hello !", "data": i, }) }
Previous example send back the message + a greeting message
func (*WebSocketHandler) Close ¶
func (ws *WebSocketHandler) Close()
Close connection after having removed handler from the rooms stack.
func (*WebSocketHandler) GetConnection ¶
func (ws *WebSocketHandler) GetConnection() *websocket.Conn
GetConnection returns the websocket client connection.
func (*WebSocketHandler) OnClose ¶
func (ws *WebSocketHandler) OnClose() error
OnClose is called when a client connection is closed.
func (*WebSocketHandler) OnConnect ¶
func (ws *WebSocketHandler) OnConnect() error
OnConnect is called when a client connection is opened.
func (*WebSocketHandler) SendJSON ¶
func (ws *WebSocketHandler) SendJSON(i interface{}) error
SendJSON send interface "i" in json form to the current client.
func (*WebSocketHandler) SendJSONToAll ¶
func (ws *WebSocketHandler) SendJSONToAll(i interface{})
SendJSONToAll send the interface "i" in json form to the entire client list.
func (*WebSocketHandler) SendJSONToRoom ¶
func (ws *WebSocketHandler) SendJSONToRoom(room string, i interface{})
SendJSONToRoom send the interface "i" in json form to the client connected to the the room named "name".
func (*WebSocketHandler) SendJSONToThisRoom ¶
func (ws *WebSocketHandler) SendJSONToThisRoom(i interface{})
SendJSONToThisRoom send interface "i" in json form to the client connected to the same room of the current client connection.
func (*WebSocketHandler) SendText ¶
func (ws *WebSocketHandler) SendText(s string) error
SendText send string "s" to the current client.
func (*WebSocketHandler) SendTextToAll ¶
func (ws *WebSocketHandler) SendTextToAll(s string)
SendTextToAll send message "s" to the entire list of connected clients.
func (*WebSocketHandler) SendTextToRoom ¶
func (ws *WebSocketHandler) SendTextToRoom(name, s string)
SendTextToRoom send message "s" to the room named "name".
func (*WebSocketHandler) SendTextToThisRoom ¶
func (ws *WebSocketHandler) SendTextToThisRoom(s string)
SendTextToThisRoom send message s to the room of the current client connection.
func (*WebSocketHandler) Write ¶
func (ws *WebSocketHandler) Write(b []byte) error
func (*WebSocketHandler) WriteJSON ¶
func (ws *WebSocketHandler) WriteJSON(i interface{}) error
WriteJSON is an alias for SendJSON.
func (*WebSocketHandler) WriteString ¶
func (ws *WebSocketHandler) WriteString(m string) error
WriteString is an alias to SendText.