types

package
v0.0.1-alpha.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2016 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InvalidTypeTitle = "Invalid type"
	InvalidDataTitle = "Invalid data"

	CurrentSchemaVersion = 3
)

Variables

View Source
var (
	//InternalFields are what we only use internally in the service and don't wish to return to any clients
	InternalFields = []string{
		"_groupId",
		"_active",
		"_schemaVersion",
		"_version",
		"createdTime",
	}

	BaseUserIDField  = DatumField{Name: "userId"}
	BaseGroupIDField = DatumField{Name: "_groupId"}
	BaseSubTypeField = DatumField{Name: "subType"}

	BaseTypeField = DatumFieldInformation{
		DatumField: &DatumField{Name: "type"},
		Tag:        "required",
		Message:    "This is a required field",
	}

	BaseDeviceIDField = DatumFieldInformation{
		DatumField: &DatumField{Name: "deviceId"},
		Tag:        "required",
		Message:    "This is a required field",
	}
)
View Source
var (
	MmolOrMgUnitsField = DatumFieldInformation{
		DatumField: &DatumField{Name: "units"},
		Tag:        "mmolmgunits",
		Message:    fmt.Sprintf("Must be one of %s, %s", mmol, mg),
		Allowed: Allowed{

			"mmol/l": true,

			"mg/dl": true,
			// contains filtered or unexported fields
		},
	}

	MmolUnitsField = DatumFieldInformation{
		DatumField: &DatumField{Name: "units"},
		Tag:        "mmolunits",
		Message:    fmt.Sprintf("Must be %s", mmol),
		Allowed: Allowed{

			"mmol/l": true,
			// contains filtered or unexported fields
		},
	}

	BloodGlucoseValueField = FloatDatumField{
		DatumField: &DatumField{Name: "value"},
		Tag:        "bloodglucosevalue",
	}
)
View Source
var (
	ZuluTimeStringField = DateDatumField{
		DatumField: &DatumField{Name: "time"},
		Tag:        "zuluTimeString",
		Message:    "An ISO 8601-formatted UTC timestamp with a final Z for 'Zulu' time e.g 2013-05-04T03:58:44.584Z",
		AllowedDate: &AllowedDate{

			Format:        "2006-01-02T15:04:05Z",
			LowerLimit:    "2007-01-01T00:00:00Z",
			AllowedFuture: false,
		},
	}

	NonZuluTimeStringField = DateDatumField{
		DatumField: &DatumField{Name: "time"},
		Tag:        "nonZuluTimeString",
		Message:    "An ISO 8601 formatted timestamp without any timezone offset information e.g 2013-05-04T03:58:44.584",
		AllowedDate: &AllowedDate{

			Format:        "2006-01-02T15:04:05",
			LowerLimit:    "2007-01-01T00:00:00",
			AllowedFuture: true,
		},
	}

	OffsetTimeStringField = DateDatumField{
		DatumField: &DatumField{Name: "time"},
		Tag:        "offsetTimeString",
		Message:    "An ISO 8601-formatted timestamp including a timezone offset from UTC e.g 2013-05-04T03:58:44-08:00",
		AllowedDate: &AllowedDate{

			Format:        "2006-01-02T15:04:05-07:00",
			LowerLimit:    "2007-01-01T00:00:00-00:00",
			AllowedFuture: false,
		},
	}

	OffsetOrZuluTimeStringField = DateDatumField{
		DatumField: &DatumField{Name: "time"},
		Tag:        "offsetOrZuluTimeString",
		Message:    "An ISO 8601-formatted timestamp including either a timezone offset from UTC OR converted to UTC with a final Z for 'Zulu' time. e.g.2013-05-04T03:58:44.584Z OR 2013-05-04T03:58:44-08:00",
	}
)

Functions

func AnnotationsValidator

func AnnotationsValidator(v *validator.Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool

func GetPlatformValidator

func GetPlatformValidator() *validate.PlatformValidator

func MmolOrMgUnitsValidator

func MmolOrMgUnitsValidator(v *validator.Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool

func MmolUnitsValidator

func MmolUnitsValidator(v *validator.Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool

func NonZuluPastTimeStringValidator

func NonZuluPastTimeStringValidator(v *validator.Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool

func OffsetOrZuluPastTimeStringValidator

func OffsetOrZuluPastTimeStringValidator(v *validator.Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool

func OffsetPastTimeStringValidator

func OffsetPastTimeStringValidator(v *validator.Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool

func PayloadValidator

func PayloadValidator(v *validator.Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool

func TimezoneOffsetValidator

func TimezoneOffsetValidator(v *validator.Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool

func ZuluPastTimeStringValidator

func ZuluPastTimeStringValidator(v *validator.Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool

Types

type Allowed

type Allowed map[string]bool

type AllowedDate

type AllowedDate struct {
	Format        string
	LowerLimit    string
	AllowedFuture bool // TODO_DATA: NonZulu dates allow future dates, others do not
}

type AllowedFloatRange

type AllowedFloatRange struct {
	UpperLimit float64
	LowerLimit float64
}

type AllowedIntRange

type AllowedIntRange struct {
	UpperLimit int
	LowerLimit int
}

type Base

type Base struct {
	ID       string  `json:"id" bson:"id" valid:"required"`
	UserID   *string `json:"userId" bson:"userId" valid:"required"`
	DeviceID *string `json:"deviceId" bson:"deviceId" valid:"required"`
	Time     *string `json:"time" bson:"time" valid:"offsetOrZuluTimeString"`
	Type     *string `json:"type" bson:"type" valid:"required"`
	UploadID *string `json:"uploadId" bson:"uploadId" valid:"-"`

	//optional data
	DeviceTime       *string       `json:"deviceTime,omitempty" bson:"deviceTime,omitempty" valid:"omitempty,nonZuluTimeString"`
	TimezoneOffset   *int          `json:"timezoneOffset,omitempty" bson:"timezoneOffset,omitempty" valid:"omitempty,timezoneoffset"`
	ConversionOffset *int          `json:"conversionOffset,omitempty" bson:"conversionOffset,omitempty" valid:"omitempty,required"`
	ClockDriftOffset *int          `json:"clockDriftOffset,omitempty" bson:"clockDriftOffset,omitempty" valid:"omitempty,required"`
	Payload          interface{}   `json:"payload,omitempty" bson:"payload,omitempty" valid:"omitempty,payload"`
	Annotations      []interface{} `json:"annotations,omitempty" bson:"annotations,omitempty" valid:"omitempty,annotations"`

	//used for versioning and de-deping
	Internal `bson:",inline"`
	// contains filtered or unexported fields
}

func BuildBase

func BuildBase(datum Datum, errs validate.ErrorProcessing) Base

type BloodGlucoseValidation

type BloodGlucoseValidation struct {
	Value *float64

	Units *string
	// contains filtered or unexported fields
}

func NewBloodGlucoseValidation

func NewBloodGlucoseValidation(val *float64, units *string) *BloodGlucoseValidation

func (*BloodGlucoseValidation) SetValueAllowedToBeEmpty

func (b *BloodGlucoseValidation) SetValueAllowedToBeEmpty(valueAllowedToBeEmpty bool) *BloodGlucoseValidation

func (*BloodGlucoseValidation) SetValueErrorPath

func (b *BloodGlucoseValidation) SetValueErrorPath(valueErrorPath string) *BloodGlucoseValidation

func (*BloodGlucoseValidation) ValidateAndConvertBloodGlucoseValue

func (b *BloodGlucoseValidation) ValidateAndConvertBloodGlucoseValue(errs validate.ErrorProcessing) (*float64, *string)

type DateDatumField

type DateDatumField struct {
	*DatumField
	Tag     validate.ValidationTag
	Message string
	*AllowedDate
}

type Datum

type Datum map[string]interface{}

func (Datum) ToArray

func (d Datum) ToArray(fieldName string, errs validate.ErrorProcessing) []interface{}

func (Datum) ToBool

func (d Datum) ToBool(fieldName string, errs validate.ErrorProcessing) *bool

func (Datum) ToFloat64

func (d Datum) ToFloat64(fieldName string, errs validate.ErrorProcessing) *float64

func (Datum) ToInt

func (d Datum) ToInt(fieldName string, errs validate.ErrorProcessing) *int

func (Datum) ToMap

func (d Datum) ToMap(fieldName string, errs validate.ErrorProcessing) map[string]interface{}

func (Datum) ToObject

func (d Datum) ToObject(fieldName string, errs validate.ErrorProcessing) interface{}

func (Datum) ToString

func (d Datum) ToString(fieldName string, errs validate.ErrorProcessing) *string

func (Datum) ToStringArray

func (d Datum) ToStringArray(fieldName string, errs validate.ErrorProcessing) []string

func (Datum) ToTime

func (d Datum) ToTime(fieldName string, errs validate.ErrorProcessing) *time.Time

type DatumArray

type DatumArray []Datum

type DatumField

type DatumField struct {
	Name string
}

type DatumFieldInformation

type DatumFieldInformation struct {
	*DatumField
	Tag     validate.ValidationTag
	Message string
	Allowed
}

type ExpectedErrorDetails

type ExpectedErrorDetails struct {
	Path   string
	Detail string
}

type FloatDatumField

type FloatDatumField struct {
	*DatumField
	Tag     validate.ValidationTag
	Message string
	*AllowedFloatRange
}

type IntDatumField

type IntDatumField struct {
	*DatumField
	Tag     validate.ValidationTag
	Message string
	*AllowedIntRange
}

type Internal

type Internal struct {
	CreatedTime   string `json:"createdTime" bson:"createdTime" valid:"zuluTimeString"`
	GroupID       string `json:"-" bson:"_groupId" valid:"required"`
	ActiveFlag    bool   `json:"-" bson:"_active" valid:"required"`
	SchemaVersion int    `json:"-" bson:"_schemaVersion" valid:"required,min=0"`
	Version       int    `json:"-" bson:"_version,omitempty" valid:"-"`
}

Internal are existing fields used for versioning and de-deping

type TestingHelper

type TestingHelper struct {
	ErrorProcessing validate.ErrorProcessing
}

func NewTestingHelper

func NewTestingHelper() *TestingHelper

func (*TestingHelper) ErrorIsExpected

func (t *TestingHelper) ErrorIsExpected(builtType interface{}, expected ExpectedErrorDetails) error

func (*TestingHelper) HasExpectedErrors

func (t *TestingHelper) HasExpectedErrors(builtType interface{}, expected map[string]ExpectedErrorDetails) error

func (*TestingHelper) ValidDataType

func (t *TestingHelper) ValidDataType(builtType interface{}) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL