Skip to content

Instantly share code, notes, and snippets.

@alexaandru
alexaandru / chi.go
Created February 14, 2024 16:40
Chi-like syntactic sugar layer on top of stdlib http.ServeMux
// Chi-like syntactic sugar layer on top of stdlib http.ServeMux.
package main
import (
"net/http"
"slices"
)
type (
middleware func(http.Handler) http.Handler
@shawwn
shawwn / since2010.md
Created May 11, 2021 09:46
"What happened after 2010?"

This was a response to a Hacker News comment asking me what I've been up to since 2010. I'm posting it here since HN rejects it with "that comment is too long." I suppose that's fair, since this ended up being something of an autobiography.

--

What happened after 2010?

@harlow
harlow / cache.go
Created August 24, 2016 18:23
Golang cache map
package cache
import (
"crypto/sha256"
"encoding/json"
"fmt"
"os"
"sync"
"time"
)
package main
import (
"net/http"
"database/sql"
"fmt"
"log"
"os"
)
@elithrar
elithrar / use.go
Last active April 3, 2025 18:10
go/use: Little middleware chains that could. Inspired by comments here: https://github.com/gorilla/mux/pull/36
r := mux.NewRouter()
// Single handler
r.HandleFunc("/form", use(http.HandlerFunc(formHandler), csrf, logging)
// All handlers
http.Handle("/", recovery(r))
// Sub-routers
apiMiddleware := []func(http.Handler) http.Handler{logging, apiAuth, json}