diff --git a/README.md b/README.md index fca98d5..223e76e 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,10 @@ import ( ) func main() { - client, err := t38c.New("localhost:9851", t38c.Debug) + tile38, err := t38c.New(t38c.Config{ + Address: "localhost:9851", + Debug: true, // print queries to stdout + }) if err != nil { panic(err) } diff --git a/client.go b/client.go index d090e91..a1fce67 100644 --- a/client.go +++ b/client.go @@ -25,49 +25,33 @@ type Client struct { Server *Server } -type clientParams struct { - debug bool - password *string - poolSize int -} - -// ClientOption ... -type ClientOption func(*clientParams) - -// Debug option. -var Debug = ClientOption(func(c *clientParams) { - c.debug = true -}) - -// WithPassword option. -func WithPassword(password string) ClientOption { - return func(c *clientParams) { - c.password = &password - } -} - -// SetPoolSize option. -func SetPoolSize(size int) ClientOption { - return func(c *clientParams) { - c.poolSize = size - } +// Config is a t38c client config. +type Config struct { + // Tile38 server address. + // + // Example: localhost:9851 + Address string + + // Enables debug logging. + // Executed queries will be printed to stdout. + Debug bool + + // Allows to perform password authorization. + Password *string + + // ConnectionPoolSize sets number of connections in the pool. + // Defaults to 4. + ConnectionPoolSize int } // New creates a new Tile38 client. -// By default uses redis pool with 5 connections. -// In debug mode will also print commands which will be sent to the server. -func New(addr string, opts ...ClientOption) (*Client, error) { - params := &clientParams{poolSize: 5} - for _, opt := range opts { - opt(params) - } - - radixPool, err := transport.NewRadix(addr, params.poolSize, params.password) +func New(cfg Config) (*Client, error) { + radixPool, err := transport.NewRadix(cfg.Address, cfg.ConnectionPoolSize, cfg.Password) if err != nil { return nil, err } - return NewWithExecutor(radixPool, params.debug) + return NewWithExecutor(radixPool, cfg.Debug) } // NewWithExecutor creates a new Tile38 client with provided executor. diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index c56f456..5f68320 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -12,7 +12,10 @@ import ( func TestE2E(t *testing.T) { skipE2E(t) - client, err := t38c.New(os.Getenv("T38C_TEST_ADDR"), t38c.Debug) + client, err := t38c.New(t38c.Config{ + Address: os.Getenv("T38C_TEST_ADDR"), + Debug: true, + }) require.NoError(t, err) t.Run("TestKeys", func(t *testing.T) { diff --git a/examples/basic.go b/examples/basic.go index 53d8c48..45ac8b2 100644 --- a/examples/basic.go +++ b/examples/basic.go @@ -13,7 +13,10 @@ import ( ) func main() { - tile38, err := t38c.New("localhost:9851", t38c.Debug, t38c.SetPoolSize(10)) + tile38, err := t38c.New(t38c.Config{ + Address: "localhost:9851", + Debug: true, + }) if err != nil { log.Fatal(err) } diff --git a/examples/fields.go b/examples/fields.go index 8ba1570..b5f0ea8 100644 --- a/examples/fields.go +++ b/examples/fields.go @@ -11,7 +11,10 @@ import ( ) func main() { - tile38, err := t38c.New("localhost:9851", t38c.Debug) + tile38, err := t38c.New(t38c.Config{ + Address: "localhost:9851", + Debug: true, + }) if err != nil { log.Fatal(err) } diff --git a/examples/flush_db.go b/examples/flush_db.go index cf7b1cf..814b9eb 100644 --- a/examples/flush_db.go +++ b/examples/flush_db.go @@ -19,14 +19,11 @@ import ( */ func main() { - // Variables to be used along the way. - var ( - err error - tile38 *t38c.Client - ) - // Create a Tile38 client. - tile38, err = t38c.New("localhost:9851", t38c.Debug) + tile38, err := t38c.New(t38c.Config{ + Address: "localhost:9851", + Debug: true, + }) if err != nil { log.Fatal(err) } diff --git a/examples/geofencing.go b/examples/geofencing.go index 0888662..2aef2b9 100644 --- a/examples/geofencing.go +++ b/examples/geofencing.go @@ -13,7 +13,10 @@ import ( ) func main() { - tile38, err := t38c.New("localhost:9851", t38c.Debug) + tile38, err := t38c.New(t38c.Config{ + Address: "localhost:9851", + Debug: true, + }) if err != nil { log.Fatal(err) } diff --git a/examples/object_types.go b/examples/object_types.go index 9b252c1..e6cc123 100644 --- a/examples/object_types.go +++ b/examples/object_types.go @@ -12,7 +12,10 @@ import ( ) func main() { - tile38, err := t38c.New("localhost:9851", t38c.Debug) + tile38, err := t38c.New(t38c.Config{ + Address: "localhost:9851", + Debug: true, + }) if err != nil { log.Fatal(err) } diff --git a/examples/pubsub.go b/examples/pubsub.go index 5bb2e15..a88490c 100644 --- a/examples/pubsub.go +++ b/examples/pubsub.go @@ -13,7 +13,10 @@ import ( ) func main() { - tile38, err := t38c.New("localhost:9851", t38c.Debug) + tile38, err := t38c.New(t38c.Config{ + Address: "localhost:9851", + Debug: true, + }) if err != nil { log.Fatal(err) } diff --git a/examples/searching.go b/examples/searching.go index 4aa4725..8610788 100644 --- a/examples/searching.go +++ b/examples/searching.go @@ -14,7 +14,10 @@ import ( ) func main() { - tile38, err := t38c.New("localhost:9851", t38c.Debug) + tile38, err := t38c.New(t38c.Config{ + Address: "localhost:9851", + Debug: true, + }) if err != nil { log.Fatal(err) }