Skip to content

Commit

Permalink
Merge pull request #31 from nnev/fix_28
Browse files Browse the repository at this point in the history
Pass a *Kasse to RegisterHTTPReader
  • Loading branch information
koebi committed Sep 12, 2015
2 parents 8f4a97f + 5852b9b commit 8c9af9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions http_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -414,7 +414,7 @@ func main() {
}()
}

RegisterHTTPReader()
RegisterHTTPReader(k)
go func() {
log.Fatal(http.ListenAndServe(*listen, context.ClearHandler(http.DefaultServeMux)))
}()
Expand Down

0 comments on commit 8c9af9a

Please sign in to comment.