示例#1
0
文件: record.go 项目: speedland/apps
func init() {
	RecordValidator.Field("Id").Required().Match(ValidUUID)
	RecordValidator.Field("Title").Required().
		Unmatch(InvalidChars).Min(1).Max(64)
	RecordValidator.Field("Category").Required().
		Unmatch(InvalidChars).Min(1).Max(64)

	RecordValidator.Field("StartAt").Required()
	RecordValidator.Field("EndAt").Required()
	RecordValidator.Field("Cid").Required()
	RecordValidator.Field("Sid").Required()
	RecordValidator.Field("Uid").Required()
	RecordValidator.Func(func(r interface{}) *v.FieldValidationError {
		rec := r.(*TvRecord)
		rt := rec.RecordTime()
		if rt < MinRecordTime {
			return v.NewFieldValidationError("録画時間が短すぎます。", nil)
		}
		if rt > MaxRecordTime {
			return v.NewFieldValidationError("録画時間が長すぎます。", nil)
		}
		return nil
	})
	// Note:
	//   we don't validate overlaps since it should be noticed by
	//   other way and fixed by manually.
}
示例#2
0
文件: util.go 项目: speedland/lib
func ValidateDateTimeString(val interface{}) *v.FieldValidationError {
	switch t := val.(type) {
	case string:
		if _, err := ParseDateTime(val.(string)); err != nil {
			return v.NewFieldValidationError("Datetime format must be ISO8601 in UTC timezone (ending with 'Z')", nil)
		}
	default:
		return v.NewFieldValidationError(
			"not string but {{.Type}}",
			map[string]interface{}{"Type": t},
		)
	}
	return nil
}