a simple url shortening service, in the same vein as bit.ly and tinyurl.com, written in Go and using BoltDB as a backend
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

45 rindas
781B

  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. }