You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if I set a type alias of basic type,like []string ,then, I neet to add two function,such as ( value and scan ,mysql json need this), the bug is appened.
the entire code under:
package main
import (
"database/sql/driver""encoding/json""fmt"
validation "github.com/go-ozzo/ozzo-validation"
)
typeTags []string// mysql 8.0 json need value and scan function, so I need type aliastypeCoursesstruct {
TagTags`gorm:"type:json;comment:体系名是json格式" json:"tag"`
}
// !!!!!! IF YOU REMOVE THIS FUNCTION, IT IS VALIDETED !!!!!// !!!!!! IF YOU ADD PONITER IN P, IT IS VALIDETED !!!!func (pTags) Value() (driver.Value, error) {
b, err:=json.Marshal(p)
returnb, err
}
func (p*Tags) Scan(inputany) error {
returnjson.Unmarshal(input.([]byte), p)
}
funcmain() {
varcourseDtoCoursescourseDto.Tag=Tags{"student", "engineer"}
err:=validation.ValidateStruct(&courseDto,
validation.Field(&courseDto.Tag, validation.Required, validation.Length(1, 3)),
)
fmt.Println(err)
}
Something strange is coming in function value !!!
If p without pointer can't pass validate!
if I set a type alias of basic type,like
[]string
,then, I neet to add two function,such as ( value and scan ,mysql json need this), the bug is appened.the entire code under:
Something strange is coming in function value !!!
If
p
without pointer can't pass validate!But, if add pointer, it pass!
The text was updated successfully, but these errors were encountered: