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.
|
|
package bolt
import ( bolt "go.etcd.io/bbolt" "net/url" "os" "time" )
type BoltStorage struct { DB *bolt.DB }
func (stor *BoltStorage) Shutdown() { stor.DB.Close() }
func New(u *url.URL) (*BoltStorage, error) { path := u.Opaque if u.Path != "" { path = u.Path }
db, err := bolt.Open(path, 0600, &bolt.Options{Timeout: 3 * time.Second}) if err != nil { return nil, err } return &BoltStorage{DB: db}, nil }
func (stor *BoltStorage) Backup(bpath string) error { tx, err := stor.DB.Begin(false) if err != nil { return err } defer tx.Rollback()
err = tx.CopyFile(bpath, os.FileMode(0600)) if err != nil { return err } return nil }
|