本文整理匯總了Golang中github.com/go-swagger/go-swagger/errors.InvalidType函數的典型用法代碼示例。如果您正苦於以下問題:Golang InvalidType函數的具體用法?Golang InvalidType怎麽用?Golang InvalidType使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了InvalidType函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Validate
func (t *typeValidator) Validate(data interface{}) *Result {
result := new(Result)
result.Inc()
if data == nil || reflect.DeepEqual(reflect.Zero(reflect.TypeOf(data)), reflect.ValueOf(data)) {
if len(t.Type) > 0 && !t.Type.Contains("null") { // TODO: if a property is not required it also passes this
return sErr(errors.InvalidType(t.Path, t.In, strings.Join(t.Type, ","), "null"))
}
return result
}
// check if the type matches, should be used in every validator chain as first item
val := reflect.Indirect(reflect.ValueOf(data))
schType, format := t.schemaInfoForType(data)
isLowerInt := t.Format == "int64" && format == "int32"
isLowerFloat := t.Format == "float64" && format == "float32"
if val.Kind() != reflect.String && t.Format != "" && !(format == t.Format || isLowerInt || isLowerFloat) {
return sErr(errors.InvalidType(t.Path, t.In, t.Format, format))
}
if t.Format != "" && val.Kind() == reflect.String {
return result
}
isFloatInt := schType == "number" && swag.IsFloat64AJSONInteger(val.Float()) && t.Type.Contains("integer")
isIntFloat := schType == "integer" && t.Type.Contains("number")
if !(t.Type.Contains(schType) || isFloatInt || isIntFloat) {
return sErr(errors.InvalidType(t.Path, t.In, strings.Join(t.Type, ","), schType))
}
return result
}
示例2: invalidTypeError
func invalidTypeError(param *spec.Parameter, data interface{}) *errors.Validation {
tpe := param.Type
if param.Format != "" {
tpe = param.Format
}
return errors.InvalidType(param.Name, param.In, tpe, data)
}
示例3: bindPetID
func (o *DeletePetParams) bindPetID(raw string, formats strfmt.Registry) error {
value, err := swag.ConvertInt64(raw)
if err != nil {
return errors.InvalidType("petId", "path", "int64", raw)
}
o.PetID = value
return nil
}
示例4: bindID
func (o *GetEventByIDParams) bindID(raw string, formats strfmt.Registry) error {
value, err := swag.ConvertInt64(raw)
if err != nil {
return errors.InvalidType("id", "path", "int64", raw)
}
o.ID = value
return nil
}
示例5: FormatOf
// FormatOf validates if a string matches a format in the format registry
func FormatOf(path, in, format, data string, registry strfmt.Registry) *errors.Validation {
if registry == nil {
registry = strfmt.Default
}
if ok := registry.ContainsName(format); !ok {
return errors.InvalidTypeName(format)
}
if ok := registry.Validates(format, data); !ok {
return errors.InvalidType(path, in, format, data)
}
return nil
}
示例6: bindID
func (o *UpdateOneParams) bindID(rawData []string, hasKey bool, formats strfmt.Registry) error {
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
value, err := swag.ConvertInt64(raw)
if err != nil {
return errors.InvalidType("id", "path", "int64", raw)
}
o.ID = value
return nil
}
示例7: readResponse
func (o *ListTasksOK) readResponse(response client.Response, consumer httpkit.Consumer, formats strfmt.Registry) error {
// response header X-Last-Task-Id
xLastTaskId, err := swag.ConvertInt64(response.GetHeader("X-Last-Task-Id"))
if err != nil {
return errors.InvalidType("X-Last-Task-Id", "header", "int64", response.GetHeader("X-Last-Task-Id"))
}
o.XLastTaskID = xLastTaskId
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
示例8: bindSince
func (o *GetTaskCommentsParams) bindSince(rawData []string, hasKey bool, formats strfmt.Registry) error {
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
if raw == "" { // empty values pass all other validations
return nil
}
value, err := formats.Parse("date-time", raw)
if err != nil {
return errors.InvalidType("since", "query", "strfmt.DateTime", raw)
}
o.Since = *(value.(*strfmt.DateTime))
return nil
}
示例9: bindLimit
func (o *ListEventsParams) bindLimit(rawData []string, hasKey bool, formats strfmt.Registry) error {
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
if raw == "" { // empty values pass all other validations
return nil
}
value, err := swag.ConvertInt32(raw)
if err != nil {
return errors.InvalidType("limit", "query", "int32", raw)
}
o.Limit = &value
return nil
}
示例10: bindSinceID
func (o *ListTasksParams) bindSinceID(rawData []string, hasKey bool, formats strfmt.Registry) error {
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
if raw == "" { // empty values pass all other validations
return nil
}
value, err := swag.ConvertInt64(raw)
if err != nil {
return errors.InvalidType("sinceId", "query", "int64", raw)
}
o.SinceID = value
return nil
}
示例11: bindLimit
func (o *FindParams) bindLimit(rawData []string, hasKey bool, formats strfmt.Registry) error {
if !hasKey {
return errors.Required("limit", "formData")
}
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
value, err := swag.ConvertInt32(raw)
if err != nil {
return errors.InvalidType("limit", "formData", "int32", raw)
}
o.Limit = value
return nil
}
示例12: bindPageSize
func (o *ListTasksParams) bindPageSize(rawData []string, hasKey bool, formats strfmt.Registry) error {
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
if raw == "" { // empty values pass all other validations
o.PageSize = 20
return nil
}
value, err := swag.ConvertInt32(raw)
if err != nil {
return errors.InvalidType("pageSize", "query", "int32", raw)
}
o.PageSize = value
return nil
}
示例13: bindOrderID
func (o *GetOrderByIDParams) bindOrderID(rawData []string, hasKey bool, formats strfmt.Registry) error {
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
value, err := swag.ConvertInt64(raw)
if err != nil {
return errors.InvalidType("orderId", "path", "int64", raw)
}
o.OrderID = value
if err := o.validateOrderID(formats); err != nil {
return err
}
return nil
}
示例14: bindXRateLimit
func (o *FindParams) bindXRateLimit(rawData []string, hasKey bool, formats strfmt.Registry) error {
if !hasKey {
return errors.Required("X-Rate-Limit", "header")
}
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
if err := validate.RequiredString("X-Rate-Limit", "header", raw); err != nil {
return err
}
value, err := swag.ConvertInt32(raw)
if err != nil {
return errors.InvalidType("X-Rate-Limit", "header", "int32", raw)
}
o.XRateLimit = value
return nil
}
示例15: bindTags
func (o *FindParams) bindTags(rawData []string, hasKey bool, formats strfmt.Registry) error {
if !hasKey {
return errors.Required("tags", "formData")
}
raw := rawData
size := len(raw)
if size == 0 {
return nil
}
ic := raw
isz := size
var ir []int32
iValidateElement := func(i int, tagsI int32) *errors.Validation {
return nil
}
for i := 0; i < isz; i++ {
value, err := swag.ConvertInt32(ic[i])
if err != nil {
return errors.InvalidType(fmt.Sprintf("%s.%v", "tags", i), "formData", "int32", ic[i])
}
if err := iValidateElement(i, o.Tags[i]); err != nil {
return err
}
ir = append(ir, value)
}
o.Tags = ir
return nil
}