a simple url shortening service, in the same vein as bit.ly and tinyurl.com, written in Go and using BoltDB as a backend
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.

storage.go 781B

1 year ago
6 months ago
1 year ago
1 year ago
1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package storage
  2. import (
  3. "fmt"
  4. "git.binarythought.com/cdramey/qurl/obj"
  5. "git.binarythought.com/cdramey/qurl/storage/bolt"
  6. "net/url"
  7. "strings"
  8. )
  9. type Storage interface {
  10. AddQURL(*obj.QURL) error
  11. GetQURLByURL(string) (*obj.QURL, error)
  12. GetQURLByID(uint64) (*obj.QURL, error)
  13. SetQURLSequence(uint64) error
  14. Backup(string) error
  15. Shutdown()
  16. }
  17. func NewStorage(su string) (Storage, error) {
  18. u, err := url.Parse(su)
  19. if err != nil {
  20. return nil, err
  21. }
  22. if u.Scheme == "" {
  23. return nil, fmt.Errorf("URL must include a scheme")
  24. }
  25. var stor Storage
  26. switch strings.ToLower(u.Scheme) {
  27. case "bolt", "boltdb", "bbolt":
  28. stor, err = bolt.New(u)
  29. if err != nil {
  30. return nil, err
  31. }
  32. default:
  33. return nil, fmt.Errorf("Unsupported URL scheme")
  34. }
  35. return stor, nil
  36. }