I have tried to query mysql database table data but am getting the byte data after trying many instances to convert the byte data to the hexadecimal values. Any help about how can i get the hexadecimal values from the database.
I created the table below as
CREATE TABLE `subscriber_profile` (
....
`msin` binary(5) NOT NULL,
`msisdn` bigint(16) NOT NULL,
`k` binary(16) DEFAULT NULL,
`opc` binary(16) DEFAULT NULL,
`sqn` binary(6) DEFAULT NULL,
...
PRIMARY KEY (`mcc`,`mnc`,`msin`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
And the data in the database as
INSERT INTO subscriber_profile
VALUES (...,358507777001/msisdn/,0x000102030405060708090A0B0C0D0E0F/k/,0xBC2BCE2A23BE2FAE32E4F1B4546004F7/opc/,...);
Am querying the table using msisdn as parameter. Also is using byte in struct field right?
type SubscriberProfile struct {
...
Msisdn int `json:"msisdn"`
K []byte `json:"k"`
Opc []byte `json:"opc"`
}
func GetPara(msisdn int) []SubscriberProfile {
db := dbConn()
selDB, err := db.Query("SELECT msisdn, k, opc FROM subscriber_profile WHERE msisdn=?;", msisdn)
if err != nil {
panic(err.Error())
}
av := SubscriberProfile{}
res := []SubscriberProfile{}
for selDB.Next() {
var msisdn int
var k, opc []byte
err = selDB.Scan(&msisdn, &k, &opc)
if err != nil {
panic(err.Error())
}
av.Msisdn = msisdn
av.K = k
av.Opc = opc
res = append(res, av)
}
return res
}
I have tried to use hex.EncodeToString(k) but could not get the right result.
var data []SubscriberProfile
data = GetPara(358507777001)
fmt.Println(data)
output:
[{0 0 0 358507777001 [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15] [188 43 206 42 35 190 47 174 50 228 241 180 84 96 4 247]}]
Am expecting an output [{0 0 0 358507777001 000102030405060708090A0B0C0D0E0F BC2BCE2A23BE2FAE32E4F1B4546004F7 0 ...}]
Any help?