// Copyright 2013 The Prometheus Authors// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at//// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.package modelimport ()// ZeroSamplePair is the pseudo zero-value of SamplePair used to signal a// non-existing sample pair. It is a SamplePair with timestamp Earliest and// value 0.0. Note that the natural zero value of SamplePair has a timestamp// of 0, which is possible to appear in a real SamplePair and thus not// suitable to signal a non-existing SamplePair.varZeroSamplePair = SamplePair{Timestamp: Earliest}// A SampleValue is a representation of a value for a given sample at a given// time.typeSampleValuefloat64// MarshalJSON implements json.Marshaler.func ( SampleValue) () ([]byte, error) {returnjson.Marshal(.String())}// UnmarshalJSON implements json.Unmarshaler.func ( *SampleValue) ( []byte) error {iflen() < 2 || [0] != '"' || [len()-1] != '"' {returnerrors.New("sample value must be a quoted string") } , := strconv.ParseFloat(string([1:len()-1]), 64)if != nil {return } * = SampleValue()returnnil}// Equal returns true if the value of v and o is equal or if both are NaN. Note// that v==o is false if both are NaN. If you want the conventional float// behavior, use == to compare two SampleValues.func ( SampleValue) ( SampleValue) bool {if == {returntrue }returnmath.IsNaN(float64()) && math.IsNaN(float64())}func ( SampleValue) () string {returnstrconv.FormatFloat(float64(), 'f', -1, 64)}// SamplePair pairs a SampleValue with a Timestamp.typeSamplePairstruct { Timestamp Time Value SampleValue}func ( SamplePair) () ([]byte, error) { , := json.Marshal(.Timestamp)if != nil {returnnil, } , := json.Marshal(.Value)if != nil {returnnil, }return []byte(fmt.Sprintf("[%s,%s]", , )), nil}// UnmarshalJSON implements json.Unmarshaler.func ( *SamplePair) ( []byte) error { := [...]json.Unmarshaler{&.Timestamp, &.Value}returnjson.Unmarshal(, &)}// Equal returns true if this SamplePair and o have equal Values and equal// Timestamps. The semantics of Value equality is defined by SampleValue.Equal.func ( *SamplePair) ( *SamplePair) bool {return == || (.Value.Equal(.Value) && .Timestamp.Equal(.Timestamp))}func ( SamplePair) () string {returnfmt.Sprintf("%s @[%s]", .Value, .Timestamp)}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.