summaryrefslogtreecommitdiffstats
path: root/data.go
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2016-11-21 19:36:31 -0500
committerGuillaume Horel <guillaume.horel@gmail.com>2016-11-21 19:36:31 -0500
commit0e5bb6b93920fe9782ab976bb556f66707f0db7f (patch)
treedae89ffd08ede61f33b057d7d7126d43436aeda6 /data.go
parentc2c39cc2756230c1de29d8065b8b320f2f084045 (diff)
downloadlastfm-api-0e5bb6b93920fe9782ab976bb556f66707f0db7f.tar.gz
return error directly
Diffstat (limited to 'data.go')
-rw-r--r--data.go22
1 files changed, 6 insertions, 16 deletions
diff --git a/data.go b/data.go
index 7cdccca..bced353 100644
--- a/data.go
+++ b/data.go
@@ -34,8 +34,8 @@ type Session struct {
type DataStore interface {
PutSession(*Session)
- GetSession(key string) (*Session, bool)
- GetPassword(userName string) (string, bool)
+ GetSession(key string) (*Session, error)
+ GetPassword(userName string) (string, error)
PutScrobbles([]Scrobble)
Api
}
@@ -71,28 +71,18 @@ func (store *SqlStore) PutSession(s *Session) {
s.User, s.Key, s.Client, s.Protocol, s.Created)
}
-func (store *SqlStore) GetSession(key string) (*Session, bool) {
+func (store *SqlStore) GetSession(key string) (*Session, error) {
s := &Session{}
row := store.QueryRow("SELECT * FROM sessions WHERE key = ?", key)
err := row.Scan(&s.User, &s.Key, &s.Client, &s.Protocol, &s.Created)
- if err == sql.ErrNoRows {
- return s, false
- } else if err != nil {
- fmt.Println(err)
- }
- return s, true
+ return s, err
}
-func (store *SqlStore) GetPassword(name string) (string, bool) {
+func (store *SqlStore) GetPassword(name string) (string, error) {
var password string
row := store.QueryRow("SELECT password FROM users WHERE name = ?", name)
err := row.Scan(&password)
- if err == sql.ErrNoRows {
- return password, false
- } else if err != nil {
- fmt.Println(err)
- }
- return password, true
+ return password, err
}
func (store *SqlStore) PutScrobbles(scrobbles []Scrobble) {