Merge pull request #5376 from nuss-justin/golint/models

Lint models package
pull/5600/head
Jason Wilder 2016-02-09 09:17:53 -07:00
commit e24e57cf43
2 changed files with 8 additions and 7 deletions

View File

@ -129,6 +129,7 @@ func ParsePointsString(buf string) ([]Point, error) {
return ParsePoints([]byte(buf))
}
// ParseKey returns the measurement name and tags from a point.
func ParseKey(buf string) (string, Tags, error) {
_, keyBuf, err := scanKey([]byte(buf), 0)
tags := parseTags([]byte(buf))
@ -1087,6 +1088,7 @@ func NewPoint(name string, tags Tags, fields Fields, time time.Time) (Point, err
}, nil
}
// NewPointFromBytes returns a new Point from a marshalled Point.
func NewPointFromBytes(b []byte) (Point, error) {
p := &point{}
if err := p.UnmarshalBinary(b); err != nil {

View File

@ -10,28 +10,27 @@ import (
)
var (
// Maximum time that can be represented via int64 nanoseconds since the epoch.
// MaxNanoTime is the maximum time that can be represented via int64 nanoseconds since the epoch.
MaxNanoTime = time.Unix(0, math.MaxInt64).UTC()
// Minumum time that can be represented via int64 nanoseconds since the epoch.
// MinNanoTime is the minumum time that can be represented via int64 nanoseconds since the epoch.
MinNanoTime = time.Unix(0, math.MinInt64).UTC()
// The time is out of the representable range using int64 nanoseconds since the epoch.
// ErrTimeOutOfRange gets returned when time is out of the representable range using int64 nanoseconds since the epoch.
ErrTimeOutOfRange = fmt.Errorf("time outside range %s - %s", MinNanoTime, MaxNanoTime)
)
// Safely calculate the time given. Will return error if the time is outside the
// SafeCalcTime safely calculates the time given. Will return error if the time is outside the
// supported range.
func SafeCalcTime(timestamp int64, precision string) (time.Time, error) {
mult := GetPrecisionMultiplier(precision)
if t, ok := safeSignedMult(timestamp, mult); ok {
return time.Unix(0, t).UTC(), nil
} else {
return time.Time{}, ErrTimeOutOfRange
}
return time.Time{}, ErrTimeOutOfRange
}
// Check that a time is within the safe range.
// CheckTime checks that a time is within the safe range.
func CheckTime(t time.Time) error {
if t.Before(MinNanoTime) || t.After(MaxNanoTime) {
return ErrTimeOutOfRange