https://github.com/reddec/run-http-server
Bootstrap for HTTP server
https://github.com/reddec/run-http-server
Last synced: over 1 year ago
JSON representation
Bootstrap for HTTP server
- Host: GitHub
- URL: https://github.com/reddec/run-http-server
- Owner: reddec
- License: mit
- Created: 2021-10-30T11:24:40.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-11-10T14:29:23.000Z (over 4 years ago)
- Last Synced: 2025-03-09T00:06:40.543Z (over 1 year ago)
- Language: Go
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HTTP server bootstrap
Designed for go-flags package but can be used independently.
Motivation: I tired to write the same bootstrap code again and again in my project.
Features:
- native integration with [go-flags](https://github.com/jessevdk/go-flags)
- context-aware: gracefully finished execution when context closed
- supports TLS and Auto-TLS (Let's Encrypt)
## Installation
go get github.com/reddec/run-http-server
## Usage
```go
package main
import (
"context"
"net/http"
"os"
"os/signal"
"github.com/jessevdk/go-flags"
"github.com/reddec/run-http-server"
)
func main() {
var server httpserver.Server
flags.Parse(&server)
http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
writer.Write([]byte("hello world"))
})
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
panic(server.Run(ctx))
}
```