Documentation ¶
Overview ¶
Package http provides a HTTP server which implements the app.Runtime interface.
Index ¶
- type Runtime
- type RuntimeOption
- func Handle(pattern string, h http.Handler) RuntimeOption
- func HandleFunc(pattern string, f func(http.ResponseWriter, *http.Request)) RuntimeOption
- func Http2Only() RuntimeOption
- func ListenOnPort(port uint) RuntimeOption
- func LogHandler(h slog.Handler) RuntimeOption
- func TLSConfig(cfg *tls.Config) RuntimeOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime is a bedrock.Runtime for running a HTTP service.
func NewRuntime ¶
func NewRuntime(opts ...RuntimeOption) *Runtime
NewRuntime returns a fully initialized HTTP runtime.
func (*Runtime) Run ¶
Run implements app.Runtime interface.
Example ¶
rt := NewRuntime( ListenOnPort(8080), HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "Hello, world") }), ) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() go func() { rt.Run(ctx) }() resp, err := http.Get("http://localhost:8080") if err != nil { fmt.Println(err) return } defer resp.Body.Close() b, err := io.ReadAll(resp.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(b))
Output: Hello, world
type RuntimeOption ¶
type RuntimeOption func(*runtimeOptions)
RuntimeOption are options for configuring the HTTP runtime.
func Handle ¶
func Handle(pattern string, h http.Handler) RuntimeOption
Handle registers a http.Handler for the given path pattern.
func HandleFunc ¶
func HandleFunc(pattern string, f func(http.ResponseWriter, *http.Request)) RuntimeOption
HandleFunc registers a http.HandlerFunc for the given path pattern.
func Http2Only ¶
func Http2Only() RuntimeOption
Http2Only configures the HTTP server to only accept HTTP/2 connections.
func ListenOnPort ¶
func ListenOnPort(port uint) RuntimeOption
ListenOnPort will configure the HTTP server to listen on the given port.
Default port is 8080.
func LogHandler ¶
func LogHandler(h slog.Handler) RuntimeOption
LogHandler configures the underlying slog.Handler.
func TLSConfig ¶
func TLSConfig(cfg *tls.Config) RuntimeOption
TLSConfig configues the HTTP server to serve HTTPS via the given TLS config.
Directories ¶
Path | Synopsis |
---|---|
Package httpclient provides a production ready http.Client.
|
Package httpclient provides a production ready http.Client. |
Package httphealth provides a http.Handler for exposing health.Metrics
|
Package httphealth provides a http.Handler for exposing health.Metrics |
Package httpvalidate provides helpers for validating incoming HTTP requests.
|
Package httpvalidate provides helpers for validating incoming HTTP requests. |