go-by-test/context/context.go

24 lines
354 B
Go
Raw Normal View History

2024-09-21 18:07:09 +00:00
package context
import (
"context"
2024-09-21 18:07:09 +00:00
"fmt"
"log"
2024-09-21 18:07:09 +00:00
"net/http"
)
type Store interface {
Fetch(ctx context.Context) (string, error)
2024-09-21 18:07:09 +00:00
}
func Server(store Store) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
data, err := store.Fetch(r.Context())
if err != nil {
log.Println(err)
return
}
fmt.Fprint(w, data)
2024-09-21 18:07:09 +00:00
}
}