@@ -19,38 +19,70 @@ import (
1919 "github.com/opensergo/opensergo-go/pkg/transport/subscribe"
2020)
2121
22+ type ClientOptions struct {
23+ connectRetryTimes uint
24+ }
25+
26+ func NewDefaultClientOptions () * ClientOptions {
27+ return & ClientOptions {
28+ connectRetryTimes : 3 ,
29+ }
30+ }
31+
32+ func (opts * ClientOptions ) ConnectRetryTimes () uint {
33+ return opts .connectRetryTimes
34+ }
35+
36+ type ClientOption func (* ClientOptions )
37+
38+ func WithConnectRetryTimes (connectRetryTimes uint ) ClientOption {
39+ return func (opts * ClientOptions ) {
40+ opts .connectRetryTimes = connectRetryTimes
41+ }
42+ }
43+
2244// SubscribeOptions represents the options of OpenSergo data subscription.
2345type SubscribeOptions struct {
24- Subscribers []subscribe.Subscriber
25- Attachments map [string ]interface {}
46+ subscribers []subscribe.Subscriber
47+ attachments map [string ]interface {}
48+ }
49+
50+ func (opts * SubscribeOptions ) Subscribers () []subscribe.Subscriber {
51+ return opts .subscribers
52+ }
53+
54+ func (opts * SubscribeOptions ) Attachments () map [string ]interface {} {
55+ return opts .attachments
2656}
2757
2858type SubscribeOption func (* SubscribeOptions )
2959
3060// WithSubscriber provides a subscriber.
3161func WithSubscriber (subscriber subscribe.Subscriber ) SubscribeOption {
3262 return func (opts * SubscribeOptions ) {
33- if opts .Subscribers == nil {
34- opts .Subscribers = make ([]subscribe.Subscriber , 0 )
63+ if opts .subscribers == nil {
64+ opts .subscribers = make ([]subscribe.Subscriber , 0 )
3565 }
36- opts .Subscribers = append (opts .Subscribers , subscriber )
66+ opts .subscribers = append (opts .subscribers , subscriber )
3767 }
3868}
3969
4070// WithAttachment provides an attachment (key-value pair).
4171func WithAttachment (key string , value interface {}) SubscribeOption {
4272 return func (opts * SubscribeOptions ) {
43- if opts .Attachments == nil {
44- opts .Attachments = make (map [string ]interface {})
73+ if opts .attachments == nil {
74+ opts .attachments = make (map [string ]interface {})
4575 }
46- opts .Attachments [key ] = value
76+ opts .attachments [key ] = value
4777 }
4878}
4979
5080// OpenSergoClient is the universal interface of OpenSergo client.
5181type OpenSergoClient interface {
5282 // Start the client.
5383 Start () error
84+ // Close the client.
85+ Close () error
5486 // SubscribeConfig subscribes data for given subscribe target.
5587 SubscribeConfig (key model.SubscribeKey , opts ... SubscribeOption ) error
5688 // UnsubscribeConfig unsubscribes data for given subscribe target.
0 commit comments