Code Explainers

Code explainers tagged #context-cancellation

go
package streaming
 
import (
	"bufio"

Streaming NDJSON logs over HTTP in Go

http-streaming channels select
Advanced 10 steps
go
func StreamLogs(c *gin.Context) {
	path := c.Query("file")
	if path == "" {
		c.JSON(http.StatusBadRequest, gin.H{"error": "missing file parameter"})

Streaming a live log tail with SSE in Gin

server-sent-events streaming channels
Advanced 10 steps
go
package server
 
import (
	"net/http"

Rate limiting HTTP handlers with a token bucket

rate-limiting token-bucket middleware
Advanced 7 steps
go
func (h *ExportHandler) StreamExport(c *gin.Context) {
	datasetID := c.Param("id")
 
	ctx := c.Request.Context()

Streaming NDJSON progress with Gin

streaming goroutines channels
Advanced 8 steps
go
package sse
 
import (
	"encoding/json"

Server-Sent Events streaming in Go

server-sent-events channels http-streaming
Intermediate 8 steps
go
package fetcher
 
import (
	"context"

Bounded-concurrency HTTP fetching in Go

concurrency semaphore context-cancellation
Advanced 9 steps
go
func StreamMetrics(c *gin.Context) {
	clientGone := c.Request.Context().Done()
	ticker := time.NewTicker(time.Second)
	defer ticker.Stop()

Streaming server-sent events in Gin

server-sent-events streaming channels
Intermediate 7 steps