44 lines
702 B
Go
44 lines
702 B
Go
|
package storage
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"net/url"
|
||
|
"qurl/qurl"
|
||
|
"qurl/storage/bolt"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
type Storage interface {
|
||
|
AddQURL(*qurl.QURL) error
|
||
|
// GetQURL(uint64) (*qurl.QURL, error)
|
||
|
GetQURLByURL(string) (*qurl.QURL, error)
|
||
|
SetQURLSequence(uint64) error
|
||
|
Shutdown()
|
||
|
}
|
||
|
|
||
|
func NewStorage(su string) (Storage, error) {
|
||
|
u, err := url.Parse(su)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
if u.Scheme == "" {
|
||
|
return nil, fmt.Errorf("URL must include a scheme")
|
||
|
}
|
||
|
|
||
|
var stor Storage
|
||
|
|
||
|
switch strings.ToLower(u.Scheme) {
|
||
|
case "bolt", "boltdb", "bbolt":
|
||
|
stor, err = bolt.New(u)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
default:
|
||
|
return nil, fmt.Errorf("Unsupported URL scheme")
|
||
|
}
|
||
|
|
||
|
return stor, nil
|
||
|
}
|