kwiscale

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2016 License: BSD-3-Clause Imports: 22 Imported by: 2

README

kwiscale

Build Status Coverage Status Documentation Status GoDoc

Web Middleware for Golang

At this time, Kwiscale is at the very begining of developpement. But you can test and give'em some pull-request to improve it.

Features

  • Implement your handlers as structs with HTTP Verbs as method
  • Plugin system for template engines, session engines and ORM
  • Use gorilla to manipulate routes and mux
  • Handler spawned with concurrency

How to use

Install with "go get" command:

go get gopkg.in/kwiscale/framework.v1

Create a project:

mkdir ~/myproject && cd ~/myproject

The common way to create handlers is to append a package::

mkdir handlers
vim handlers/index.go

Let's try an example:

package handlers

import "gopkg.in/kwiscale/framework.v1"

// this is the Index Handler that
// is composed by a RequestHandler
type IndexHandler struct {
    // compose your handler with kwiscale.Handler
    kwiscale.RequestHandler
}

// Will respond to GET request. "params" are url params (not GET and POST data)
func (i *IndexHandler) Get () {
    i.WriteString("Hello !" + i.Vars["userid"])
}

Then in you main.go::


package main

import (
    "gopkg.in/kwiscale/framework.v1"
    "./handlers"
)

// HomeHandler
type HomeHandler struct {
	kwiscale.RequestHandler
}

// Get respond to GET request
func (h *HomeHandler) Get (){
	h.WriteString("reponse to GET home")
}

// Another handler
type OtherHandler struct {
	kwiscale.RequestHandler
}

func (o *OtherHandler) Get (){
	// read url params
	// it always returns a string !
	userid := o.Vars["userid"]
	o.WriteString(fmt.Printf("Hello user %s", userid))
}


func main() {
	kwiscale.DEBUG = true
	app := kwiscale.NewApp(&kswicale.Config{
        Port: ":8000",
    })
	app.AddRoute("/", HomeHandler{})
	app.AddRoute("/user/{userid:[0-9]+}", OtherHandler{})
    app.ListenAndServe()

    // note: App respects http.Mux so you can use:
    // http.ListenAndServe(":9999", app)
    // to override behaviors, testing, or if your infrastructure
    // restricts this usage
}

Then run:

go run main.go

Or build your project:

go build main.go
./main

The Kwiscale way ?

Kwiscale let you declare Handler methods with the HTTP method. This allows you to declare:

  • Get()
  • Post()
  • Head()
  • Delete()
  • Put()
  • Patch()

Basic Templates

Kwiscale provides a "basic" template engine that use http/template. Kwiscale only add a "very basic template override system".

If you plan to have a complete override system, please use http://gopkg.in/kwiscale/template-pongo2.v1 that implements pango2 template.

See the following example.

Append templates directory:

mkdir templates

Then create templates/main.html:

<!DOCTYPE html>
<html>
    <head>
        <title>{{ if .title }}{{.title}}{{ else }} Default title {{ end }}</title>
    </head>
    <body>
        {{/* Remember to use "." as context */}}
        {{ template "CONTENT" . }}
    </body>
</html>

Now create templates/home directory:

mkdir templates/home

Create templates/home/welcome.html:

{{/* override "main.html" */}}

{{ define "CONTENT" }}
    This the welcome message {{ .msg }}
{{ end }}

This template overrides "main.html" (in ./templates/ directory) and append "CONTENT" template definition. So, the "CONTENT" block will appear at template "CONTENT" in "main.html". That's all.

In handlers/index.go you may now ask for template rendering:

func (h *IndexHandler) Get() {
    h.Render("home/welcome.html", map[string]string{
        "title" : "Welcome !!!",
        "msg"   : "Hello you",
    })
}

You can override template directory using App configuration passed to the constructor:

app := kwiscale.NewApp(&kswiscale.Config{
    TemplateDir: "./my-template-dir",
})

TODO

Features in progress:

  • Database ORM interface
  • Custom Error handler

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

See http://readthedocs.org/projects/kwiscale/

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound error type.
	ErrNotFound = errors.New("Not found")
	// ErrNotImplemented error type.
	ErrNotImplemented = errors.New("Not implemented")
	// ErrInternalError for internal error.
	ErrInternalError = errors.New("Internal server error")
)

Functions

func Error

func Error(v ...interface{})

Error prints error on STDOUT.

func Log

func Log(v ...interface{})

Log print logs on STDOUT if debug is activated.

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

func RegisterTemplateEngine(name string, tpl Template)

RegisterTemplateEngine records template engine that implements Template interface. The name is used to let config select the template engine.

func SetDebug

func SetDebug(mode bool)

SetDebug changes debug mode.

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 NewApp

func NewApp(config *Config) *App

NewApp Create new *App - App constructor.

func NewAppFromConfigFile

func NewAppFromConfigFile(filename ...string) *App

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

func (app *App) GetRoute(name string) *mux.Route

GetRoute return the *mux.Route that have the given name.

func (*App) GetRoutes

func (app *App) GetRoutes(name string) []*mux.Route

GetRoutes get all routes for a handler

func (*App) GetTemplate

func (app *App) GetTemplate() Template

GetTemplate returns a new instance of Template.

func (*App) ListenAndServe

func (app *App) ListenAndServe(port ...string)

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.

func (*App) SetStatic

func (app *App) SetStatic(prefix string)

SetStatic set the route "prefix" to serve files configured in Config.StaticDir

func (*App) SoftStop

func (app *App) SoftStop() chan int

SoftStop stops each handler manager goroutine (useful for testing).

type BaseHandler

type BaseHandler struct {
	Vars map[string]string
	// contains filtered or unexported fields
}

BaseHandler is the parent struct of every Handler. Implement WebHandler.

func (*BaseHandler) App

func (b *BaseHandler) App() *App

App returns the current application.

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".

func (*BaseHandler) URL added in v1.0.3

func (b *BaseHandler) URL(s ...string) (*url.URL, error)

URL return an url based on the declared route and given string pair.

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

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

func (dh *ErrorHandler) Get()

Get shows a standard error in HTML.

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

type WSStringHandler interface {
	OnMessage(int, string, error)
}

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.

Directories

Path Synopsis
Kwiscale command line interface.
Kwiscale command line interface.

Jump to

Keyboard shortcuts

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