Created
August 30, 2018 15:19
-
-
Save iMega/407a3a8ae7241e11aadcf87ffd501150 to your computer and use it in GitHub Desktop.
best practice append
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A constructor for a piece of middleware. | |
// Some middleware use this constructor out of the box, | |
// so in most cases you can just pass somepackage.New | |
type Constructor func(http.Handler) http.Handler | |
// Chain acts as a list of http.Handler constructors. | |
// Chain is effectively immutable: | |
// once created, it will always hold | |
// the same set of constructors in the same order. | |
type Chain struct { | |
constructors []Constructor | |
} | |
// New creates a new chain, | |
// memorizing the given list of middleware constructors. | |
// New serves no other function, | |
// constructors are only called upon a call to Then(). | |
func New(constructors ...Constructor) Chain { | |
return Chain{append(([]Constructor)(nil), constructors...)} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment