diff --git a/http_reader.go b/http_reader.go index 1896a96..a9f56ce 100644 --- a/http_reader.go +++ b/http_reader.go @@ -17,12 +17,13 @@ type HTTPReader struct { // RegisterHTTPReader returns a registered HTTPReader, that listens on // /reader and adds some basic handlers to simulate card-swipes. -func RegisterHTTPReader() (*HTTPReader, error) { - r := mux.NewRouter() - r.Methods("GET").Path("/reader/").HandlerFunc(HTTPReader{}.Index) - r.Methods("POST", "GET").Path("/reader/swipe").HandlerFunc(HTTPReader{}.Swipe) - http.Handle("/reader/", r) - return &HTTPReader{}, nil +func RegisterHTTPReader(k *Kasse) (*HTTPReader, error) { + r := &HTTPReader{k} + router := mux.NewRouter() + router.Methods("GET").Path("/reader/").HandlerFunc(r.Index) + router.Methods("POST", "GET").Path("/reader/swipe").HandlerFunc(r.Swipe) + http.Handle("/reader/", router) + return r, nil } var ( diff --git a/main.go b/main.go index aefbabc..01a0b82 100644 --- a/main.go +++ b/main.go @@ -379,7 +379,7 @@ func (k *Kasse) GetTransactions(user User, n int) ([]Transaction, error) { func main() { flag.Parse() - var k Kasse + k := new(Kasse) k.log = log.New(os.Stderr, "", log.LstdFlags) if db, err := sqlx.Connect(*driver, *connect); err != nil { @@ -414,7 +414,7 @@ func main() { }() } - RegisterHTTPReader() + RegisterHTTPReader(k) go func() { log.Fatal(http.ListenAndServe(*listen, context.ClearHandler(http.DefaultServeMux))) }()