Skip to content

Commit

Permalink
refactor clientOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jnan806 committed Feb 9, 2023
1 parent 9fca930 commit a4de0ac
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 114 deletions.
11 changes: 6 additions & 5 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ import (
"github.com/opensergo/opensergo-go/pkg/transport/subscribe"
)

type OpensergoOptions struct {
}

type OpensergoOption func(*OpensergoOptions)

type ClientOptions struct {
connectRetryTimes uint
}

func NewDefaultClientOptions() *ClientOptions {
return &ClientOptions{
connectRetryTimes: 3,
}
}

func (opts *ClientOptions) ConnectRetryTimes() uint {
return opts.connectRetryTimes
}
Expand Down
14 changes: 3 additions & 11 deletions pkg/client/opensergo_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/opensergo/opensergo-go/pkg/api"
"github.com/opensergo/opensergo-go/pkg/client/stream"
"github.com/opensergo/opensergo-go/pkg/common/logging"
"github.com/opensergo/opensergo-go/pkg/global"
"github.com/opensergo/opensergo-go/pkg/model"
transportPb "github.com/opensergo/opensergo-go/pkg/proto/transport/v1"
"github.com/opensergo/opensergo-go/pkg/transport/subscribe"
Expand All @@ -34,8 +33,7 @@ type OpenSergoClient struct {
host string
port uint32

opensergoOptions *api.OpensergoOptions
clientOptions *api.ClientOptions
clientOptions *api.ClientOptions

transportServiceClient transportPb.OpenSergoUniversalTransportServiceClient
subscribeConfigOutsStream *stream.SubscribeConfigOutsStream
Expand All @@ -45,12 +43,7 @@ type OpenSergoClient struct {

// NewOpenSergoClient returns an instance of OpenSergoClient, and init some properties.
func NewOpenSergoClient(host string, port uint32, opts ...api.ClientOption) (*OpenSergoClient, error) {
// globalOpts
globalOptions := global.GetGlobalOptions()
// OpensergoOptions from GetGlobalOptions
opensergoOptions := globalOptions.OpensergoOptions()
// ClientOptions from GetGlobalOptions
clientOptions := globalOptions.ClientOptions()
clientOptions := api.NewDefaultClientOptions()
// override default ClientOptions by params
if len(opts) > 0 {
for _, opt := range opts {
Expand All @@ -68,10 +61,9 @@ func NewOpenSergoClient(host string, port uint32, opts ...api.ClientOption) (*Op
openSergoClient := &OpenSergoClient{
host: host,
port: port,
opensergoOptions: opensergoOptions,
clientOptions: clientOptions,
transportServiceClient: transportServiceClient,
subscribeConfigOutsStream: stream.NewSubscribeConfigOutsStream(opensergoOptions, clientOptions, transportServiceClient),
subscribeConfigOutsStream: stream.NewSubscribeConfigOutsStream(clientOptions, transportServiceClient),
requestId: groupcache.AtomicInt(0),
}
return openSergoClient, nil
Expand Down
6 changes: 2 additions & 4 deletions pkg/client/stream/subscribeconfig_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ import (
type SubscribeConfigOutsStream struct {
outsStream

opensergoOptions *api.OpensergoOptions
clientOptions *api.ClientOptions
clientOptions *api.ClientOptions

transportServiceClient transportPb.OpenSergoUniversalTransportServiceClient

Expand All @@ -55,9 +54,8 @@ type subscribeConfigPbStreamObserverWrapper struct {
observer *subscribeConfigPbStreamObserver
}

func NewSubscribeConfigOutsStream(opensergoOptions *api.OpensergoOptions, clientOptions *api.ClientOptions, transportServiceClient transportPb.OpenSergoUniversalTransportServiceClient) *SubscribeConfigOutsStream {
func NewSubscribeConfigOutsStream(clientOptions *api.ClientOptions, transportServiceClient transportPb.OpenSergoUniversalTransportServiceClient) *SubscribeConfigOutsStream {
stream := &SubscribeConfigOutsStream{
opensergoOptions: opensergoOptions,
clientOptions: clientOptions,
transportServiceClient: transportServiceClient,
SubscribeDataCache: &subscribe.SubscribeDataCache{},
Expand Down
16 changes: 0 additions & 16 deletions pkg/global/doc.go

This file was deleted.

78 changes: 0 additions & 78 deletions pkg/global/global_options.go

This file was deleted.

0 comments on commit a4de0ac

Please sign in to comment.