Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions db/etcd/etcd.client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package etcd

import (
"context"
"time"

tlsconfig "github.com/helays/utils/v2/crypto/tls.config"
"github.com/helays/utils/v2/tools"
"go.etcd.io/etcd/client/v3"
"time"
)

type Config struct {
Expand All @@ -28,33 +29,33 @@ type Config struct {
}

// NewClient 创建etcd客户端
func (this Config) NewClient(ctx context.Context) (*clientv3.Client, error) {
c := clientv3.Config{
Endpoints: this.Endpoints,
AutoSyncInterval: tools.AutoTimeDuration(this.AutoSyncInterval, time.Second),
DialTimeout: tools.AutoTimeDuration(this.DialTimeout, time.Second, 10*time.Second),
DialKeepAliveTime: tools.AutoTimeDuration(this.DialKeepAliveTime, time.Second),
DialKeepAliveTimeout: tools.AutoTimeDuration(this.DialKeepAliveTimeout, time.Second),
MaxCallSendMsgSize: this.MaxCallSendMsgSize,
MaxCallRecvMsgSize: this.MaxCallRecvMsgSize,
Username: this.Username,
Password: this.Password,
RejectOldCluster: this.RejectOldCluster,
func (c *Config) NewClient(ctx context.Context) (*clientv3.Client, error) {
cfg := clientv3.Config{
Endpoints: c.Endpoints,
AutoSyncInterval: tools.AutoTimeDuration(c.AutoSyncInterval, time.Second),
DialTimeout: tools.AutoTimeDuration(c.DialTimeout, time.Second, 10*time.Second),
DialKeepAliveTime: tools.AutoTimeDuration(c.DialKeepAliveTime, time.Second),
DialKeepAliveTimeout: tools.AutoTimeDuration(c.DialKeepAliveTimeout, time.Second),
MaxCallSendMsgSize: c.MaxCallSendMsgSize,
MaxCallRecvMsgSize: c.MaxCallRecvMsgSize,
Username: c.Username,
Password: c.Password,
RejectOldCluster: c.RejectOldCluster,
Context: ctx,
PermitWithoutStream: this.PermitWithoutStream,
MaxUnaryRetries: this.MaxUnaryRetries,
BackoffWaitBetween: tools.AutoTimeDuration(this.BackoffWaitBetween, time.Second),
BackoffJitterFraction: this.BackoffJitterFraction,
PermitWithoutStream: c.PermitWithoutStream,
MaxUnaryRetries: c.MaxUnaryRetries,
BackoffWaitBetween: tools.AutoTimeDuration(c.BackoffWaitBetween, time.Second),
BackoffJitterFraction: c.BackoffJitterFraction,
}

// 使用tls
if this.EnableTLS {
// 使用tls
tlsConfig, err := this.TLS.NewTLSConfig()
// 使用 tls
if c.EnableTLS {
// 使用 tls
tlsConfig, err := c.TLS.NewTLSConfig()
if err != nil {
return nil, err
}
c.TLS = tlsConfig
cfg.TLS = tlsConfig
}
return clientv3.New(c)
return clientv3.New(cfg)
}
49 changes: 26 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ require (
github.com/gorilla/handlers v1.5.2
github.com/gorilla/schema v1.4.1
github.com/helays/gomail/v2 v2.0.3
github.com/jackc/pgx/v5 v5.7.6
github.com/jackc/pgx/v5 v5.8.0
github.com/jlaffaye/ftp v0.2.0
github.com/malfunkt/iprange v0.9.0
github.com/minio/minio-go/v7 v7.0.97
github.com/minio/minio-go/v7 v7.0.98
github.com/nacos-group/nacos-sdk-go/v2 v2.3.5
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/pkg/errors v0.9.1
github.com/pkg/sftp v1.13.10
github.com/quic-go/quic-go v0.58.0
github.com/quic-go/quic-go v0.59.0
github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9
github.com/redis/go-redis/v9 v9.17.2
github.com/robfig/cron/v3 v3.0.1
Expand All @@ -41,11 +41,11 @@ require (
go.etcd.io/etcd/client/v3 v3.6.7
go.uber.org/zap v1.27.1
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba
golang.org/x/crypto v0.46.0
golang.org/x/exp v0.0.0-20251219203646-944ab1f22d93
golang.org/x/net v0.48.0
golang.org/x/text v0.32.0
gopkg.in/ini.v1 v1.67.0
golang.org/x/crypto v0.47.0
golang.org/x/exp v0.0.0-20260112195511-716be5621a96
golang.org/x/net v0.49.0
golang.org/x/text v0.33.0
gopkg.in/ini.v1 v1.67.1
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/mysql v1.6.0
Expand All @@ -61,14 +61,14 @@ require (
github.com/alibabacloud-go/darabonba-array v0.1.0 // indirect
github.com/alibabacloud-go/darabonba-encode-util v0.0.2 // indirect
github.com/alibabacloud-go/darabonba-map v0.0.2 // indirect
github.com/alibabacloud-go/darabonba-openapi/v2 v2.1.13 // indirect
github.com/alibabacloud-go/darabonba-openapi/v2 v2.1.14 // indirect
github.com/alibabacloud-go/darabonba-signature-util v0.0.7 // indirect
github.com/alibabacloud-go/darabonba-string v1.0.2 // indirect
github.com/alibabacloud-go/debug v1.0.1 // indirect
github.com/alibabacloud-go/endpoint-util v1.1.1 // indirect
github.com/alibabacloud-go/kms-20160120/v3 v3.4.0 // indirect
github.com/alibabacloud-go/openapi-util v0.1.1 // indirect
github.com/alibabacloud-go/tea v1.3.14 // indirect
github.com/alibabacloud-go/openapi-util v0.1.2 // indirect
github.com/alibabacloud-go/tea v1.4.0 // indirect
github.com/alibabacloud-go/tea-utils/v2 v2.0.9 // indirect
github.com/alibabacloud-go/tea-xml v1.1.3 // indirect
github.com/aliyun/alibaba-cloud-sdk-go v1.63.107 // indirect
Expand Down Expand Up @@ -102,12 +102,12 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.30.1 // indirect
github.com/goccy/go-yaml v1.19.1 // indirect
github.com/goccy/go-yaml v1.19.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.7.0-rc.1 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v1.0.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.4 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
Expand All @@ -124,13 +124,13 @@ require (
github.com/jinzhu/now v1.1.5 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.18.2 // indirect
github.com/klauspost/compress v1.18.3 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/klauspost/crc32 v1.3.0 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.32 // indirect
github.com/mattn/go-sqlite3 v1.14.33 // indirect
github.com/minio/crc64nvme v1.1.1 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand All @@ -140,18 +140,18 @@ require (
github.com/orcaman/concurrent-map v1.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/philhofer/fwd v1.2.0 // indirect
github.com/pierrec/lz4/v4 v4.1.23 // indirect
github.com/pierrec/lz4/v4 v4.1.25 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.23.2 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.67.4 // indirect
github.com/prometheus/common v0.67.5 // indirect
github.com/prometheus/procfs v0.19.2 // indirect
github.com/quic-go/qpack v0.6.0 // indirect
github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.4 // indirect
github.com/richardlehane/mscfb v1.0.6 // indirect
github.com/richardlehane/msoleps v1.0.6 // indirect
github.com/rs/xid v1.6.0 // indirect
github.com/tiendc/go-deepcopy v1.7.2 // indirect
github.com/tinylib/msgp v1.6.1 // indirect
github.com/tinylib/msgp v1.6.3 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.3.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
Expand All @@ -168,18 +168,21 @@ require (
go.uber.org/mock v0.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/arch v0.23.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.39.0 // indirect
golang.org/x/sys v0.40.0 // indirect
golang.org/x/time v0.14.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20251222181119-0a764e51fe1b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20251222181119-0a764e51fe1b // indirect
google.golang.org/genproto v0.0.0-20260114163908-3f89685c29c3 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260114163908-3f89685c29c3 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260114163908-3f89685c29c3 // indirect
google.golang.org/grpc v1.78.0 // indirect
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
)


// google.golang.org/genproto v0.0.0-20251111163417-95abcf5c77ba // indirect
// google.golang.org/genproto/googleapis/api v0.0.0-20251124214823-79d6a2a48846 // indirect
// google.golang.org/genproto/googleapis/rpc v0.0.0-20251124214823-79d6a2a48846 // indirect
Expand Down