feat: refactor go.mod.

This commit is contained in:
tx7do
2024-11-14 15:47:21 +08:00
parent f3d17b9d34
commit 120029bb01
16 changed files with 675 additions and 175 deletions

View File

@@ -25,7 +25,7 @@ require (
github.com/tx7do/kratos-bootstrap/api v0.0.7
github.com/tx7do/kratos-bootstrap/config v0.0.5
github.com/tx7do/kratos-bootstrap/logger v0.0.6
github.com/tx7do/kratos-bootstrap/registry v0.0.5
github.com/tx7do/kratos-bootstrap/registry v0.0.6
github.com/tx7do/kratos-bootstrap/tracer v0.0.5
github.com/tx7do/kratos-bootstrap/utils v0.1.0
golang.org/x/tools v0.27.0

View File

@@ -70,6 +70,7 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4Yn
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
@@ -99,6 +100,7 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8Yc
github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ=
github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4=
github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo=
github.com/emicklei/go-restful v2.16.0+incompatible h1:rgqiKNjTnFQA6kkhFe16D8epTksy9HQ1MyrbDXSdYhM=
github.com/emicklei/go-restful/v3 v3.12.1 h1:PJMDIM/ak7btuL8Ex0iYET9hxM3CI2sjZtzpL63nKAU=
github.com/emicklei/go-restful/v3 v3.12.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
@@ -299,6 +301,7 @@ github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWS
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 h1:ad0vkEBuk23VJzZR9nkLVG0YAoN9coASF1GusYX6AlU=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0/go.mod h1:igFoXX2ELCW06bol23DWPB5BEWfZISOzSP5K2sbLea0=

View File

@@ -1,22 +1,24 @@
package apollo
import (
"github.com/go-kratos/kratos/v2/config"
// apollo
apolloKratos "github.com/go-kratos/kratos/contrib/config/apollo/v2"
"github.com/go-kratos/kratos/v2/config"
conf "github.com/tx7do/kratos-bootstrap/api/gen/go/conf/v1"
)
// NewConfigSource 创建一个远程配置源 - Apollo
func NewConfigSource(c *conf.RemoteConfig) config.Source {
func NewConfigSource(cfg *conf.RemoteConfig) config.Source {
if cfg == nil || cfg.Apollo == nil {
return nil
}
source := apolloKratos.NewSource(
apolloKratos.WithAppID(c.Apollo.AppId),
apolloKratos.WithCluster(c.Apollo.Cluster),
apolloKratos.WithEndpoint(c.Apollo.Endpoint),
apolloKratos.WithNamespace(c.Apollo.Namespace),
apolloKratos.WithSecret(c.Apollo.Secret),
apolloKratos.WithAppID(cfg.Apollo.AppId),
apolloKratos.WithCluster(cfg.Apollo.Cluster),
apolloKratos.WithEndpoint(cfg.Apollo.Endpoint),
apolloKratos.WithNamespace(cfg.Apollo.Namespace),
apolloKratos.WithSecret(cfg.Apollo.Secret),
apolloKratos.WithEnableBackup(),
)
return source

View File

@@ -22,6 +22,10 @@ func getConfigKey(configKey string, useBackslash bool) string {
// NewConfigSource 创建一个远程配置源 - Consul
func NewConfigSource(c *conf.RemoteConfig) config.Source {
if c == nil || c.Consul == nil {
return nil
}
cfg := consulApi.DefaultConfig()
cfg.Address = c.Consul.Address
cfg.Scheme = c.Consul.Scheme

View File

@@ -25,6 +25,10 @@ func getConfigKey(configKey string, useBackslash bool) string {
// NewConfigSource 创建一个远程配置源 - Etcd
func NewConfigSource(c *conf.RemoteConfig) config.Source {
if c == nil || c.Etcd == nil {
return nil
}
cfg := etcdClient.Config{
Endpoints: c.Etcd.Endpoints,
DialTimeout: c.Etcd.Timeout.AsDuration(),

View File

@@ -17,33 +17,53 @@ require (
github.com/go-kratos/kratos/contrib/config/etcd/v2 v2.0.0-20241105072421-f8b97f675b32
github.com/go-kratos/kratos/contrib/config/kubernetes/v2 v2.0.0-20241105072421-f8b97f675b32
github.com/go-kratos/kratos/contrib/config/nacos/v2 v2.0.0-20241105072421-f8b97f675b32
github.com/go-kratos/kratos/contrib/config/polaris/v2 v2.0.0-20241105072421-f8b97f675b32
github.com/go-kratos/kratos/v2 v2.8.2
github.com/hashicorp/consul/api v1.30.0
github.com/nacos-group/nacos-sdk-go v1.1.5
github.com/tx7do/kratos-bootstrap/api v0.0.5
github.com/polarismesh/polaris-go v1.5.8
github.com/tx7do/kratos-bootstrap/api v0.0.7
go.etcd.io/etcd/client/v3 v3.5.17
google.golang.org/grpc v1.68.0
k8s.io/client-go v0.31.2
)
require (
dario.cat/mergo v1.0.0 // indirect
github.com/aliyun/alibaba-cloud-sdk-go v1.61.18 // indirect
github.com/apolloconfig/agollo/v4 v4.3.1 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dlclark/regexp2 v1.11.4 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
github.com/polarismesh/specification v1.5.3 // indirect
github.com/prometheus/client_golang v1.20.5 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.60.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/sagikazarmark/locafero v0.6.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
)
require (
dario.cat/mergo v1.0.1 // indirect
github.com/aliyun/alibaba-cloud-sdk-go v1.63.51 // indirect
github.com/apolloconfig/agollo/v4 v4.4.0 // indirect
github.com/armon/go-metrics v0.5.3 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-errors/errors v1.5.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
@@ -52,18 +72,18 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/serf v0.10.1 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
github.com/imdario/mergo v1.0.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
@@ -72,44 +92,42 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.11.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/spf13/viper v1.19.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tx7do/kratos-bootstrap/utils v0.1.0
github.com/x448/float16 v0.8.4 // indirect
go.etcd.io/etcd/api/v3 v3.5.17 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.17 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.17.0 // indirect
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.24.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/term v0.26.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/time v0.8.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241113202542-65e8d215514f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241113202542-65e8d215514f // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.31.2 // indirect
k8s.io/apimachinery v0.31.2 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
k8s.io/utils v0.0.0-20241104163129-6fe5fd82f078 // indirect
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.3 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

File diff suppressed because it is too large Load Diff

View File

@@ -13,6 +13,10 @@ import (
// NewConfigSource 创建一个远程配置源 - Kubernetes
func NewConfigSource(c *conf.RemoteConfig) config.Source {
if c == nil || c.Kubernetes == nil {
return nil
}
source := k8sKratos.NewSource(
k8sKratos.Namespace(c.Kubernetes.Namespace),
k8sKratos.LabelSelector(""),

View File

@@ -25,6 +25,10 @@ func getConfigKey(configKey string, useBackslash bool) string {
// NewConfigSource 创建一个远程配置源 - Nacos
func NewConfigSource(c *conf.RemoteConfig) config.Source {
if c == nil || c.Nacos == nil {
return nil
}
srvConf := []nacosConstant.ServerConfig{
*nacosConstant.NewServerConfig(c.Nacos.Address, c.Nacos.Port),
}

View File

@@ -1,28 +1,32 @@
package polaris
import (
conf "github.com/tx7do/kratos-bootstrap/api/gen/go/conf/v1"
polarisKratos "github.com/go-kratos/kratos/contrib/config/polaris/v2"
"github.com/go-kratos/kratos/v2/config"
"github.com/go-kratos/kratos/v2/log"
polarisApi "github.com/polarismesh/polaris-go"
conf "github.com/tx7do/kratos-bootstrap/api/gen/go/conf/v1"
)
// NewConfigSource 创建一个远程配置源 - Polaris
func NewConfigSource(_ *conf.RemoteConfig) config.Source {
//configApi, err := polarisApi.NewConfigAPI()
//if err != nil {
// log.Fatal(err)
//}
//
//var opts []polarisKratos.Option
//opts = append(opts, polarisKratos.WithNamespace("default"))
//opts = append(opts, polarisKratos.WithFileGroup("default"))
//opts = append(opts, polarisKratos.WithFileName("default.yaml"))
//
//source, err := polarisKratos.New(configApi, opts...)
//if err != nil {
// log.Fatal(err)
//}
//
//return source
configApi, err := polarisApi.NewConfigAPI()
if err != nil {
log.Fatal(err)
}
var opts []polarisKratos.Option
opts = append(opts, polarisKratos.WithNamespace("default"))
opts = append(opts, polarisKratos.WithFileGroup("default"))
opts = append(opts, polarisKratos.WithFileName("default.yaml"))
source, err := polarisKratos.New(configApi, opts...)
if err != nil {
log.Fatal(err)
}
return source
return nil
}

View File

@@ -3,11 +3,16 @@ package aliyun
import (
aliyunLogger "github.com/go-kratos/kratos/contrib/log/aliyun/v2"
"github.com/go-kratos/kratos/v2/log"
conf "github.com/tx7do/kratos-bootstrap/api/gen/go/conf/v1"
)
// NewLogger 创建一个新的日志记录器 - Aliyun
func NewLogger(cfg *conf.Logger) log.Logger {
if cfg == nil || cfg.Aliyun == nil {
return nil
}
wrapped := aliyunLogger.NewAliyunLog(
aliyunLogger.WithProject(cfg.Aliyun.Project),
aliyunLogger.WithEndpoint(cfg.Aliyun.Endpoint),

View File

@@ -3,11 +3,16 @@ package fluent
import (
fluentLogger "github.com/go-kratos/kratos/contrib/log/fluent/v2"
"github.com/go-kratos/kratos/v2/log"
conf "github.com/tx7do/kratos-bootstrap/api/gen/go/conf/v1"
)
// NewLogger 创建一个新的日志记录器 - Fluent
func NewLogger(cfg *conf.Logger) log.Logger {
if cfg == nil || cfg.Fluent == nil {
return nil
}
wrapped, err := fluentLogger.NewLogger(cfg.Fluent.Endpoint)
if err != nil {
panic("create fluent logger failed")

View File

@@ -3,12 +3,18 @@ package logrus
import (
logrusLogger "github.com/go-kratos/kratos/contrib/log/logrus/v2"
"github.com/go-kratos/kratos/v2/log"
"github.com/sirupsen/logrus"
conf "github.com/tx7do/kratos-bootstrap/api/gen/go/conf/v1"
)
// NewLogger 创建一个新的日志记录器 - Logrus
func NewLogger(cfg *conf.Logger) log.Logger {
if cfg == nil || cfg.Logrus == nil {
return nil
}
loggerLevel, err := logrus.ParseLevel(cfg.Logrus.Level)
if err != nil {
loggerLevel = logrus.InfoLevel

View File

@@ -3,11 +3,16 @@ package tencent
import (
tencentLogger "github.com/go-kratos/kratos/contrib/log/tencent/v2"
"github.com/go-kratos/kratos/v2/log"
conf "github.com/tx7do/kratos-bootstrap/api/gen/go/conf/v1"
)
// NewLogger 创建一个新的日志记录器 - Tencent
func NewLogger(cfg *conf.Logger) log.Logger {
if cfg == nil || cfg.Tencent == nil {
return nil
}
wrapped, err := tencentLogger.NewLogger(
tencentLogger.WithTopicID(cfg.Tencent.TopicId),
tencentLogger.WithEndpoint(cfg.Tencent.Endpoint),

View File

@@ -2,18 +2,22 @@ package zap
import (
zapLogger "github.com/go-kratos/kratos/contrib/log/zap/v2"
"github.com/go-kratos/kratos/v2/log"
conf "github.com/tx7do/kratos-bootstrap/api/gen/go/conf/v1"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"gopkg.in/natefinch/lumberjack.v2"
conf "github.com/tx7do/kratos-bootstrap/api/gen/go/conf/v1"
)
// NewLogger 创建一个新的日志记录器 - Zap
func NewLogger(cfg *conf.Logger) log.Logger {
if cfg == nil || cfg.Zap == nil {
return nil
}
encoderConfig := zap.NewProductionEncoderConfig()
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
encoderConfig.TimeKey = "time"

View File

@@ -5,8 +5,8 @@ git tag utils/v0.1.0 --force
git tag cache/redis/v0.0.5 --force
git tag oss/minio/v0.0.5 --force
git tag registry/v0.0.6 --force
git tag config/v0.0.5 --force
git tag logger/v0.0.6 --force
git tag config/v0.0.6 --force
git tag logger/v0.0.7 --force
git tag rpc/v0.0.5 --force
git tag tracer/v0.0.5 --force