Adapters to add middleware to HTTP Handlers
Adapters to add middleware to HTTP Handlers.
Use go get
:
go get github.com/dadamssolutions/adaptd
Or, in go.mod
:
require (
github.com/dadamssolutions/adaptd
)
import (
"net/http"
"github.com/dadamssolutions/adaptd"
)
func main() {
// Index handler should enure that HTTPS is used
http.Handle("/", adaptd.EnsureHTTPS(false)(indexHandler))
// Login handler should use HTTPS and handle GET and POST requests
// Use Adapt to add multiple Adapters at once.
// Be sure to check HTTPS first.
loginHandler = adaptd.Adapt(loginHandler,
adaptd.EnsureHTTPS(false),
adaptd.GetAndOtherRequest(loginPostHandler, http.MethodPost))
http.Handle("/login", loginHandler)
http.ListenAndServeTLS(":8080", "cert.pem", "key.pem", nil)
}
Submit a pull request.
We use SemVer for versioning. For the versions available, see the tags on this repository.
This project is licensed under the MIT License - see the LICENSE file for details