valente

package module
Version: v0.1.6 Latest Latest
Warning

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

Go to latest
Published: May 19, 2020 License: MIT Imports: 5 Imported by: 2

README

valente - websocket for golang webapp

license Godoc Go Report Card wercker status codecov

valente is an experiment with Golang webapp using WebSockets. There are similar solutions in another languages/platform:

  • The Wt WebFramework has an experimental features with all comunications between server and browser using websockets.
  • N2O and Nitrogen are frameworks with that feature coded in Erlang.

The use of asynchronism is mandatory for this solutions. Traditional threads aren't viable, due to high memory consumed for each connection. The Wt Framework is using Boost::asio to handle connections. In Go and Erlang, the languages features should make that scheme simple and scalable. I don't know :)

The valente is based on Nitrogen ideas.

Installing

To start using valente, install Go and run go get:

$ go get github.com/trumae/valente/...

This will retrieve the library and install the valente command line utility into your $GOBIN path.

How to use

$ valente new appsample
$ cd appsample
$ go get
$ go build
$ ./appsample

Access http://localhost:8000/ with your browser for boilerplate demo.

Run Sample

$ cd samples/finance
$ go get
$ go build
$ finance

Access http://localhost:8000/ with your browser and enjoy.

Alt text

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrProtocol is an error of WS Valente protocol
	ErrProtocol = errors.New("Protocol Error")

	//ErrEOFWS end of file of WS
	ErrEOFWS = errors.New("EOF Error")
)

Functions

This section is empty.

Types

type App

type App struct {
	WS          *action.WebSocket
	Forms       map[string]Form
	Data        map[string]interface{}
	CurrentForm Form
	LastAccess  time.Time
}

App is a Web Application representation

func (*App) AddForm

func (app *App) AddForm(name string, f Form)

AddForm add a new form to App

func (*App) GoTo

func (app *App) GoTo(formName string, params []string) error

GoTo replace the current form into app

func (*App) Initialize

func (app *App) Initialize()

Initialize inits the App

func (*App) Run

func (app *App) Run()

Run handle events

func (*App) WebSocket

func (app *App) WebSocket(ws *action.WebSocket)

WebSocket set the WS value

type Form

type Form interface {
	Name() string
	AddEventHandler(evt string, f HandlerFunc) Form
	Run(ws *action.WebSocket, app *App) error
	Initialize(ws *action.WebSocket) Form
	Render(ws *action.WebSocket, app *App, params []string) error
}

Form represents the unit of user interaction

type FormImpl

type FormImpl struct {
	FName string
	// contains filtered or unexported fields
}

FormImpl its a simple Form

func (FormImpl) AddEventHandler

func (form FormImpl) AddEventHandler(evt string, f HandlerFunc) Form

AddEventHandler add an f function to handle evt event

func (FormImpl) Initialize

func (form FormImpl) Initialize(ws *action.WebSocket) Form

Initialize inits the form

func (FormImpl) Name added in v0.1.4

func (form FormImpl) Name() string

Name return the name string

func (FormImpl) Render

func (form FormImpl) Render(ws *action.WebSocket, app *App, params []string) error

Render form start

func (FormImpl) Run

func (form FormImpl) Run(ws *action.WebSocket, app *App) error

Run execs the form

type HandlerFunc

type HandlerFunc func(*action.WebSocket, *App, []string)

HandlerFunc is a function of handle an event received into websocket.Conn

Source Files

Jump to

Keyboard shortcuts

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