{"id":374,"date":"2026-05-11T09:00:00","date_gmt":"2026-05-11T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-server-sent-events\/"},"modified":"2026-10-10T21:21:19","modified_gmt":"2026-10-10T15:51:19","slug":"go-server-sent-events","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-server-sent-events\/","title":{"rendered":"Go Server-Sent Events: Live Updates Over HTTP"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go Server-Sent Events let a server push live updates to a browser over a plain HTTP connection. In this post, you will learn how the event stream format works and why it is often simpler than WebSockets. Then we will build an order tracker that sends updates to every open page the moment they happen.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This lesson follows on from <a href=\"https:\/\/smitabharat.com\/blog\/go-websockets-chat\/\">Go WebSockets for a real-time chat server<\/a>, so you can compare both tools. We also use channels from <a href=\"https:\/\/smitabharat.com\/blog\/go-channels-examples\/\">Go channels explained with examples<\/a> and the <code>select<\/code> statement from <a href=\"https:\/\/smitabharat.com\/blog\/go-select-statement\/\">the Go select statement lesson<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Are Go Server-Sent Events?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In short, Server-Sent Events, or SSE, is a web standard for one-way streaming from a server to a browser. First, the browser opens a normal GET request. Then the server simply never finishes the response. Instead, it keeps writing small text messages whenever something new happens.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, think of a radio station. You tune in once, and then the station keeps talking. However, you cannot talk back through the radio. Similarly, with SSE the server talks and the browser listens.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The best part is that Go Server-Sent Events need no extra package. In fact, everything comes from <code>net\/http<\/code> in the standard library.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Go Server-Sent Events Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">However, many &#8220;live&#8221; features only need data flowing one way. In those cases, WebSockets add more moving parts than you need. For example, here are typical uses of Go Server-Sent Events.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Order or delivery tracking<\/strong>: the page updates when the status changes, so the customer never refreshes.<\/li>\n\n\n\n<li><strong>Notifications<\/strong>: a new comment or message shows a badge right away.<\/li>\n\n\n\n<li><strong>Live scores and prices<\/strong>: numbers change on screen as soon as the server knows.<\/li>\n\n\n\n<li><strong>Progress bars<\/strong>: a long export job reports 10%, 20% and so on.<\/li>\n\n\n\n<li><strong>AI chat replies<\/strong>: many chat apps stream answers word by word with SSE.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In short, choose Go Server-Sent Events whenever the server talks and the browser mostly listens.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Go Server-Sent Events Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">First, the browser creates an <code>EventSource<\/code> that points at a URL. Next, the server answers with the header <code>Content-Type: text\/event-stream<\/code> and keeps the connection open. Then, every time there is news, the server writes a few text lines followed by a blank line. Finally, the browser fires an event for each block it receives.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-diagram-1-1024x640.png\" alt=\"Go Server-Sent Events diagram showing one open GET request carrying a stream of text events\" class=\"wp-image-349\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">The browser opens one GET request, and the server keeps it open, writing a new text event block each time something changes.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Also, the browser handles reconnects for you. If the connection drops, <code>EventSource<\/code> waits a moment and connects again. Also, the last event ID travels in a <code>Last-Event-ID<\/code> header, so the server can resend anything the user missed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Event Stream Format<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In the stream, each message is plain text. So every line has a field name, a colon and a value. Then a blank line ends the message. This table shows the fields you can use.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Field<\/th><th>Example<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td><code>data<\/code><\/td><td><code>data: {\"order\":1042}<\/code><\/td><td>The message body, often JSON<\/td><\/tr><tr><td><code>event<\/code><\/td><td><code>event: order<\/code><\/td><td>A custom event name for the browser<\/td><\/tr><tr><td><code>id<\/code><\/td><td><code>id: 7<\/code><\/td><td>An ID the browser remembers for reconnects<\/td><\/tr><tr><td><code>retry<\/code><\/td><td><code>retry: 3000<\/code><\/td><td>Wait time in milliseconds before reconnecting<\/td><\/tr><tr><td><code>:<\/code> comment<\/td><td><code>: keep-alive<\/code><\/td><td>Ignored by the browser, useful as a heartbeat<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">For instance, one complete message looks like this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>id: 1\nevent: order\ndata: {\"order\":1042,\"status\":\"paid\"}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Clearly, the empty line at the end matters. Without it, the browser keeps waiting and never fires the event.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Server-Sent Events vs WebSockets<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Both tools deliver live data. However, they solve slightly different problems. The table below compares them.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Server-Sent Events<\/th><th>WebSockets<\/th><\/tr><\/thead><tbody><tr><td>Direction<\/td><td>Server to browser only<\/td><td>Both ways<\/td><\/tr><tr><td>Protocol<\/td><td>Plain HTTP<\/td><td>Upgrade to a new protocol<\/td><\/tr><tr><td>Extra Go package<\/td><td>None<\/td><td>Usually one<\/td><\/tr><tr><td>Auto reconnect<\/td><td>Built into the browser<\/td><td>You write it yourself<\/td><\/tr><tr><td>Data type<\/td><td>Text only<\/td><td>Text or binary<\/td><\/tr><tr><td>Works with HTTP tools and proxies<\/td><td>Yes, easily<\/td><td>Needs upgrade support<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-diagram-2-1024x640.png\" alt=\"Server-Sent Events vs WebSockets diagram comparing direction, protocol and reconnects\" class=\"wp-image-350\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">SSE sends events one way over normal HTTP with automatic reconnects, while WebSockets carry messages both ways after an upgrade.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So when should you use which? Pick Server-Sent Events for feeds, alerts and progress updates. On the other hand, pick WebSockets for chat, games and other features where the browser also sends a lot.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hands-On: Build a Live Order Tracker<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s build a small service with Go Server-Sent Events. A <code>POST \/publish<\/code> request announces an order update, and every browser connected to <code>GET \/events<\/code> receives it instantly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: A Broker for Subscribers<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here, the broker keeps one channel per connected browser. As a result, publishing a message means sending it into every channel.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Broker keeps one channel per connected client.\ntype Broker struct {\n\tmu      sync.Mutex\n\tclients map[chan string]struct{}\n}\n\nfunc NewBroker() *Broker {\n\treturn &amp;Broker{clients: make(map[chan string]struct{})}\n}\n\nfunc (b *Broker) subscribe() chan string {\n\tch := make(chan string, 10)\n\tb.mu.Lock()\n\tb.clients[ch] = struct{}{}\n\tb.mu.Unlock()\n\treturn ch\n}\n\nfunc (b *Broker) unsubscribe(ch chan string) {\n\tb.mu.Lock()\n\tdelete(b.clients, ch)\n\tb.mu.Unlock()\n}\n\nfunc (b *Broker) publish(msg string) {\n\tb.mu.Lock()\n\tdefer b.mu.Unlock()\n\tfor ch := range b.clients {\n\t\tselect {\n\t\tcase ch &lt;- msg:\n\t\tdefault: \/\/ client is too slow, skip this message\n\t\t}\n\t}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Notice that each channel has a buffer of 10 messages. Also, the <code>select<\/code> with a <code>default<\/code> case never blocks. So if one browser falls behind, the broker skips it instead of freezing everyone else.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: The Event Stream Handler<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This handler sets the SSE headers and subscribes to the broker. After that, it writes events until the browser leaves.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func (b *Broker) events(w http.ResponseWriter, r *http.Request) {\n\tw.Header().Set(\"Content-Type\", \"text\/event-stream\")\n\tw.Header().Set(\"Cache-Control\", \"no-cache\")\n\tw.Header().Set(\"Connection\", \"keep-alive\")\n\n\trc := http.NewResponseController(w)\n\trc.SetWriteDeadline(time.Time{}) \/\/ no write timeout for this stream\n\n\tch := b.subscribe()\n\tdefer b.unsubscribe(ch)\n\n\tfmt.Fprint(w, \"retry: 3000\\n\\n\")\n\trc.Flush()\n\n\tid := 0\n\tfor {\n\t\tselect {\n\t\tcase &lt;-r.Context().Done():\n\t\t\tlog.Println(\"client disconnected\")\n\t\t\treturn\n\t\tcase msg := &lt;-ch:\n\t\t\tid++\n\t\t\tfmt.Fprintf(w, \"id: %d\\nevent: order\\ndata: %s\\n\\n\", id, msg)\n\t\t\tif err := rc.Flush(); err != nil {\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s look at the important lines. First, <code>http.NewResponseController<\/code> gives access to <code>Flush<\/code>, which pushes the bytes to the browser right away. Without it, Go would hold them in a buffer. Next, <code>SetWriteDeadline(time.Time{})<\/code> removes the server&#8217;s write timeout for this one request. Then <code>r.Context().Done()<\/code> fires when the browser closes the tab, so the loop ends and the deferred <code>unsubscribe<\/code> runs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Publishing and Starting the Server<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, we add a tiny publish endpoint and start the server with a normal write timeout.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func (b *Broker) publishHandler(w http.ResponseWriter, r *http.Request) {\n\tb.publish(r.FormValue(\"msg\"))\n\tfmt.Fprintln(w, \"sent\")\n}\n\nfunc main() {\n\tb := NewBroker()\n\tmux := http.NewServeMux()\n\tmux.HandleFunc(\"GET \/events\", b.events)\n\tmux.HandleFunc(\"POST \/publish\", b.publishHandler)\n\tsrv := &amp;http.Server{Addr: \":8080\", Handler: mux, WriteTimeout: 10 * time.Second}\n\tlog.Println(\"SSE server on :8080\")\n\tlog.Fatal(srv.ListenAndServe())\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Test It with curl<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">First, open one terminal and listen to the stream. The <code>-N<\/code> flag turns off curl&#8217;s buffering, so lines appear as they arrive.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -N localhost:8080\/events<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then, in a second terminal, publish two updates.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -X POST -d 'msg={\"order\":1042,\"status\":\"paid\"}' localhost:8080\/publish\ncurl -X POST -d 'msg={\"order\":1043,\"status\":\"shipped\"}' localhost:8080\/publish<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first terminal now shows the full stream, exactly as the server wrote it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>retry: 3000\n\nid: 1\nevent: order\ndata: {\"order\":1042,\"status\":\"paid\"}\n\nid: 2\nevent: order\ndata: {\"order\":1043,\"status\":\"shipped\"}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We ran this test and the stream stayed open well past the 10 second <code>WriteTimeout<\/code>. However, when we removed the <code>SetWriteDeadline<\/code> line, curl stopped after exactly 10 seconds with a partial transfer error. So that one line really matters.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Listen in the Browser<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In a web page, <code>EventSource<\/code> does the reading and reconnecting for you, so the code stays short.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;ul id=\"orders\"&gt;&lt;\/ul&gt;\n&lt;script&gt;\n  const es = new EventSource(\"\/events\");\n  es.addEventListener(\"order\", (e) =&gt; {\n    const order = JSON.parse(e.data);\n    const li = document.createElement(\"li\");\n    li.textContent = \"Order \" + order.order + \" is \" + order.status;\n    document.getElementById(\"orders\").appendChild(li);\n  });\n&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Because our server sends <code>event: order<\/code>, the page listens with <code>addEventListener(\"order\", ...)<\/code>. By contrast, messages without an <code>event<\/code> line arrive in <code>es.onmessage<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Resuming After a Reconnect<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When the network drops, the browser reconnects on its own. Then it sends the last ID it saw in the <code>Last-Event-ID<\/code> request header. As a result, your handler can send only the events the user missed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func lastEventID(r *http.Request) int {\n\tn, err := strconv.Atoi(r.Header.Get(\"Last-Event-ID\"))\n\tif err != nil {\n\t\treturn 0 \/\/ first visit, or no ID yet\n\t}\n\treturn n\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For example, say the browser reports ID 41. Then you load events 42 and later from your database and send them first. After that, the handler switches to live events as usual. In our tracker, IDs start again at 1 for each connection. So a real app should use IDs that come from the database.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Scaling Go Server-Sent Events<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Each open stream is one goroutine and one channel, which is cheap in Go. So a single small server can hold thousands of listeners. However, our broker lives in memory, just like the chat hub in the WebSockets post.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Therefore, if you run several servers, an update published on one server never reaches browsers on another. The fix is the same as before. Each server subscribes to a shared message system and forwards messages to its own Go Server-Sent Events clients.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Go Server-Sent Events<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Forgetting to flush<\/strong>: events sit in a buffer and appear in bursts. So call <code>Flush<\/code> after every message.<\/li>\n\n\n\n<li><strong>Leaving the write timeout on<\/strong>: the stream dies after the server&#8217;s <code>WriteTimeout<\/code>. Clear it per request with <code>SetWriteDeadline(time.Time{})<\/code>.<\/li>\n\n\n\n<li><strong>Missing the blank line<\/strong>: the browser never fires the event. Always end each message with <code>\\n\\n<\/code>.<\/li>\n\n\n\n<li><strong>Ignoring the request context<\/strong>: closed tabs leave goroutines running forever. Watch <code>r.Context().Done()<\/code> in the loop.<\/li>\n\n\n\n<li><strong>Blocking on slow clients<\/strong>: one stuck browser freezes every publish. Use buffered channels with a <code>default<\/code> case.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Go Server-Sent Events<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Send JSON in the data field<\/strong>, because it keeps messages easy to parse in JavaScript.<\/li>\n\n\n\n<li>**Set an <code>id<\/code> on every event**, so reconnecting browsers can ask for what they missed.<\/li>\n\n\n\n<li><strong>Send a comment line every 30 seconds<\/strong>, as some proxies close quiet connections.<\/li>\n\n\n\n<li><strong>Use HTTP\/2 in production<\/strong>, since browsers limit HTTP\/1.1 to about six connections per site.<\/li>\n\n\n\n<li><strong>Keep messages small<\/strong>, and send IDs or links rather than whole records.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To practise Go Server-Sent Events, add a heartbeat to the handler. Every 15 seconds, write the comment line <code>: ping<\/code> followed by a blank line, even when no orders arrive.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hint: create a <code>time.Ticker<\/code> and add one more <code>case<\/code> to the <code>select<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These pages explain the exact API and the event stream rules, so keep them close while you build.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pkg.go.dev\/net\/http#ResponseController\">net\/http: ResponseController<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Server-sent_events\/Using_server-sent_events\">MDN: Using server-sent events<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/html.spec.whatwg.org\/multipage\/server-sent-events.html\">HTML standard: Server-sent events<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go Server-Sent Events stream updates from server to browser over plain HTTP.<\/li>\n\n\n\n<li>Each message is text lines like <code>data:<\/code> and <code>id:<\/code>, ended by a blank line.<\/li>\n\n\n\n<li><code>http.NewResponseController<\/code> lets you flush and clear the write deadline.<\/li>\n\n\n\n<li>A broker with one buffered channel per client handles many listeners.<\/li>\n\n\n\n<li>The browser&#8217;s <code>EventSource<\/code> reconnects on its own and resends the last ID.<\/li>\n\n\n\n<li>Use SSE for one-way feeds and WebSockets for two-way features.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">However, our broker only works inside one server process. Next, we will connect many services with a real message system: NATS.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next lesson: <a href=\"https:\/\/smitabharat.com\/blog\/go-nats-messaging\/\">Go NATS Messaging: Publish, Subscribe and Request<\/a><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Go Server-Sent Events let a server push live updates to a browser over a plain HTTP connection. In this post, you will learn how&hellip;<\/p>\n","protected":false},"author":1,"featured_media":348,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[15],"tags":[11,68,23,21],"swapz_series":[],"class_list":["post-374","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-go-lang","tag-go-sse","tag-go-tutorial","tag-golang-basics"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Server-Sent Events: Live Updates Over HTTP<\/title>\n<meta name=\"description\" content=\"Learn Go Server-Sent Events with simple examples: the event stream format, flushing, a broker for many clients and EventSource in the browser.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-server-sent-events\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Server-Sent Events: Live Updates Over HTTP\" \/>\n<meta property=\"og:description\" content=\"Learn Go Server-Sent Events with simple examples: the event stream format, flushing, a broker for many clients and EventSource in the browser.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-server-sent-events\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-05-11T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-10T15:51:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-server-sent-events\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-server-sent-events\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Server-Sent Events: Live Updates Over HTTP\",\"datePublished\":\"2026-05-11T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:51:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-server-sent-events\\\/\"},\"wordCount\":1480,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-server-sent-events\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-server-sent-events-featured.png\",\"keywords\":[\"Go Lang\",\"Go SSE\",\"Go Tutorial\",\"Golang Basics\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-server-sent-events\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-server-sent-events\\\/\",\"name\":\"Go Server-Sent Events: Live Updates Over HTTP\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-server-sent-events\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-server-sent-events\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-server-sent-events-featured.png\",\"datePublished\":\"2026-05-11T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:51:19+00:00\",\"description\":\"Learn Go Server-Sent Events with simple examples: the event stream format, flushing, a broker for many clients and EventSource in the browser.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-server-sent-events\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-server-sent-events\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-server-sent-events\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-server-sent-events-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-server-sent-events-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Server-Sent Events featured image: cards for the event stream, flushing and auto reconnect\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-server-sent-events\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Server-Sent Events: Live Updates Over HTTP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Server-Sent Events: Live Updates Over HTTP","description":"Learn Go Server-Sent Events with simple examples: the event stream format, flushing, a broker for many clients and EventSource in the browser.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-server-sent-events\/","og_locale":"en_US","og_type":"article","og_title":"Go Server-Sent Events: Live Updates Over HTTP","og_description":"Learn Go Server-Sent Events with simple examples: the event stream format, flushing, a broker for many clients and EventSource in the browser.","og_url":"https:\/\/smitabharat.com\/blog\/go-server-sent-events\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-05-11T03:30:00+00:00","article_modified_time":"2026-10-10T15:51:19+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-server-sent-events\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-server-sent-events\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Server-Sent Events: Live Updates Over HTTP","datePublished":"2026-05-11T03:30:00+00:00","dateModified":"2026-10-10T15:51:19+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-server-sent-events\/"},"wordCount":1480,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-server-sent-events\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-featured.png","keywords":["Go Lang","Go SSE","Go Tutorial","Golang Basics"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-server-sent-events\/","url":"https:\/\/smitabharat.com\/blog\/go-server-sent-events\/","name":"Go Server-Sent Events: Live Updates Over HTTP","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-server-sent-events\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-server-sent-events\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-featured.png","datePublished":"2026-05-11T03:30:00+00:00","dateModified":"2026-10-10T15:51:19+00:00","description":"Learn Go Server-Sent Events with simple examples: the event stream format, flushing, a broker for many clients and EventSource in the browser.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-server-sent-events\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-server-sent-events\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-server-sent-events\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-server-sent-events-featured.png","width":2400,"height":1260,"caption":"Go Server-Sent Events featured image: cards for the event stream, flushing and auto reconnect"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-server-sent-events\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Server-Sent Events: Live Updates Over HTTP"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/374","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=374"}],"version-history":[{"count":1,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/374\/revisions"}],"predecessor-version":[{"id":384,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/374\/revisions\/384"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/348"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=374"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}