advanced

command
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

This is a more advanced example that shows a few more possibilities when using golongpoll.

In this example, we'll demonstrate publishing events via http handlers and also adding additional logic/validation on top of the LongpollManager's SubscriptionHandler function.

To run this example:

go build examples/advanced/advanced.go

Then run the binary and visit http://127.0.0.1:8081/advanced Try clicking the action button with a variety of different actions and toggle whether or not they are public or private. Then switch to other users and do the same. Observe what you see. Better yet, have multiple browser windows open and click from the different users and observe.

Noteworthy things going on in this example:

  • Event payloads are an actual json object, not a plain string.

  • we use closures to capture the LongpollManager to support calling Publish() from an http handler, and to wrap the SubscriptionHandler with our own logic. This is safe to have random http handlers calling functions on LongpollManager because the manager's data members are all channels which are made for sharing.

  • The html and javascript is not the prettiest :-P

Jump to

Keyboard shortcuts

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