Release v0.10.0-beta
Pre-release
Pre-release
Changes in this PR are not backward compatible! Few things have changed. Hopefully, migration will not be painful for you. If you have any questions, please, let us know here or in our community Slack channel.
Changes:
- added
message.Marshal(data)which sets values of message fields using values provided indatastruct. - added support of
indextag for bothmessage.Marshal()andmessage.Unmarshal(). Now you can name your fields as you want and usedindextag to specify field index in the ISO8583 specification. Examples are here and here. - removed
iso8583.Unmarshal. Please, usemessage.Unmarshalinstead. - removed message.Data()
- deprecated
message.SetData(data). Usemessage.Marshal()instead. - deprecated
field.SetData(data). Usefield.Marshal(data)instead. - changed current behavior of
message.SetData(data). Before it could be used to get values into a struct after callingmessage.Unpack()like this:
data := &ISOMessage{}
mesage.SetData(data)
message.Unpack(rawMessage)
data.F1.Value // if previous versions values were populated during unpacking, but now they are notNow message.SetData(data) only sets field values. No way to get values back to the struct. In order to get values into struct you have to use message.Unmarshal(data) like this:
message.Unpack(rawMessage)
data := &ISOMessage{}
mesage.Unmarshall(data)
data.F1.Value // now you can get the valueMigration Guide
Two main changes that you may need to do in your code:
- Replace
message.SetData(data)withmessage.Marshal(data). Latter, simply sets field values with values provided in thedatastruct. Without any side-effects. - Replce
message.Data()(*YouMessageTypehere) withmessage.Unmarshal(data). It setsdata` struct values with message field values. No side-effects. - If you used
SetData()and callUnpackto get access to message field values, replace it withmessage.Unmarshal(data).
You have to change your code from this
type ISO87Data struct {
F0 *field.String
F2 *field.String
F4 *field.String
}
message := NewMessage(spec)
data := &ISO87Data{}
err := message.SetData(data) // you "link" data internally
err = message.Unpack(rawMsg) // here values are populated into linked data struct. no more.
// now you access you
data.F0.Value
data.F2.Value
data.F4.Valueto this:
type ISO87Data struct {
F0 *field.String
F2 *field.String
F4 *field.String
}
message := NewMessage(spec)
err := message.Unpack(rawMsg)
data := &ISO87Data{}
err = message.Unmarshal(data)
// now you access fields in data
data.F0.Value
data.F2.Value
data.F4.Value