项目作者: dadamssolutions

项目描述 :
Adapters to add middleware to HTTP Handlers
高级语言: Go
项目地址: git://github.com/dadamssolutions/adaptd.git
创建时间: 2018-09-16T05:30:17Z
项目社区:https://github.com/dadamssolutions/adaptd

开源协议:MIT License

下载


adaptd

Go Report Card GoDoc

Adapters to add middleware to HTTP Handlers.

Installing

Use go get:

  1. go get github.com/dadamssolutions/adaptd

Or, in go.mod:

  1. require (
  2. github.com/dadamssolutions/adaptd
  3. )

Examples

  1. import (
  2. "net/http"
  3. "github.com/dadamssolutions/adaptd"
  4. )
  5. func main() {
  6. // Index handler should enure that HTTPS is used
  7. http.Handle("/", adaptd.EnsureHTTPS(false)(indexHandler))
  8. // Login handler should use HTTPS and handle GET and POST requests
  9. // Use Adapt to add multiple Adapters at once.
  10. // Be sure to check HTTPS first.
  11. loginHandler = adaptd.Adapt(loginHandler,
  12. adaptd.EnsureHTTPS(false),
  13. adaptd.GetAndOtherRequest(loginPostHandler, http.MethodPost))
  14. http.Handle("/login", loginHandler)
  15. http.ListenAndServeTLS(":8080", "cert.pem", "key.pem", nil)
  16. }

Contributing

Submit a pull request.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details

Acknowledgments

  • @matryer/writing-middleware-in-golang-and-how-go-makes-it-so-much-fun-4375c1246e81">Mat Ryer