gotdd/context.go

23 lines
361 B
Go
Raw Permalink Normal View History

2022-01-20 04:20:12 +00:00
package main
import (
"context"
"fmt"
"net/http"
)
type Store interface {
Fetch(ctx context.Context) (string, error)
}
func Server(store Store) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
data, err := store.Fetch(r.Context())
if err != nil {
return // todo: log error however you like
}
fmt.Fprint(w, data)
}
}