Skip to content

Commit 35b29de

Browse files
authored
Merge pull request #21 from jattento/feature/add-documentation-to-remaining-api-elements
add documentation to remaining api elements
2 parents 7ac888e + a99dca2 commit 35b29de

File tree

12 files changed

+168
-55
lines changed

12 files changed

+168
-55
lines changed

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### Required tools
22
GOTOOLS_CHECK = go golangci-lint
33

4-
all: ensure-deps linter test
4+
all: ensure-deps linter test gofmt
55

66
### Testing
77
test:
@@ -23,7 +23,12 @@ linter:
2323
@echo "==> Running linter"
2424
golangci-lint run ./...
2525

26+
gofmt:
27+
@echo "==> Running go fmt"
28+
go fmt ./...
29+
30+
2631
# To avoid unintended conflicts with file names, always add to .PHONY
2732
# unless there is a reason not to.
2833
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
29-
.PHONY: all check_tools test test-cover linter ensure-deps
34+
.PHONY: all check_tools test test-cover linter ensure-deps gofmt

pkg/bitmap/bitmap.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"math"
77
)
88

9+
// Bitmap is a alias for map[int]bool used for better code reading.
910
type Bitmap = map[int]bool
1011

1112
const (
@@ -18,10 +19,13 @@ const (
1819
)
1920

2021
var (
21-
// Errors...
22-
ErrBitmapISOWrongLength = errors.New("wrong bitmap length input")
23-
ErrBitmapISOBadBitmapPosition = errors.New("bad bitmap position input")
24-
ErrBitmapISOImpossibleBitmap = errors.New("impossible generate bitmap, lowest and highest limits too far")
22+
// ErrBitmapISOWrongLength exported error for asserting.
23+
ErrBitmapISOWrongLength = errors.New("wrong bitmap length input")
24+
// ErrBitmapISOBadBitmapPosition exported error for asserting.
25+
ErrBitmapISOBadBitmapPosition = errors.New("bad bitmap position input")
26+
// ErrBitmapISOImpossibleBitmap exported error for asserting.
27+
ErrBitmapISOImpossibleBitmap = errors.New("impossible generate bitmap, lowest and highest limits too far")
28+
// ErrBitmapISOFirstBitProhibited exported error for asserting.
2529
ErrBitmapISOFirstBitProhibited = errors.New("first bit can be setted manually in input")
2630
)
2731

@@ -137,6 +141,7 @@ func setBit(n byte, pos uint) byte {
137141
return n
138142
}
139143

144+
// Extremities returns the lowest and highest elements of a bitmap.
140145
func Extremities(b Bitmap) (low, high int) {
141146
firstIteration := true
142147
for k := range b {

pkg/encoding/ebcdic/1047.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ebcdic
22

3+
// V1047 version of EBCDIC encoding
34
var V1047 = version{entries: []entry{
45
{0x00, 0x00, 0x0}, // "NULL"
56
{0x01, 0x01, 0x0}, // "START OF HEADING"

pkg/encoding/ebcdic/ebcdic.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type entry struct {
1414
representation rune
1515
}
1616

17+
// NULL is used for invalid encoding conversions.
1718
const NULL = 0x0
1819

1920
// FromGoString converts a string to ebcdic bytes.
@@ -37,7 +38,7 @@ func (v *version) FromGoString(s string) []byte {
3738
return output
3839
}
3940

40-
// FromGoString converts a ebcdic bytes to a string.
41+
// ToGoString converts a ebcdic bytes to a string.
4142
func (v *version) ToGoString(b []byte) string {
4243
if len(v.decoding) == 0 {
4344
v.generateDecodingMap()

pkg/iso8583/bitmap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (b BITMAP) MarshalISO8583(length int, encoding string) ([]byte, error) {
3131
return bitmap.ToBytes(b.Bitmap), nil
3232
}
3333

34-
// Returns which bits are on, key values are between 1 and 64, both included.
34+
// Bits returns which bits are on, key values are between 1 and 64, both included.
3535
// First value is bit 1.
3636
func (b BITMAP) Bits() (map[int]bool, error) {
3737
return b.Bitmap, nil

pkg/iso8583/decode.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Unmarshaler interface {
3232
UnmarshalISO8583(b []byte, length int, encoding string) (n int, err error)
3333
}
3434

35-
// Unmarshaler interface for iso8583 bitmaps.
35+
// UnmarshalerBitmap is the unmarshaler interface for iso8583 bitmaps.
3636
//
3737
// Length tag: It indicates the amount of representative bits contained
3838
// by the bitmap. For example in a classic 8 byte bitmap it would be 64,
@@ -160,7 +160,7 @@ func newUnmarshalBuffer(data []byte) *unmarshalBuffer {
160160
return &buffer
161161
}
162162

163-
// incrementConsumed increments the placeholder considering the data length.
163+
// IncrementConsumedCounter increments the placeholder considering the data length.
164164
func (buffer *unmarshalBuffer) IncrementConsumedCounter(n int, fieldName string) error {
165165
if len(buffer.data[buffer.placeholder:]) < n {
166166
// This error can only be caused by bad unmarshal implementations

pkg/iso8583/decode_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestUnmarshal(t *testing.T) {
4343
field3 iso8583.VAR `iso8583:"3,length:3"`
4444
}{
4545
Field2: "asd",
46-
Bitmap: iso8583.BITMAP{map[int]bool{1: false, 2: true, 3: false, 4: false, 5: false, 6: false,
46+
Bitmap: iso8583.BITMAP{Bitmap: map[int]bool{1: false, 2: true, 3: false, 4: false, 5: false, 6: false,
4747
7: false, 8: false, 9: false, 10: false, 11: false, 12: false, 13: false, 14: false, 15: false,
4848
16: false, 17: false, 18: false, 19: false, 20: false, 21: false, 22: false, 23: false, 24: false,
4949
25: false, 26: false, 27: false, 28: false, 29: false, 30: false, 31: false, 32: false, 33: false,
@@ -77,15 +77,15 @@ func TestUnmarshal(t *testing.T) {
7777
}{
7878
Field2: "asd",
7979
Field66: "fgh",
80-
Field1: iso8583.BITMAP{map[int]bool{1: false, 2: true, 3: false, 4: false, 5: false, 6: false,
80+
Field1: iso8583.BITMAP{Bitmap: map[int]bool{1: false, 2: true, 3: false, 4: false, 5: false, 6: false,
8181
7: false, 8: false, 9: false, 10: false, 11: false, 12: false, 13: false, 14: false, 15: false,
8282
16: false, 17: false, 18: false, 19: false, 20: false, 21: false, 22: false, 23: false, 24: false,
8383
25: false, 26: false, 27: false, 28: false, 29: false, 30: false, 31: false, 32: false, 33: false,
8484
34: false, 35: false, 36: false, 37: false, 38: false, 39: false, 40: false, 41: false, 42: false,
8585
43: false, 44: false, 45: false, 46: false, 47: false, 48: false, 49: false, 50: false, 51: false,
8686
52: false, 53: false, 54: false, 55: false, 56: false, 57: false, 58: false, 59: false, 60: false,
8787
61: false, 62: false, 63: false, 64: false}},
88-
Bitmap: iso8583.BITMAP{map[int]bool{1: true, 2: true, 3: false, 4: false, 5: false, 6: false,
88+
Bitmap: iso8583.BITMAP{Bitmap: map[int]bool{1: true, 2: true, 3: false, 4: false, 5: false, 6: false,
8989
7: false, 8: false, 9: false, 10: false, 11: false, 12: false, 13: false, 14: false, 15: false,
9090
16: false, 17: false, 18: false, 19: false, 20: false, 21: false, 22: false, 23: false, 24: false,
9191
25: false, 26: false, 27: false, 28: false, 29: false, 30: false, 31: false, 32: false, 33: false,

pkg/iso8583/encode.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Marshaler interface {
4444
// Omitempty tag does not affect MarshalerBitmap.
4545
// NOTE: This implementation is not a must in bitmaps.
4646
type MarshalerBitmap interface {
47+
// MarshalISO8583Bitmap must consume b map information and return the corresponding byte slice.
4748
// b should always represent which bits are on what not necessarily is equal to what fields are present.
4849
// For example: In a traditional 8 byte bitmap. Te presence of field 65 would be represented in with bit 1 on.
4950
// len(b) == length tag.

pkg/iso8583/encoding.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import (
44
"github.com/jattento/go-iso8583/pkg/encoding/ebcdic"
55
)
66

7+
// UnmarshalDecodings is the unmarshal encodings map used by inbuilt ISO fields, you can append more encoding for extended functionality.
78
var UnmarshalDecodings = map[string]func([]byte) ([]byte, error){
89
"ebcdic": errWrapper(func(bytes []byte) []byte { return []byte(ebcdic.V1047.ToGoString(bytes)) }),
910
"ascii": nop,
1011
}
1112

13+
// MarshalEncodings is the marshal encodings map used by inbuilt ISO fields, you can append more encoding for extended functionality.
1214
var MarshalEncodings = map[string]func([]byte) ([]byte, error){
1315
"ebcdic": errWrapper(func(bytes []byte) []byte {
1416
return ebcdic.V1047.FromGoString(string(bytes))

pkg/iso8583/lllvar.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import (
44
"errors"
55
)
66

7-
// LLLVAR: For use of different encoding for 'LLL' and 'VAR' separate both encodings with a slash,
7+
// LLLVAR field type.
8+
// For use of different encoding for 'LLL' and 'VAR' separate both encodings with a slash,
89
// where first element is the lll encoding and the second the var encoding.
910
// For Unmarshal length indicate the amount of byte that contain the LLL value
1011
// For example:

pkg/iso8583/llvar.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import (
88
"unicode"
99
)
1010

11-
// LLVAR: For use of different encoding for 'LL' and 'VAR' separate both encodings with a slash,
11+
// LLVAR field type.
12+
// For use of different encoding for 'LL' and 'VAR' separate both encodings with a slash,
1213
// where first element is the ll encoding and the second the var encoding.
1314
// For Unmarshal length indicate the amount of byte that contain the LL value
1415
// For example:

pkg/mti/mti.go

Lines changed: 136 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -73,61 +73,157 @@ func (mti MTI) HigherOrEqualThan(v MTI) bool {
7373
type origin int
7474

7575
const (
76-
OriginAcquirer origin = iota //
77-
OriginAcquirerRepeat //
78-
OriginIssuer //
79-
OriginIssuerRepeat //
80-
OriginOther //
81-
OriginOtherRepeat //
82-
OriginReservedByISO6 //
83-
OriginReservedByISO7 //
84-
OriginReservedByISO8 //
85-
OriginReservedByISO9 //
76+
// OriginAcquirer message type identifier.
77+
OriginAcquirer origin = iota
78+
79+
// OriginAcquirerRepeat message type identifier.
80+
OriginAcquirerRepeat
81+
82+
// OriginIssuer message type identifier.
83+
OriginIssuer
84+
85+
// OriginIssuerRepeat message type identifier.
86+
OriginIssuerRepeat
87+
88+
// OriginOther message type identifier.
89+
OriginOther
90+
91+
// OriginOtherRepeat message type identifier.
92+
OriginOtherRepeat
93+
94+
// OriginReservedByISO6 message type identifier.
95+
OriginReservedByISO6
96+
97+
// OriginReservedByISO7 message type identifier.
98+
OriginReservedByISO7
99+
100+
// OriginReservedByISO8 message type identifier.
101+
OriginReservedByISO8
102+
103+
// OriginReservedByISO9 message type identifier.
104+
OriginReservedByISO9
86105
)
87106

88107
type function int
89108

90109
const (
91-
FunctionRequest function = iota * 10 // Request from acquirer to issuer to carry out an action; issuer may accept or reject
92-
FunctionRequestResponse // Issuer response to a request
93-
FunctionAdvice // Advice that an action has taken place; receiver can only accept, not reject
94-
FunctionAdviceResponse // Response to an advice
95-
FunctionNotification // Notification that an event has taken place; receiver can only accept, not reject
96-
FunctionNotificationAcknowledgement // Response to a notification
97-
FunctionInstruction // ISO 8583:2003
98-
FunctionInstructionAcknowledgement // Instruction acknowledgement
99-
FunctionReservedByISO8 // Reserved for ISO.
100-
FunctionReservedByISO9 // Reserved for ISO.
110+
// FunctionRequest message type identifier.
111+
// Request from acquirer to issuer to carry out an action; issuer may accept or reject
112+
FunctionRequest function = iota * 10
113+
114+
// FunctionRequestResponse message type identifier.
115+
// Issuer response to a request
116+
FunctionRequestResponse
117+
118+
// FunctionAdvice message type identifier.
119+
// Advice that an action has taken place; receiver can only accept, not reject
120+
FunctionAdvice
121+
122+
// FunctionAdviceResponse message type identifier.
123+
// Response to an advice
124+
FunctionAdviceResponse
125+
126+
// FunctionNotification message type identifier.
127+
// Notification that an event has taken place; receiver can only accept, not reject
128+
FunctionNotification
129+
130+
// FunctionNotificationAcknowledgement message type identifier.
131+
// Response to a notification
132+
FunctionNotificationAcknowledgement
133+
134+
// FunctionInstruction message type identifier.
135+
// ISO 8583:2003
136+
FunctionInstruction
137+
138+
// FunctionInstructionAcknowledgement message type identifier.
139+
// Instruction acknowledgement
140+
FunctionInstructionAcknowledgement
141+
142+
// FunctionReservedByISO8 message type identifier.
143+
// Reserved for ISO.
144+
FunctionReservedByISO8
145+
146+
// FunctionReservedByISO9 message type identifier.
147+
// Reserved for ISO.
148+
FunctionReservedByISO9
101149
)
102150

103151
type class int
104152

105153
const (
106-
ClassReservedByISO000 class = iota * 100 //
107-
ClassAuthorizationMessage // Determine if funds are available, get an approval but do not post to account for reconciliation. Dual message system (DMS), awaits file exchange for posting to the account.
108-
ClassFinancialMessages // Determine if funds are available, get an approval and post directly to the account. Single message system (SMS), no file exchange after this.
109-
ClassFileActionsMessage // Used for hot-card, TMS and other exchanges
110-
ClassReversalAndChargebackMessages // Reversal (x4x0 or x4x1): Reverses the action of a previous authorization. Chargeback (x4x2 or x4x3): Charges back a previously cleared financial message.
111-
ClassReconciliationMessage // Transmits settlement information message.
112-
ClassAdministrativeMessage // Transmits administrative advice. Often used for failure messages (e.g., message reject or failure to apply).
113-
ClassFeeCollectionMessages //
114-
ClassNetworkManagementMessage // Used for secure key exchange, logon, echo test and other network functions.
115-
ClassReservedByISO900 //
154+
// ClassReservedByISO000 message type identifier.
155+
ClassReservedByISO000 class = iota * 100
156+
157+
// ClassAuthorizationMessage message type identifier.
158+
// Determine if funds are available, get an approval but do not post to account for reconciliation.
159+
// Dual message system (DMS), awaits file exchange for posting to the account.
160+
ClassAuthorizationMessage
161+
162+
// ClassFinancialMessages message type identifier.
163+
// Determine if funds are available, get an approval and post directly to the account. Single message system (SMS),
164+
// no file exchange after this.
165+
ClassFinancialMessages
166+
167+
// ClassFileActionsMessage message type identifier.
168+
// Used for hot-card, TMS and other exchanges
169+
ClassFileActionsMessage
170+
171+
// ClassReversalAndChargebackMessages message type identifier.
172+
// Reversal (x4x0 or x4x1): Reverses the action of a previous authorization.
173+
// Chargeback (x4x2 or x4x3): Charges back a previously cleared financial message.
174+
ClassReversalAndChargebackMessages
175+
176+
// ClassReconciliationMessage message type identifier.
177+
// Transmits settlement information message.
178+
ClassReconciliationMessage
179+
180+
// ClassAdministrativeMessage message type identifier.
181+
// Transmits administrative advice. Often used for failure messages (e.g., message reject or failure to apply).
182+
ClassAdministrativeMessage
183+
184+
// ClassFeeCollectionMessages message type identifier.
185+
ClassFeeCollectionMessages
186+
187+
// ClassNetworkManagementMessage message type identifier.
188+
// Used for secure key exchange, logon, echo test and other network functions.
189+
ClassNetworkManagementMessage
190+
191+
// ClassReservedByISO900 message type identifier.
192+
ClassReservedByISO900
116193
)
117194

118195
type version int
119196

120197
const (
121-
Version8583To1987 version = iota * 1000 //
122-
Version8583To1993 //
123-
Version8583To2003 //
124-
VersionReservedByISO3000 //
125-
VersionReservedByISO4000 //
126-
VersionReservedByISO5000 //
127-
VersionReservedByISO6000 //
128-
VersionReservedByISO7000 //
129-
VersionNationalUse //
130-
VersionPrivateUse //
198+
// Version8583To1987 message type identifier.
199+
Version8583To1987 version = iota * 1000
200+
201+
// Version8583To1993 message type identifier.
202+
Version8583To1993
203+
204+
// Version8583To2003 message type identifier.
205+
Version8583To2003
206+
207+
// VersionReservedByISO3000 message type identifier.
208+
VersionReservedByISO3000
209+
210+
// VersionReservedByISO4000 message type identifier.
211+
VersionReservedByISO4000
212+
213+
// VersionReservedByISO5000 message type identifier.
214+
VersionReservedByISO5000
215+
216+
// VersionReservedByISO6000 message type identifier.
217+
VersionReservedByISO6000
218+
219+
// VersionReservedByISO7000 message type identifier.
220+
VersionReservedByISO7000
221+
222+
// VersionNationalUse message type identifier.
223+
VersionNationalUse
224+
225+
// VersionPrivateUse message type identifier.
226+
VersionPrivateUse
131227
)
132228

133229
func itoa(n int) string { return strconv.Itoa(n) }

0 commit comments

Comments
 (0)