Add credential-free sample mode with sample data, README, and doc reconciliation
This commit is contained in:
@@ -39,6 +39,12 @@ func Email(r *http.Request) string {
|
||||
return email
|
||||
}
|
||||
|
||||
func Fixed(email string, next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
next.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), contextKey{}, email)))
|
||||
})
|
||||
}
|
||||
|
||||
func (a *Auth) Register(mux *http.ServeMux) {
|
||||
mux.HandleFunc("POST /auth/login", a.login)
|
||||
mux.HandleFunc("POST /auth/logout", a.logout)
|
||||
|
||||
@@ -11,15 +11,19 @@ import (
|
||||
|
||||
const refreshInterval = 5 * time.Minute
|
||||
|
||||
type Geocoder interface {
|
||||
Lookup(address string) (geocode.Point, error)
|
||||
}
|
||||
|
||||
type Cache struct {
|
||||
source data.Source
|
||||
geocoder *geocode.Client
|
||||
geocoder Geocoder
|
||||
blobs BlobChecker
|
||||
mu sync.RWMutex
|
||||
model *Model
|
||||
}
|
||||
|
||||
func NewCache(source data.Source, geocoder *geocode.Client, blobs BlobChecker) (*Cache, error) {
|
||||
func NewCache(source data.Source, geocoder Geocoder, blobs BlobChecker) (*Cache, error) {
|
||||
c := &Cache{source: source, geocoder: geocoder, blobs: blobs}
|
||||
if err := c.refresh(); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package geocode
|
||||
|
||||
import "crypto/sha256"
|
||||
|
||||
type Fake struct{}
|
||||
|
||||
func (Fake) Lookup(address string) (Point, error) {
|
||||
sum := sha256.Sum256([]byte(address))
|
||||
return Point{
|
||||
Lat: 37.5 + (float64(sum[0])/255-0.5)*0.12,
|
||||
Lng: -122.45 + (float64(sum[1])/255-0.5)*0.12,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user