39 lines
682 B
Go
39 lines
682 B
Go
package internal
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
var (
|
|
ErrInvalidStore = errors.New("error: invalid store")
|
|
ErrURLNotFound = errors.New("error: url not found")
|
|
)
|
|
|
|
type Store interface {
|
|
Merge() error
|
|
Close() error
|
|
Sync() error
|
|
|
|
DelURL(hash string) error
|
|
HasURL(hash string) bool
|
|
GetURL(hash string) (*URL, error)
|
|
SetURL(hash string, url *URL) error
|
|
URLCount() int64
|
|
ForEachURL(f func(*URL) error) error
|
|
}
|
|
|
|
func NewStore(store string) (Store, error) {
|
|
u, err := ParseURI(store)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error parsing store uri: %s", err)
|
|
}
|
|
|
|
switch u.Type {
|
|
case "bitcask":
|
|
return newBitcaskStore(u.Path)
|
|
default:
|
|
return nil, ErrInvalidStore
|
|
}
|
|
}
|