本文整理匯總了Golang中github.com/go-openapi/errors.InvalidType函數的典型用法代碼示例。如果您正苦於以下問題:Golang InvalidType函數的具體用法?Golang InvalidType怎麽用?Golang InvalidType使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了InvalidType函數的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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))
kind := val.Kind()
schType, format := t.schemaInfoForType(data)
//fmt.Println("path:", t.Path, "schType:", schType, "format:", format, "expType:", t.Type, "expFmt:", t.Format, "kind:", val.Kind().String())
isLowerInt := t.Format == "int64" && format == "int32"
isLowerFloat := t.Format == "float64" && format == "float32"
isFloatInt := schType == "number" && swag.IsFloat64AJSONInteger(val.Float()) && t.Type.Contains("integer")
isIntFloat := schType == "integer" && t.Type.Contains("number")
if kind != reflect.String && kind != reflect.Slice && t.Format != "" && !(t.Type.Contains(schType) || format == t.Format || isFloatInt || isIntFloat || isLowerInt || isLowerFloat) {
return sErr(errors.InvalidType(t.Path, t.In, t.Format, format))
}
if !(t.Type.Contains("number") || t.Type.Contains("integer")) && t.Format != "" && (kind == reflect.String || kind == reflect.Slice) {
return result
}
if !(t.Type.Contains(schType) || isFloatInt || isIntFloat) {
return sErr(errors.InvalidType(t.Path, t.In, strings.Join(t.Type, ","), schType))
}
return result
}
示例2: 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
}
示例3: bindPetID
func (o *GetPetByIDParams) bindPetID(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("petId", "path", "int64", raw)
}
o.PetID = value
return nil
}
示例4: bindID
func (o *AddCommentToTaskParams) 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
}
示例5: readResponse
func (o *ListTasksOK) readResponse(response runtime.ClientResponse, consumer runtime.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
}
示例6: 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
}
示例7: bindSince
func (o *FindTodosParams) 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 := swag.ConvertInt64(raw)
if err != nil {
return errors.InvalidType("since", "query", "int64", raw)
}
o.Since = &value
return nil
}
示例8: bindPageSize
func (o *GetTaskCommentsParams) 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
var pageSizeDefault int32 = int32(20)
o.PageSize = &pageSizeDefault
return nil
}
value, err := swag.ConvertInt32(raw)
if err != nil {
return errors.InvalidType("pageSize", "query", "int32", raw)
}
o.PageSize = &value
return nil
}
示例9: bindLimit
func (o *FindTodosParams) 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
var limitDefault int32 = int32(20)
o.Limit = &limitDefault
return nil
}
value, err := swag.ConvertInt32(raw)
if err != nil {
return errors.InvalidType("limit", "query", "int32", raw)
}
o.Limit = &value
return nil
}
示例10: 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
}
示例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]
}
if raw == "" { // empty values pass all other validations
return nil
}
value, err := swag.ConvertInt32(raw)
if err != nil {
return errors.InvalidType("limit", "formData", "int32", raw)
}
o.Limit = value
return nil
}
示例12: 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, value); err != nil {
return err
}
ir = append(ir, value)
}
o.Tags = ir
return nil
}