title: Saving and Read byte[] in Golang from database
body: <p>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:</p>
  
  <pre><code>type Member struct {
      MyField              []byte     `gorm:"column:MyField" schema:"-"`
  }
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>[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]
  </code></pre>
  
  <p>Until there everything is ok, then when I read the register from the database and print that value I get:</p>
  
  <pre><code>[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]
  </code></pre>
  
  <p>They are different, why?
  I used gorm to create the tables, and the type of that column is defined in my postgres database as <em>bytea</em></p>
  
  <p><strong>The code</strong></p>
  
  <p><strong><em>To save:</em></strong></p>
  
  <pre><code>bs, err := bcrypt.GenerateFromPassword([]byte(Pass), bcrypt.DefaultCost)    
  
  if err != nil {
          fmt.Println("Hey error!")
  }
  user.MyField = bs
  db.Create(&amp;user)
  </code></pre>
  
  <p><strong><em>To Read:</em></strong>
      db.First(&amp;user,id)
  fmt.Println(user.MyField)</p>