Susumu Yata
null+****@clear*****
Thu Jul 27 11:12:18 JST 2017
Susumu Yata 2017-07-27 11:12:18 +0900 (Thu, 27 Jul 2017) New Revision: 24a572a53ccf04d7624325a9ebd7c044292becf0 https://github.com/groonga/grnci/commit/24a572a53ccf04d7624325a9ebd7c044292becf0 Message: Add options to libgrn.Client. Modified files: v2/libgrn/client.go Modified: v2/libgrn/client.go (+28 -7) =================================================================== --- v2/libgrn/client.go 2017-07-27 11:07:41 +0900 (21b130d) +++ v2/libgrn/client.go 2017-07-27 11:12:18 +0900 (3de33db) @@ -7,9 +7,21 @@ import ( ) const ( - maxIdleConns = 2 // Maximum number of idle connections + defaultMaxIdleConns = 2 // Maximum number of idle connections ) +// ClientOptions is options of Client. +type ClientOptions struct { + MaxIdleConns int // Maximum number of idle connections +} + +// NewClientOptions returns the default ClientOptions. +func NewClientOptions() *ClientOptions { + return &ClientOptions{ + MaxIdleConns: defaultMaxIdleConns, + } +} + // Client is a thread-safe GQTP client or DB handle. type Client struct { addr string @@ -19,12 +31,15 @@ type Client struct { // DialClient returns a new Client connected to a GQTP server. // The expected address format is [scheme://][host][:port]. -func DialClient(addr string) (*Client, error) { +func DialClient(addr string, options *ClientOptions) (*Client, error) { + if options == nil { + options = NewClientOptions() + } conn, err := Dial(addr) if err != nil { return nil, err } - conns := make(chan *Conn, maxIdleConns) + conns := make(chan *Conn, options.MaxIdleConns) conns <- conn return &Client{ addr: addr, @@ -33,26 +48,32 @@ func DialClient(addr string) (*Client, error) { } // OpenClient opens an existing DB and returns a new Client. -func OpenClient(path string) (*Client, error) { +func OpenClient(path string, options *ClientOptions) (*Client, error) { + if options == nil { + options = NewClientOptions() + } conn, err := Open(path) if err != nil { return nil, err } return &Client{ baseConn: conn, - idleConns: make(chan *Conn, maxIdleConns), + idleConns: make(chan *Conn, options.MaxIdleConns), }, nil } // CreateClient creates a new DB and returns a new Client. -func CreateClient(path string) (*Client, error) { +func CreateClient(path string, options *ClientOptions) (*Client, error) { + if options == nil { + options = NewClientOptions() + } conn, err := Create(path) if err != nil { return nil, err } return &Client{ baseConn: conn, - idleConns: make(chan *Conn, maxIdleConns), + idleConns: make(chan *Conn, options.MaxIdleConns), }, nil } -------------- next part -------------- HTML����������������������������...Télécharger