I am working on a API in Golang, am using Gorm as ORM. Currently am having an issue with a []byte field, I have it defined in my struct as:
type Member struct {
MyField []byte `gorm:"column:MyField" schema:"-"`
}
Then, I have the methods to Save and Read that resource, so the value when I save it is different to value that I am reading. For example,am using bcrypt to generate the hashed password, trying with 12345 the result is:
[36 50 97 36 49 48 36 46 56 98 88 72 82 71 113 66 100 65 105 103 70 119 114 97 73 77 99 78 117 106 54 78 103 88 68 49 56 110 103 112 105 86
104 79 117 47 114 57 116 51 47 53 97 100 109 103 106 46 68 109]
Until there everything is ok, then when I read the register from the database and print that value I get:
[36 50 97 36 48 52 36 56 49 67 66 121 118 90 47 47 104 49 83 120 50 108 112 71 73 51 67 88 46 97 52 74 54 66 84 73 106 105 110 122 98 69 90 51
78 113 67 66 49 103 50 56 116 47 57 120 78 103 109 54]
They are different, why? I used gorm to create the tables, and the type of that column is defined in my postgres database as bytea
The code
To save:
bs, err := bcrypt.GenerateFromPassword([]byte(Pass), bcrypt.DefaultCost)
if err != nil {
fmt.Println("Hey error!")
}
user.MyField = bs
db.Create(&user)
To Read: db.First(&user,id) fmt.Println(user.MyField)