2020-07-23 16:44:27 +00:00
|
|
|
package pbcommon
|
2019-09-20 18:37:22 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// IsRead is always true for QueryOption
|
|
|
|
func (q *QueryOptions) IsRead() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// AllowStaleRead returns whether a stale read should be allowed
|
|
|
|
func (q *QueryOptions) AllowStaleRead() bool {
|
|
|
|
return q.AllowStale
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *QueryOptions) TokenSecret() string {
|
|
|
|
return q.Token
|
|
|
|
}
|
|
|
|
|
2020-03-10 16:15:22 +00:00
|
|
|
func (q *QueryOptions) SetTokenSecret(s string) {
|
|
|
|
q.Token = s
|
|
|
|
}
|
|
|
|
|
2019-09-26 13:55:02 +00:00
|
|
|
// SetToken is needed to implement the structs.QueryOptionsCompat interface
|
|
|
|
func (q *QueryOptions) SetToken(token string) {
|
|
|
|
q.Token = token
|
2019-09-20 18:37:22 +00:00
|
|
|
}
|
|
|
|
|
2019-09-26 13:55:02 +00:00
|
|
|
// SetMinQueryIndex is needed to implement the structs.QueryOptionsCompat interface
|
|
|
|
func (q *QueryOptions) SetMinQueryIndex(minQueryIndex uint64) {
|
|
|
|
q.MinQueryIndex = minQueryIndex
|
2019-09-20 18:37:22 +00:00
|
|
|
}
|
|
|
|
|
2019-09-26 13:55:02 +00:00
|
|
|
// SetMaxQueryTime is needed to implement the structs.QueryOptionsCompat interface
|
|
|
|
func (q *QueryOptions) SetMaxQueryTime(maxQueryTime time.Duration) {
|
|
|
|
q.MaxQueryTime = maxQueryTime
|
2019-09-20 18:37:22 +00:00
|
|
|
}
|
|
|
|
|
2019-09-26 13:55:02 +00:00
|
|
|
// SetAllowStale is needed to implement the structs.QueryOptionsCompat interface
|
|
|
|
func (q *QueryOptions) SetAllowStale(allowStale bool) {
|
|
|
|
q.AllowStale = allowStale
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetRequireConsistent is needed to implement the structs.QueryOptionsCompat interface
|
|
|
|
func (q *QueryOptions) SetRequireConsistent(requireConsistent bool) {
|
|
|
|
q.RequireConsistent = requireConsistent
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetUseCache is needed to implement the structs.QueryOptionsCompat interface
|
|
|
|
func (q *QueryOptions) SetUseCache(useCache bool) {
|
|
|
|
q.UseCache = useCache
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetMaxStaleDuration is needed to implement the structs.QueryOptionsCompat interface
|
|
|
|
func (q *QueryOptions) SetMaxStaleDuration(maxStaleDuration time.Duration) {
|
|
|
|
q.MaxStaleDuration = maxStaleDuration
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetMaxAge is needed to implement the structs.QueryOptionsCompat interface
|
|
|
|
func (q *QueryOptions) SetMaxAge(maxAge time.Duration) {
|
|
|
|
q.MaxAge = maxAge
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetMustRevalidate is needed to implement the structs.QueryOptionsCompat interface
|
|
|
|
func (q *QueryOptions) SetMustRevalidate(mustRevalidate bool) {
|
|
|
|
q.MustRevalidate = mustRevalidate
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetStaleIfError is needed to implement the structs.QueryOptionsCompat interface
|
|
|
|
func (q *QueryOptions) SetStaleIfError(staleIfError time.Duration) {
|
|
|
|
q.StaleIfError = staleIfError
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetFilter is needed to implement the structs.QueryOptionsCompat interface
|
|
|
|
func (q *QueryOptions) SetFilter(filter string) {
|
|
|
|
q.Filter = filter
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetLastContact is needed to implement the structs.QueryMetaCompat interface
|
2019-09-20 18:37:22 +00:00
|
|
|
func (q *QueryMeta) SetLastContact(lastContact time.Duration) {
|
|
|
|
q.LastContact = lastContact
|
|
|
|
}
|
|
|
|
|
2019-09-26 13:55:02 +00:00
|
|
|
// SetKnownLeader is needed to implement the structs.QueryMetaCompat interface
|
2019-09-20 18:37:22 +00:00
|
|
|
func (q *QueryMeta) SetKnownLeader(knownLeader bool) {
|
|
|
|
q.KnownLeader = knownLeader
|
|
|
|
}
|
|
|
|
|
2019-09-26 13:55:02 +00:00
|
|
|
// SetIndex is needed to implement the structs.QueryMetaCompat interface
|
2019-09-20 18:37:22 +00:00
|
|
|
func (q *QueryMeta) SetIndex(index uint64) {
|
|
|
|
q.Index = index
|
|
|
|
}
|
|
|
|
|
2019-09-26 13:55:02 +00:00
|
|
|
// SetConsistencyLevel is needed to implement the structs.QueryMetaCompat interface
|
|
|
|
func (q *QueryMeta) SetConsistencyLevel(consistencyLevel string) {
|
|
|
|
q.ConsistencyLevel = consistencyLevel
|
|
|
|
}
|
|
|
|
|
2019-09-20 18:37:22 +00:00
|
|
|
// WriteRequest only applies to writes, always false
|
|
|
|
func (w WriteRequest) IsRead() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-09-26 13:55:02 +00:00
|
|
|
func (w WriteRequest) TokenSecret() string {
|
|
|
|
return w.Token
|
|
|
|
}
|
|
|
|
|
2020-03-10 16:15:22 +00:00
|
|
|
func (w *WriteRequest) SetTokenSecret(s string) {
|
|
|
|
w.Token = s
|
|
|
|
}
|
|
|
|
|
2019-09-20 18:37:22 +00:00
|
|
|
// AllowStaleRead returns whether a stale read should be allowed
|
|
|
|
func (w WriteRequest) AllowStaleRead() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (td TargetDatacenter) RequestDatacenter() string {
|
|
|
|
return td.Datacenter
|
|
|
|
}
|