forked from SAP/cgo-ase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recorder.go
47 lines (38 loc) · 1.08 KB
/
recorder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// SPDX-FileCopyrightText: 2020 SAP SE
// SPDX-FileCopyrightText: 2021 SAP SE
// SPDX-FileCopyrightText: 2022 SAP SE
// SPDX-FileCopyrightText: 2023 SAP SE
//
// SPDX-License-Identifier: Apache-2.0
package ase
import "sync"
// MessageRecorder can be utilized to record non-SQL responses
// from the server.
//
// See the example examples/recorder on how to utilize the
// MessageRecorder.
type MessageRecorder struct {
Messages []string
lock sync.Mutex
}
// NewMessageRecorder returns an initialized
// MessageRecorder.
func NewMessageRecorder() *MessageRecorder {
return new(MessageRecorder)
}
// Reset prepares the MessageRecorder to record a new message.
func (rec *MessageRecorder) Reset() {
rec.lock.Lock()
defer rec.lock.Unlock()
rec.Messages = make([]string, 0)
}
// HandleMessage implements the MessageHandler interface.
func (rec *MessageRecorder) HandleMessage(msg Message) {
rec.lock.Lock()
defer rec.lock.Unlock()
rec.Messages = append(rec.Messages, msg.Content())
}
// Text returns the received messages.
func (rec *MessageRecorder) Text() []string {
return rec.Messages
}