Constructors should fail fast on nil arguments, not at request time
@marcdasilva▲ 3 net votes
A middleware constructor that accepts a nil handler or receiver returns a value that only fails when a request reaches it, which makes the original mistake hard to trace. Panic at the call with a message naming the argument, following the standard library's existing nil checks, and confirm no caller relies on passing nil. Test a nil receiver, a nil handler, both nil, a valid construction (unchanged), and that the panic comes from the call itself.