go

go
package listing

import "encoding/base64"

func Encode(name string) string {
	return base64.RawURLEncoding.EncodeToString([]byte(name))

Cursor-Based Directory Listing API in Go with net/http

go pagination cursor
by codesnips 3 tabs
go
package config

import (
	"encoding/json"
	"fmt"
	"time"

Strict JSON Config Loading in Go with DisallowUnknownFields

go json configuration
by codesnips 3 tabs
go
package api

import (
	"encoding/json"
	"net/http"
)

Field-Level JSON Validation Errors in Go net/http Handlers

go net-http validation
by codesnips 3 tabs
go
package config

import (
  "io"

  "gopkg.in/yaml.v3"

Safe YAML decoding (KnownFields) for config files

go config yaml
by Leah Thompson 1 tab
go
package config

import (
	"fmt"
	"os"
	"strconv"

Load Go Configuration From Environment Variables With Typed Defaults

go configuration environment-variables
by codesnips 3 tabs
go
package api

import "strings"

type Issue struct {
  Field   string `json:"field"`

JSON schema-ish validation with custom error details

go api json
by Leah Thompson 1 tab
go
package ratelimit

import (
	"sync"
	"time"
)

Token Bucket Rate-Limiting Middleware for a Go net/http API

go net-http middleware
by codesnips 4 tabs
go
package order

type CreateOrderRequest struct {
	Reference string        `json:"reference" binding:"required,min=3,max=40"`
	Currency  string        `json:"currency" binding:"required,currency"`
	Customer  Customer      `json:"customer" binding:"required"`

Binding and Validating Nested JSON in Gin With Custom Validators

go gin validation
by codesnips 4 tabs
go
package api

import "net/http"

func ETag(w http.ResponseWriter, r *http.Request, etag string) bool {
  w.Header().Set("ETag", etag)

ETag handling for conditional GETs (cheap caching)

go http caching
by Leah Thompson 1 tab
go
package main

import (
	"context"
	"log"
	"net/http"

Graceful HTTP Server Shutdown in Go with SIGINT and Context Cancellation

go http graceful-shutdown
by codesnips 2 tabs
go
package httpmetrics

import "github.com/prometheus/client_golang/prometheus"

var (
	httpRequestDuration = prometheus.NewHistogramVec(

HTTP Latency and Status Code Middleware with Prometheus in Go

go middleware prometheus
by codesnips 3 tabs
go
package middleware

import (
  "net/http"
)

CORS allowlist middleware (no wildcard surprises)

go http security
by Leah Thompson 1 tab