Added proper redirection, improved loading error display
This commit is contained in:
@ -158,3 +158,34 @@ func (stor *BoltStorage) GetQURLByURL(u string) (*qurl.QURL, error) {
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (stor *BoltStorage) GetQURLByID(id uint64) (*qurl.QURL, error) {
|
||||
tx, err := stor.DB.Begin(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
|
||||
// Create a byte array from the ID
|
||||
bid := make([]byte, 8)
|
||||
binary.BigEndian.PutUint64(bid, id)
|
||||
|
||||
rb := tx.Bucket(QURLBucket)
|
||||
if rb == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
qb := rb.Bucket(bid)
|
||||
if qb == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
q := &qurl.QURL{ID: id}
|
||||
|
||||
qu := qb.Get(URLField)
|
||||
if qu != nil {
|
||||
q.URL = string(qu)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user