Golang:HTML页面和GO通讯

Is there a way other than templates to communicate between Go and html pages ? Using something like postmessages ?

Scenario ::--> Streaming Twitter Api

Streaming api call, updates with new content as and when available;

Want to update the web page with the latest content, keeping the original content as it is.

Want to avoid using NaCl... As it is only for chrome

You can use websockets (WebSocket@Wikipedia).

Here are 2 implementations:

golang.org/x/net/websocket

github.com/gorilla/websocket

And here is an exhausting list of other websocket packages/implementations:

godoc.org websocket search

Use websockets or server sent events to push events from the server to the browser client.

Use the gorilla/websocket package for websockets. The x/net/websocket package is also available, but it's partial implementation of the protocol does not work with recent versions of Chrome.

Server sent events are so simple that a helper package is not really needed. See this example to get started with server sent events.

It's not about Go. Client side i.e. browser must be capable to handle persistent connection. So nothing new here. You have

  • Long-polling for older browsers
  • Websockets for modern browsers
  • Server-sent-events for tomorrow (to say, excluding IE, them holds even now)
  • Push-services provided by Google and Apple for mobile platforms

Either technics can be easily implemented with Go on server side. Nothing tricky.

为什么都喜欢用英文。。。。。