30 lines
501 B
Go
30 lines
501 B
Go
package tester
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
type ExpiringCache struct {
|
|
Value interface{}
|
|
Expires int
|
|
}
|
|
|
|
// get string value for comparison
|
|
func (e *ExpiringCache) StringValue() (string, error) {
|
|
switch e.Value.(type) {
|
|
case string:
|
|
return e.Value.(string), nil
|
|
default:
|
|
data, err := json.Marshal(&e.Value)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(data), nil
|
|
}
|
|
}
|
|
|
|
func (e *ExpiringCache) String() string {
|
|
return fmt.Sprintf("%s, expires %d", e.Value, e.Expires)
|
|
}
|