a simple url shortener in Go (check it out at qurl.org)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

44 lines
781 B

package storage
import (
"fmt"
"git.binarythought.com/cdramey/qurl/obj"
"git.binarythought.com/cdramey/qurl/storage/bolt"
"net/url"
"strings"
)
type Storage interface {
AddQURL(*obj.QURL) error
GetQURLByURL(string) (*obj.QURL, error)
GetQURLByID(uint64) (*obj.QURL, error)
SetQURLSequence(uint64) error
Backup(string) 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
}