2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2022-07-13 13:40:34 +00:00
|
|
|
package indexer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TimeQuery struct {
|
|
|
|
Value time.Time
|
|
|
|
}
|
|
|
|
|
|
|
|
// IndexFromTimeQuery can be used as a memdb.Indexer query via ReadIndex and
|
|
|
|
// allows querying by time.
|
|
|
|
func IndexFromTimeQuery(arg any) ([]byte, error) {
|
|
|
|
p, ok := arg.(*TimeQuery)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for TimeQuery index", arg)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct the index value and return the byte array representation of
|
|
|
|
// the time value.
|
|
|
|
var b IndexBuilder
|
|
|
|
b.Time(p.Value)
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|