summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/couchbaselabs/go-couchbase/conn_pool.go
diff options
context:
space:
mode:
authorTamal Saha <tamal@appscode.com>2019-08-23 09:40:30 -0700
committertechknowlogick <techknowlogick@gitea.io>2019-08-23 12:40:29 -0400
commit171b3598778a1ecd0a921c71ed6755bfef68f7f0 (patch)
tree02857629ef9e8e26ee0ee559153f803f77b588b7 /vendor/github.com/couchbaselabs/go-couchbase/conn_pool.go
parentca6fb004ac50fc924861112403895d637c6a2d1d (diff)
downloadgitea-171b3598778a1ecd0a921c71ed6755bfef68f7f0.tar.gz
gitea-171b3598778a1ecd0a921c71ed6755bfef68f7f0.zip
Use gitea forked macaron (#7933)
Signed-off-by: Tamal Saha <tamal@appscode.com>
Diffstat (limited to 'vendor/github.com/couchbaselabs/go-couchbase/conn_pool.go')
-rw-r--r--vendor/github.com/couchbaselabs/go-couchbase/conn_pool.go33
1 files changed, 28 insertions, 5 deletions
diff --git a/vendor/github.com/couchbaselabs/go-couchbase/conn_pool.go b/vendor/github.com/couchbaselabs/go-couchbase/conn_pool.go
index babd3adb6a..23102abd84 100644
--- a/vendor/github.com/couchbaselabs/go-couchbase/conn_pool.go
+++ b/vendor/github.com/couchbaselabs/go-couchbase/conn_pool.go
@@ -1,6 +1,7 @@
package couchbase
import (
+ "crypto/tls"
"errors"
"sync/atomic"
"time"
@@ -36,7 +37,7 @@ var ConnPoolAvailWaitTime = time.Millisecond
type connectionPool struct {
host string
- mkConn func(host string, ah AuthHandler) (*memcached.Client, error)
+ mkConn func(host string, ah AuthHandler, tlsConfig *tls.Config, bucketName string) (*memcached.Client, error)
auth AuthHandler
connections chan *memcached.Client
createsem chan bool
@@ -44,9 +45,11 @@ type connectionPool struct {
poolSize int
connCount uint64
inUse bool
+ tlsConfig *tls.Config
+ bucket string
}
-func newConnectionPool(host string, ah AuthHandler, closer bool, poolSize, poolOverflow int) *connectionPool {
+func newConnectionPool(host string, ah AuthHandler, closer bool, poolSize, poolOverflow int, tlsConfig *tls.Config, bucket string) *connectionPool {
connSize := poolSize
if closer {
connSize += poolOverflow
@@ -58,6 +61,8 @@ func newConnectionPool(host string, ah AuthHandler, closer bool, poolSize, poolO
mkConn: defaultMkConn,
auth: ah,
poolSize: poolSize,
+ tlsConfig: tlsConfig,
+ bucket: bucket,
}
if closer {
rv.bailOut = make(chan bool, 1)
@@ -69,10 +74,19 @@ func newConnectionPool(host string, ah AuthHandler, closer bool, poolSize, poolO
// ConnPoolTimeout is notified whenever connections are acquired from a pool.
var ConnPoolCallback func(host string, source string, start time.Time, err error)
-func defaultMkConn(host string, ah AuthHandler) (*memcached.Client, error) {
+// Use regular in-the-clear connection if tlsConfig is nil.
+// Use secure connection (TLS) if tlsConfig is set.
+func defaultMkConn(host string, ah AuthHandler, tlsConfig *tls.Config, bucketName string) (*memcached.Client, error) {
var features memcached.Features
- conn, err := memcached.Connect("tcp", host)
+ var conn *memcached.Client
+ var err error
+ if tlsConfig == nil {
+ conn, err = memcached.Connect("tcp", host)
+ } else {
+ conn, err = memcached.ConnectTLS("tcp", host, tlsConfig)
+ }
+
if err != nil {
return nil, err
}
@@ -92,6 +106,10 @@ func defaultMkConn(host string, ah AuthHandler) (*memcached.Client, error) {
features = append(features, memcached.FeatureXattr)
}
+ if EnableCollections {
+ features = append(features, memcached.FeatureCollections)
+ }
+
if len(features) > 0 {
if DefaultTimeout > 0 {
conn.SetDeadline(getDeadline(noDeadline, DefaultTimeout))
@@ -122,6 +140,11 @@ func defaultMkConn(host string, ah AuthHandler) (*memcached.Client, error) {
return conn, nil
}
name, pass, bucket := ah.GetCredentials()
+ if bucket == "" {
+ // Authenticator does not know specific bucket.
+ bucket = bucketName
+ }
+
if name != "default" {
_, err = conn.Auth(name, pass)
if err != nil {
@@ -221,7 +244,7 @@ func (cp *connectionPool) GetWithTimeout(d time.Duration) (rv *memcached.Client,
// Build a connection if we can't get a real one.
// This can potentially be an overflow connection, or
// a pooled connection.
- rv, err := cp.mkConn(cp.host, cp.auth)
+ rv, err := cp.mkConn(cp.host, cp.auth, cp.tlsConfig, cp.bucket)
if err != nil {
// On error, release our create hold
<-cp.createsem