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

6 years ago
4 years ago
6 years ago
6 years ago
6 years ago
  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. }