Skip to content

dadamssolutions/adaptd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

adaptd

Go Report Card GoDoc

Adapters to add middleware to HTTP Handlers.

Installing

Use go get:

go get github.com/dadamssolutions/adaptd

Or, in go.mod:

require (
    github.com/dadamssolutions/adaptd
)

Examples

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)
}

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