forked from go-stomp/stomp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubscribe_options.go
42 lines (37 loc) · 1.11 KB
/
subscribe_options.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
package stomp
import (
"github.com/go-stomp/stomp/v3/frame"
)
// SubscribeOpt contains options for for the Conn.Subscribe function.
var SubscribeOpt struct {
// Id provides the opportunity to specify the value of the "id" header
// entry in the STOMP SUBSCRIBE frame.
//
// If the client program does specify the value for "id",
// it is responsible for choosing a unique value.
Id func(id string) func(*frame.Frame) error
// Header provides the opportunity to include custom header entries
// in the SUBSCRIBE frame that the client sends to the server.
Header func(key, value string) func(*frame.Frame) error
}
func init() {
SubscribeOpt.Id = func(id string) func(*frame.Frame) error {
return func(f *frame.Frame) error {
if f.Command != frame.SUBSCRIBE {
return ErrInvalidCommand
}
f.Header.Set(frame.Id, id)
return nil
}
}
SubscribeOpt.Header = func(key, value string) func(*frame.Frame) error {
return func(f *frame.Frame) error {
if f.Command != frame.SUBSCRIBE &&
f.Command != frame.UNSUBSCRIBE {
return ErrInvalidCommand
}
f.Header.Add(key, value)
return nil
}
}
}