| 1 | package transportscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/ |
| 2 | |
| 3 | import ( |
| 4 | "bufioscip-go gomod github.com/golang/go/src go1.18 bufio/" |
| 5 | "bytesscip-go gomod github.com/golang/go/src go1.18 bytes/" |
| 6 | "ioscip-go gomod github.com/golang/go/src go1.18 io/" |
| 7 | "io/ioutilscip-go gomod github.com/golang/go/src go1.18 `io/ioutil`/" |
| 8 | |
| 9 | "github.com/mitch000001/go-hbci/messagescip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/message`/" |
| 10 | "github.com/mitch000001/go-hbci/segmentscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/segment`/" |
| 11 | ) |
| 12 | |
| 13 | // Transport defines an interface over the various ways data got exchanged with |
| 14 | // HBCI servers. It is used by higher level implementations to perform requests |
| 15 | // against the bank servers. |
| 16 | type Transportscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Transport# interface { |
| 17 | Doscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Transport#Do.(*Requestscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Request#) (*Responsescip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Response#, error) |
| 18 | } |
| 19 | |
| 20 | // The Func type is an adapter to allow the use of ordinary functions |
| 21 | // as Transport handlers. If f is a function with the appropriate signature, |
| 22 | // Func(f) is a Transport that calls f. |
| 23 | type Funcscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Func# func(*Requestscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Request#) (*Responsescip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Response#, error) |
| 24 | |
| 25 | // Do calls fn(req). |
| 26 | func (fn Funcscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Func#) Doscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Func#Do().(req *Requestscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Request#) (*Responsescip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Response#, error) { |
| 27 | return fn(req) |
| 28 | } |
| 29 | |
| 30 | // Middleware defines the interface for writing middleware for transports |
| 31 | type Middlewarescip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Middleware# func(Transportscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Transport#) Transportscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Transport# |
| 32 | |
| 33 | // A Request represents a client request to a HBCI server |
| 34 | type Requestscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Request# struct { |
| 35 | // URL specifies the URI being requested |
| 36 | // |
| 37 | // For the sake of simplicity this is a string instead a *url.URL right now |
| 38 | URLscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Request#URL. string |
| 39 | // Body is the request's body. |
| 40 | // |
| 41 | // Body has always to be non-nil |
| 42 | Bodyscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Request#Body. ioscip-go gomod github.com/golang/go/src go1.18 io/.ReadCloserscip-go gomod github.com/golang/go/src go1.18 io/ReadCloser# |
| 43 | } |
| 44 | |
| 45 | // ReadResponse reads and returns a Response from r. It populates the embedded |
| 46 | // SegmentExtractor to have it ready to use. |
| 47 | func ReadResponsescip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/ReadResponse().(r *bufioscip-go gomod github.com/golang/go/src go1.18 bufio/.Readerscip-go gomod github.com/golang/go/src go1.18 bufio/Reader#, req *Requestscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Request#) (*Responsescip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Response#, error) { |
| 48 | var buf bytesscip-go gomod github.com/golang/go/src go1.18 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.18 bytes/Buffer# |
| 49 | marshaledMessage, err := ioutilscip-go gomod github.com/golang/go/src go1.18 `io/ioutil`/.ReadAllscip-go gomod github.com/golang/go/src go1.18 `io/ioutil`/ReadAll().(ioscip-go gomod github.com/golang/go/src go1.18 io/.TeeReaderscip-go gomod github.com/golang/go/src go1.18 io/TeeReader().(r, &buf)) |
| 50 | if err != nil { |
| 51 | return nil, err |
| 52 | } |
| 53 | extractor := messagescip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/message`/.NewSegmentExtractorscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/message`/NewSegmentExtractor().(marshaledMessage) |
| 54 | _, err = extractor.Extractscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/message`/SegmentExtractor#Extract().() |
| 55 | if err != nil { |
| 56 | return nil, err |
| 57 | } |
| 58 | response := &Responsescip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Response#{ |
| 59 | Requestscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Response#Request.: req, |
| 60 | MarshaledResponsescip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Response#MarshaledResponse.: marshaledMessage, |
| 61 | SegmentExtractorscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Response#SegmentExtractor.: extractor, |
| 62 | Bodyscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Response#Body.: ioutilscip-go gomod github.com/golang/go/src go1.18 `io/ioutil`/.NopCloserscip-go gomod github.com/golang/go/src go1.18 `io/ioutil`/NopCloser().(&buf), |
| 63 | } |
| 64 | return response, nil |
| 65 | } |
| 66 | |
| 67 | // A Response represents a server response from a HBCI server |
| 68 | type Responsescip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Response# struct { |
| 69 | // The SegmentExtractor can be used to conveniently query segments from the |
| 70 | // Response. |
| 71 | // |
| 72 | // Right now the Response embeds the SegmentExtractor, which violates the SRP. |
| 73 | // Future Response types may get rid of it. |
| 74 | *messagescip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/message`/.SegmentExtractorscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Response#SegmentExtractor. |
| 75 | // Request is the request that was sent to obtain this Response. |
| 76 | // Request's Body is nil (having already been consumed). |
| 77 | Requestscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Response#Request. *Requestscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Request# |
| 78 | // MarshaledResponse represents the body payload as byte slice. It's strongly |
| 79 | // discouraged to use that as it may or may not be populated by the Transport. |
| 80 | // |
| 81 | // It's only there for legacy reasons. |
| 82 | MarshaledResponsescip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Response#MarshaledResponse. []byte |
| 83 | // Body represents the response body. |
| 84 | Bodyscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Response#Body. ioscip-go gomod github.com/golang/go/src go1.18 io/.ReadCloserscip-go gomod github.com/golang/go/src go1.18 io/ReadCloser# |
| 85 | } |
| 86 | |
| 87 | // IsEncrypted returns whether the response contains an encrypted message. |
| 88 | // This method will panic when the SegmentExtractor is not populated. |
| 89 | func (h *Responsescip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Response#) IsEncryptedscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Response#IsEncrypted().() bool { |
| 90 | return h.SegmentExtractorscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/transport`/Response#SegmentExtractor..FindSegmentscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/message`/SegmentExtractor#FindSegment().(segmentscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/segment`/.EncryptionHeaderSegmentIDscip-go gomod github.com/mitch000001/go-hbci . `github.com/mitch000001/go-hbci/segment`/EncryptionHeaderSegmentID.) != nil |
| 91 | } |