2024-09-21 18:07:09 +00:00
|
|
|
package context
|
|
|
|
|
|
|
|
import (
|
2024-09-21 18:35:43 +00:00
|
|
|
"context"
|
2024-09-21 18:07:09 +00:00
|
|
|
"fmt"
|
2024-09-21 18:46:07 +00:00
|
|
|
"log"
|
2024-09-21 18:07:09 +00:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Store interface {
|
2024-09-21 18:35:43 +00:00
|
|
|
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) {
|
2024-09-21 18:46:07 +00:00
|
|
|
data, err := store.Fetch(r.Context())
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
return
|
|
|
|
}
|
2024-09-21 18:35:43 +00:00
|
|
|
fmt.Fprint(w, data)
|
2024-09-21 18:07:09 +00:00
|
|
|
}
|
|
|
|
}
|