Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package goexperiments
import (
type HandlerMiddleware interface {
HandleHTTPC(ctx context.Context, rw http.ResponseWriter, req *http.Request, next http.Handler)
var function1 HandlerMiddleware = nil
var function2 HandlerMiddleware = nil
func makeChain(chain ...HandlerMiddleware) http.Handler {return nil}
type AddUserID struct {
OnUserID func(userID string) http.Handler
func (a *AddUserID) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
userID := req.Header.Get("userid")
a.OnUserID(userID).ServeHTTP(rw, req)
type UseUserID struct {
UserID string
func (u *UseUserID) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
type ServerNoAbuseContext struct{}
func (s *ServerNoAbuseContext) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
req = req.WithContext(context.Background())
chainWithAuth := func(userID string) http.Handler {
return makeChain(function1, function2, &UseUserID{
UserID: userID,
chainPartOne := &AddUserID{
OnUserID: chainWithAuth,
chainPartOne.ServeHTTP(rw, req)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.