-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
32 lines (27 loc) · 751 Bytes
/
error.go
File metadata and controls
32 lines (27 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package loadingcache
import (
"fmt"
"time"
)
// LoadingError is an interface which extends the default error type to also provide a method
// on how long this error should be cached for.
type LoadingError interface {
error
CacheFor() time.Duration
}
type loadingError struct {
error
ttl time.Duration
}
func (e loadingError) CacheFor() time.Duration {
return e.ttl
}
// Errorf is a function which instantiates a new error abiding by the LoadingError interface.
// Use this when you want a "tombstone" value to be created inside of the cache, specifying how long
// the tombstone should be valid for.
func Errorf(t time.Duration, f string, args ...any) LoadingError {
return loadingError{
error: fmt.Errorf(f, args...),
ttl: t,
}
}