examples/

directory
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: MIT

README

Golongpoll Examples

These instructions assume you are running them from within the ./examples directory. Note the -clientJs flag sent to many of these examples. This is used to tell the http server where to find the static js-client/client.js file.

Chatbot

This example demonstrates using both the javascript and go clients to create a dummy chatbot app. The webpage uses the javascript client while the go webserver spins up a goroutine that uses the go client to subscribe to messages sent by the webpage and respond (publish) with response messages.

To Build:

go build -o chatbot_example chatbot/chatbot.go

Note that we rename the output chatbot_example since there's already a folder called chatbot

To Run:

./chatbot_example -clientJs ../js-client/client.js

Then visit: http://127.0.0.1:8101/chatbot

FilePersist

In this example, you can publish events via webpage and they'll be saved to file via the FilePersistorAddOn. Test this out by publishing some events, then kill the program, restart and observe the events still show up.

To Build:

go build -o filepersist_example filepersist/filepersist.go

To Run:

./filepersist_example -clientJs ../js-client/client.js -persistTo ./filepersist_example.data

Then visit: http://127.0.0.1:8102/filepersist

Stressor

A simple server that shows published events on a given category and command line client(s) to stress the server via the longpoll manager's publish HTTP handler.

Server

To Build:

go build -o stressor_server stressor/server/main.go

To Run:

./stressor_server -clientJs ../js-client/client.js -serve "127.0.0.1:8080" -category test123

Then visit: http://127.0.0.1:8080/

Client

To Build:

go build -o stressor_client stressor/client/main.go

To Run:

./stressor_client -publishUrl "http://127.0.0.1:8080/publish" -category test123 -delayMs 100 -count 1000

Authentication

Shows how LongpollManager.SubscriptionHandler and LongpollManager.PublishHandler can be wrapped to require authentication. The javascript and golang clients can be configured to supply HTTP basic auth or HTTP headers containing auth data.

To Build:

go build -o auth_example authentication/auth.go

To Run:

./auth_example -clientJs ../js-client/client.js -serve "127.0.0.1:8080"

Then visit the HTTP address passed to -serve, in this case: http://127.0.0.1:8080

microchat

Simple dummy chat server that uses the standard publish/subscribe hooks.

To Build:

go build -o microchat_example microchat/microchat.go

To Run:

./microchat_example -clientJs ../js-client/client.js -serve "127.0.0.1:8080"

Then visit http://127.0.0.1:8080/ in multiple browsers to chat.

Directories

Path Synopsis
Provides example of how one can wrap SubscriptionHandler and PublishHandler to provide authentication.
Provides example of how one can wrap SubscriptionHandler and PublishHandler to provide authentication.
This example creates a dummy chatbot while demonstrating the following features: 1) Golang client used by the trivial chatbot 2) Javascript client used by UI.
This example creates a dummy chatbot while demonstrating the following features: 1) Golang client used by the trivial chatbot 2) Javascript client used by UI.
This example uses the FilePersistorAddOn to persist event data to file, allowing us to retain events across multiple program runs.
This example uses the FilePersistorAddOn to persist event data to file, allowing us to retain events across multiple program runs.
Super simple chat server with some pre-defined rooms and login-less posting using display names.
Super simple chat server with some pre-defined rooms and login-less posting using display names.
stressor

Jump to

Keyboard shortcuts

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