github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/nomad/state/indexer/time.go (about) 1 package indexer 2 3 import ( 4 "fmt" 5 "time" 6 ) 7 8 type TimeQuery struct { 9 Value time.Time 10 } 11 12 // IndexFromTimeQuery can be used as a memdb.Indexer query via ReadIndex and 13 // allows querying by time. 14 func IndexFromTimeQuery(arg any) ([]byte, error) { 15 p, ok := arg.(*TimeQuery) 16 if !ok { 17 return nil, fmt.Errorf("unexpected type %T for TimeQuery index", arg) 18 } 19 20 // Construct the index value and return the byte array representation of 21 // the time value. 22 var b IndexBuilder 23 b.Time(p.Value) 24 return b.Bytes(), nil 25 }