feat: refactor go.mod.
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
package gorm
|
||||
|
||||
import (
|
||||
"gorm.io/driver/bigquery"
|
||||
"gorm.io/driver/clickhouse"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/driver/sqlserver"
|
||||
|
||||
"gorm.io/plugin/opentelemetry/tracing"
|
||||
"gorm.io/plugin/prometheus"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/go-kratos/kratos/v2/log"
|
||||
@@ -40,9 +44,12 @@ func NewGormClient(cfg *conf.Bootstrap, l *log.Helper, migrates []interface{}) *
|
||||
case "sqlserver":
|
||||
driver = sqlserver.Open(cfg.Data.Database.Source)
|
||||
break
|
||||
case "bigquery":
|
||||
driver = bigquery.Open(cfg.Data.Database.Source)
|
||||
break
|
||||
}
|
||||
|
||||
client, err := gorm.Open(driver, &gorm.Config{})
|
||||
db, err := gorm.Open(driver, &gorm.Config{})
|
||||
if err != nil {
|
||||
l.Fatalf("failed opening connection to db: %v", err)
|
||||
return nil
|
||||
@@ -50,12 +57,50 @@ func NewGormClient(cfg *conf.Bootstrap, l *log.Helper, migrates []interface{}) *
|
||||
|
||||
// 运行数据库迁移工具
|
||||
if cfg.Data.Database.Migrate {
|
||||
if err = client.AutoMigrate(
|
||||
if err = db.AutoMigrate(
|
||||
migrates...,
|
||||
); err != nil {
|
||||
l.Fatalf("failed creating schema resources: %v", err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return client
|
||||
|
||||
if cfg.Data.Database.GetEnableTrace() {
|
||||
if err = db.Use(tracing.NewPlugin()); err != nil {
|
||||
l.Fatalf("failed enable trace: %v", err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.Data.Database.GetEnableMetrics() {
|
||||
db.Use(prometheus.New(prometheus.Config{
|
||||
DBName: "db1", // `DBName` as metrics label
|
||||
RefreshInterval: 15, // refresh metrics interval (default 15 seconds)
|
||||
PushAddr: "prometheus pusher address", // push metrics if `PushAddr` configured
|
||||
StartServer: true, // start http server to expose metrics
|
||||
HTTPServerPort: 8080, // configure http server port, default port 8080 (if you have configured multiple instances, only the first `HTTPServerPort` will be used to start server)
|
||||
MetricsCollector: []prometheus.MetricsCollector{
|
||||
&prometheus.MySQL{VariableNames: []string{"Threads_running"}},
|
||||
},
|
||||
Labels: map[string]string{
|
||||
"instance": "127.0.0.1", // config custom labels if necessary
|
||||
},
|
||||
}))
|
||||
|
||||
}
|
||||
|
||||
sqlDB, err := db.DB()
|
||||
if sqlDB != nil {
|
||||
if cfg.Data.Database.MaxIdleConnections != nil {
|
||||
sqlDB.SetMaxIdleConns(int(cfg.Data.Database.GetMaxIdleConnections()))
|
||||
}
|
||||
if cfg.Data.Database.MaxOpenConnections != nil {
|
||||
sqlDB.SetMaxOpenConns(int(cfg.Data.Database.GetMaxOpenConnections()))
|
||||
}
|
||||
if cfg.Data.Database.ConnectionMaxLifetime != nil {
|
||||
sqlDB.SetConnMaxLifetime(cfg.Data.Database.GetConnectionMaxLifetime().AsDuration())
|
||||
}
|
||||
}
|
||||
|
||||
return db
|
||||
}
|
||||
|
||||
@@ -9,25 +9,48 @@ replace github.com/tx7do/kratos-bootstrap/api => ../../api
|
||||
require (
|
||||
github.com/go-kratos/kratos/v2 v2.8.2
|
||||
github.com/tx7do/kratos-bootstrap/api v0.0.5
|
||||
gorm.io/driver/bigquery v1.2.0
|
||||
gorm.io/driver/clickhouse v0.6.1
|
||||
gorm.io/driver/mysql v1.5.7
|
||||
gorm.io/driver/postgres v1.5.9
|
||||
gorm.io/driver/sqlite v1.5.6
|
||||
gorm.io/driver/sqlserver v1.5.4
|
||||
gorm.io/gorm v1.25.12
|
||||
gorm.io/plugin/opentelemetry v0.1.8
|
||||
gorm.io/plugin/prometheus v0.1.0
|
||||
)
|
||||
|
||||
require (
|
||||
cloud.google.com/go v0.112.0 // indirect
|
||||
cloud.google.com/go/bigquery v1.58.0 // indirect
|
||||
cloud.google.com/go/compute v1.23.3 // indirect
|
||||
cloud.google.com/go/compute/metadata v0.2.3 // indirect
|
||||
cloud.google.com/go/iam v1.1.5 // indirect
|
||||
filippo.io/edwards25519 v1.1.0 // indirect
|
||||
github.com/ClickHouse/ch-go v0.63.1 // indirect
|
||||
github.com/ClickHouse/clickhouse-go/v2 v2.30.0 // indirect
|
||||
github.com/andybalholm/brotli v1.1.1 // indirect
|
||||
github.com/apache/arrow/go/v12 v12.0.1 // indirect
|
||||
github.com/apache/thrift v0.16.0 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||
github.com/go-faster/city v1.0.1 // indirect
|
||||
github.com/go-faster/errors v0.7.1 // indirect
|
||||
github.com/go-logr/logr v1.4.2 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-sql-driver/mysql v1.8.1 // indirect
|
||||
github.com/goccy/go-json v0.9.11 // indirect
|
||||
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
|
||||
github.com/golang-sql/sqlexp v0.1.0 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/flatbuffers v2.0.8+incompatible // indirect
|
||||
github.com/google/s2a-go v0.1.7 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
|
||||
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
|
||||
github.com/hashicorp/go-version v1.7.0 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
@@ -35,20 +58,47 @@ require (
|
||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/klauspost/asmfmt v1.3.2 // indirect
|
||||
github.com/klauspost/compress v1.17.11 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.14.24 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
|
||||
github.com/microsoft/go-mssqldb v1.7.2 // indirect
|
||||
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
|
||||
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect
|
||||
github.com/paulmach/orb v0.11.1 // indirect
|
||||
github.com/pierrec/lz4/v4 v4.1.21 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/prometheus/client_golang v1.17.0 // indirect
|
||||
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
|
||||
github.com/prometheus/common v0.44.0 // indirect
|
||||
github.com/prometheus/procfs v0.11.1 // indirect
|
||||
github.com/segmentio/asm v1.2.0 // indirect
|
||||
github.com/shopspring/decimal v1.4.0 // indirect
|
||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||
github.com/zeebo/xxh3 v1.0.2 // indirect
|
||||
go.opencensus.io v0.24.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
|
||||
go.opentelemetry.io/otel v1.32.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.32.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.32.0 // indirect
|
||||
golang.org/x/crypto v0.29.0 // indirect
|
||||
golang.org/x/mod v0.17.0 // indirect
|
||||
golang.org/x/net v0.30.0 // indirect
|
||||
golang.org/x/oauth2 v0.16.0 // indirect
|
||||
golang.org/x/sync v0.9.0 // indirect
|
||||
golang.org/x/sys v0.27.0 // indirect
|
||||
golang.org/x/text v0.20.0 // indirect
|
||||
golang.org/x/time v0.5.0 // indirect
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
|
||||
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
|
||||
google.golang.org/api v0.155.0 // indirect
|
||||
google.golang.org/appengine v1.6.8 // indirect
|
||||
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
|
||||
google.golang.org/grpc v1.62.1 // indirect
|
||||
google.golang.org/protobuf v1.35.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user