1// Copyright 2017 The Prometheus Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14package storage
15
16// lazyGenericSeriesSet is a wrapped series set that is initialised on first call to Next().
17type lazyGenericSeriesSet struct {
18	init func() (genericSeriesSet, bool)
19
20	set genericSeriesSet
21}
22
23func (c *lazyGenericSeriesSet) Next() bool {
24	if c.set != nil {
25		return c.set.Next()
26	}
27	var ok bool
28	c.set, ok = c.init()
29	return ok
30}
31
32func (c *lazyGenericSeriesSet) Err() error {
33	if c.set != nil {
34		return c.set.Err()
35	}
36	return nil
37}
38
39func (c *lazyGenericSeriesSet) At() Labels {
40	if c.set != nil {
41		return c.set.At()
42	}
43	return nil
44}
45
46func (c *lazyGenericSeriesSet) Warnings() Warnings {
47	if c.set != nil {
48		return c.set.Warnings()
49	}
50	return nil
51}
52
53type warningsOnlySeriesSet Warnings
54
55func (warningsOnlySeriesSet) Next() bool           { return false }
56func (warningsOnlySeriesSet) Err() error           { return nil }
57func (warningsOnlySeriesSet) At() Labels           { return nil }
58func (c warningsOnlySeriesSet) Warnings() Warnings { return Warnings(c) }
59
60type errorOnlySeriesSet struct {
61	err error
62}
63
64func (errorOnlySeriesSet) Next() bool         { return false }
65func (errorOnlySeriesSet) At() Labels         { return nil }
66func (s errorOnlySeriesSet) Err() error       { return s.err }
67func (errorOnlySeriesSet) Warnings() Warnings { return nil }
68