Skip to content

Commit

Permalink
Merge pull request #155 from vgarvardt/master
Browse files Browse the repository at this point in the history
Add ErrNotFound to Storage interface
  • Loading branch information
RangelReale authored Jun 16, 2017
2 parents 9496ce7 + 6452faf commit 1c1df84
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
9 changes: 4 additions & 5 deletions example/teststorage.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package example

import (
"errors"
"fmt"
"github.com/RangelReale/osin"
)
Expand Down Expand Up @@ -42,7 +41,7 @@ func (s *TestStorage) GetClient(id string) (osin.Client, error) {
if c, ok := s.clients[id]; ok {
return c, nil
}
return nil, errors.New("Client not found")
return nil, osin.ErrNotFound
}

func (s *TestStorage) SetClient(id string, client osin.Client) error {
Expand All @@ -62,7 +61,7 @@ func (s *TestStorage) LoadAuthorize(code string) (*osin.AuthorizeData, error) {
if d, ok := s.authorize[code]; ok {
return d, nil
}
return nil, errors.New("Authorize not found")
return nil, osin.ErrNotFound
}

func (s *TestStorage) RemoveAuthorize(code string) error {
Expand All @@ -85,7 +84,7 @@ func (s *TestStorage) LoadAccess(code string) (*osin.AccessData, error) {
if d, ok := s.access[code]; ok {
return d, nil
}
return nil, errors.New("Access not found")
return nil, osin.ErrNotFound
}

func (s *TestStorage) RemoveAccess(code string) error {
Expand All @@ -99,7 +98,7 @@ func (s *TestStorage) LoadRefresh(code string) (*osin.AccessData, error) {
if d, ok := s.refresh[code]; ok {
return s.LoadAccess(d)
}
return nil, errors.New("Refresh not found")
return nil, osin.ErrNotFound
}

func (s *TestStorage) RemoveRefresh(code string) error {
Expand Down
12 changes: 11 additions & 1 deletion storage.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
package osin

import ()
import (
"errors"
)

var (
// ErrNotFound is the error returned by Storage Get<...> and Load<...> functions in case
// no entity is found in the storage. E.g. Storage.GetClient() returns ErrNotFound when
// client is not found. All other returned errors must be treated as storage-specific errors,
// like "connection lost", "connection refused", etc.
ErrNotFound = errors.New("Entity not found")
)

// Storage interface
type Storage interface {
Expand Down
9 changes: 4 additions & 5 deletions storage_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package osin

import (
"errors"
"strconv"
"time"
)
Expand Down Expand Up @@ -74,7 +73,7 @@ func (s *TestingStorage) GetClient(id string) (Client, error) {
if c, ok := s.clients[id]; ok {
return c, nil
}
return nil, errors.New("Client not found")
return nil, ErrNotFound
}

func (s *TestingStorage) SetClient(id string, client Client) error {
Expand All @@ -91,7 +90,7 @@ func (s *TestingStorage) LoadAuthorize(code string) (*AuthorizeData, error) {
if d, ok := s.authorize[code]; ok {
return d, nil
}
return nil, errors.New("Authorize not found")
return nil, ErrNotFound
}

func (s *TestingStorage) RemoveAuthorize(code string) error {
Expand All @@ -111,7 +110,7 @@ func (s *TestingStorage) LoadAccess(code string) (*AccessData, error) {
if d, ok := s.access[code]; ok {
return d, nil
}
return nil, errors.New("Access not found")
return nil, ErrNotFound
}

func (s *TestingStorage) RemoveAccess(code string) error {
Expand All @@ -123,7 +122,7 @@ func (s *TestingStorage) LoadRefresh(code string) (*AccessData, error) {
if d, ok := s.refresh[code]; ok {
return s.LoadAccess(d)
}
return nil, errors.New("Refresh not found")
return nil, ErrNotFound
}

func (s *TestingStorage) RemoveRefresh(code string) error {
Expand Down

0 comments on commit 1c1df84

Please sign in to comment.