https://github.com/nelkinda/http-go
Making http even more useful
https://github.com/nelkinda/http-go
go golang http http-headers https mimetypes
Last synced: about 1 month ago
JSON representation
Making http even more useful
- Host: GitHub
- URL: https://github.com/nelkinda/http-go
- Owner: nelkinda
- License: mit
- Created: 2019-03-09T07:59:39.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-02-25T02:10:31.000Z (almost 3 years ago)
- Last Synced: 2024-06-21T00:13:33.657Z (over 1 year ago)
- Topics: go, golang, http, http-headers, https, mimetypes
- Language: Go
- Size: 83 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `http-go` - Making http even more useful

## HTTPS
package `https` provides a function to serve HTTPS with Let's Encrypt.
All you need is this package and a mapped hostname, and you're ready to go with just one function call.
The function `MustServeHttps` will
* Configure the Certificate Manager to obtain the certificate from Let's Encrypt.
* Start the HTTPS server in a goroutine based on the `http.ServeMux` provided as argument.
* Start an HTTP server in a goroutine which redirects to HTTPS as well as handles the Let's Encrypt callback.
Because the servers are started in goroutines, the main function now needs to wait for termination.
The `https` package provides a utility function for that.
Example code:
```go
package main
import (
"github.com/nelkinda/http-go/https"
"net/http"
"os"
)
func main() {
mux := createMux()
https.MustServeHttps("myhost.com", mux)
https.WaitForIntOrTerm()
os.Exit(0)
}
func createMux() *http.ServeMux {
mux := http.NewServeMux()
mux.HandleFunc("…", …)
return mux
}
```
This will start an HTTPS server on `myhost.com`, requesting a certificate from Let's Encrypt at the start.
## Headers
package `headers` contains all HTTP headers defined in the HTTP specifications.
## MIME Types
package `mimetypes` contains all MIME Types registered with IANA.