Create creates a new handle.
(target blobcache.OID, rights blobcache.ActionSet, createdAt, expiresAt time.Time)
| 19 | |
| 20 | // Create creates a new handle. |
| 21 | func (hs *handleSystem) Create(target blobcache.OID, rights blobcache.ActionSet, createdAt, expiresAt time.Time) blobcache.Handle { |
| 22 | secret := [16]byte{} |
| 23 | if _, err := rand.Read(secret[:]); err != nil { |
| 24 | panic(err) |
| 25 | } |
| 26 | ret := blobcache.Handle{OID: target, Secret: secret} |
| 27 | hs.mu.Lock() |
| 28 | defer hs.mu.Unlock() |
| 29 | if hs.handles == nil { |
| 30 | hs.handles = make(map[[32]byte]handle) |
| 31 | } |
| 32 | hs.handles[handleKey(ret)] = handle{ |
| 33 | target: target, |
| 34 | createdAt: createdAt, |
| 35 | expiresAt: expiresAt, |
| 36 | rights: rights, |
| 37 | } |
| 38 | if hs.active == nil { |
| 39 | hs.active = make(map[blobcache.OID]uint32) |
| 40 | } |
| 41 | hs.active[target] += 1 |
| 42 | return ret |
| 43 | } |
| 44 | |
| 45 | func (hs *handleSystem) Drop(h blobcache.Handle) { |
| 46 | k := handleKey(h) |