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.

28 lines
421 B

6 years ago
  1. package bolt
  2. import (
  3. bolt "go.etcd.io/bbolt"
  4. "net/url"
  5. "time"
  6. )
  7. type BoltStorage struct {
  8. DB *bolt.DB
  9. }
  10. func (stor *BoltStorage) Shutdown() {
  11. stor.DB.Close()
  12. }
  13. func New(u *url.URL) (*BoltStorage, error) {
  14. path := u.Opaque
  15. if u.Path != "" {
  16. path = u.Path
  17. }
  18. db, err := bolt.Open(path, 0600, &bolt.Options{Timeout: 3 * time.Second})
  19. if err != nil {
  20. return nil, err
  21. }
  22. return &BoltStorage{DB: db}, nil
  23. }