Skip to content

Commit

Permalink
feat: refactor, update bootstrap.
Browse files Browse the repository at this point in the history
  • Loading branch information
tx7do committed May 6, 2024
1 parent 1086811 commit 6d448db
Show file tree
Hide file tree
Showing 121 changed files with 655 additions and 815 deletions.
12 changes: 6 additions & 6 deletions backend/api/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ deps:
- remote: buf.build
owner: envoyproxy
repository: protoc-gen-validate
commit: eac44469a7af47e7839a7f1f3d7ac004
digest: shake256:0feabcde01b6b11e3c75a5e3f807968d5995626546f39c37e5d4205892b3a59cced0ed83b35a2eb9e6dddd3309660ad46b737c9dcd224b425de0a6654ce04417
commit: ea113bc841fa448ab34bf3f9fa6cef0f
digest: shake256:8f3653779e824957a4fe3d18cdb73531f7f7ed1393848082dfe1f90026fd187da9534e759b5833f4e5487be0d34cfa7d4ff149af9a2694863773387d61d09fce
- remote: buf.build
owner: gnostic
repository: gnostic
Expand All @@ -19,8 +19,8 @@ deps:
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 28151c0d0a1641bf938a7672c500e01d
digest: shake256:49215edf8ef57f7863004539deff8834cfb2195113f0b890dd1f67815d9353e28e668019165b9d872395871eeafcbab3ccfdb2b5f11734d3cca95be9e8d139de
commit: 74015a8aeb8445aa9e3e1454cb54bc35
digest: shake256:7149cf5e9955c692d381e557830555d4e93f205a0f1b8e2dfdae46d029369aa3fc1980e35df0d310f7cc3b622f93e19ad276769a283a967dd3065ddfd3a40e13
- remote: buf.build
owner: kratos
repository: apis
Expand All @@ -29,5 +29,5 @@ deps:
- remote: buf.build
owner: tx7do
repository: pagination
commit: 66a7080a8ac446d0abfb0250f17cad60
digest: shake256:cb27e819fe006fad3688c7f6c882a65ebd1511c26301fc498d652d2d3b203d6afc46346bf6173243afc854914f256cd3ac77c2c5c18638809b2d31197873bcd1
commit: 7a9682e38b7d47d98eafd742399a16b0
digest: shake256:c2e448ce9c66de9838cd7573fb62d562f6649661ac4029471427bd00fcf7ecb5bebdaa79dbddb5616446345eff22c1f36a46b3717e0778b3933e24dabef03c34
2 changes: 1 addition & 1 deletion backend/app.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ build:
ifeq ("$(wildcard ./bin/)","")
mkdir bin
endif
@go build -ldflags "-X main.Service.Version=$(APP_VERSION)" -o ./bin/ ./...
@go build -ldflags "-X main.version=$(APP_VERSION)" -o ./bin/ ./...

# clean build files
clean:
Expand Down
20 changes: 10 additions & 10 deletions backend/app/admin/service/cmd/server/assets/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ paths:
description: 是否不分页
schema:
type: boolean
- name: fieldMask
- name: field_mask
in: query
description: 字段掩码
schema:
Expand Down Expand Up @@ -198,7 +198,7 @@ paths:
description: 是否不分页
schema:
type: boolean
- name: fieldMask
- name: field_mask
in: query
description: 字段掩码
schema:
Expand Down Expand Up @@ -346,7 +346,7 @@ paths:
description: 是否不分页
schema:
type: boolean
- name: fieldMask
- name: field_mask
in: query
description: 字段掩码
schema:
Expand Down Expand Up @@ -489,7 +489,7 @@ paths:
description: 是否不分页
schema:
type: boolean
- name: fieldMask
- name: field_mask
in: query
description: 字段掩码
schema:
Expand Down Expand Up @@ -688,7 +688,7 @@ paths:
description: 是否不分页
schema:
type: boolean
- name: fieldMask
- name: field_mask
in: query
description: 字段掩码
schema:
Expand Down Expand Up @@ -831,7 +831,7 @@ paths:
description: 是否不分页
schema:
type: boolean
- name: fieldMask
- name: field_mask
in: query
description: 字段掩码
schema:
Expand Down Expand Up @@ -974,7 +974,7 @@ paths:
description: 是否不分页
schema:
type: boolean
- name: fieldMask
- name: field_mask
in: query
description: 字段掩码
schema:
Expand Down Expand Up @@ -1117,7 +1117,7 @@ paths:
description: 是否不分页
schema:
type: boolean
- name: fieldMask
- name: field_mask
in: query
description: 字段掩码
schema:
Expand Down Expand Up @@ -1255,7 +1255,7 @@ paths:
description: 是否不分页
schema:
type: boolean
- name: fieldMask
- name: field_mask
in: query
description: 字段掩码
schema:
Expand Down Expand Up @@ -1398,7 +1398,7 @@ paths:
description: 是否不分页
schema:
type: boolean
- name: fieldMask
- name: field_mask
in: query
description: 字段掩码
schema:
Expand Down
37 changes: 6 additions & 31 deletions backend/app/admin/service/cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,21 @@ import (
"github.com/go-kratos/kratos/v2/log"
"github.com/go-kratos/kratos/v2/registry"
"github.com/go-kratos/kratos/v2/transport/http"

"github.com/tx7do/go-utils/trans"
"github.com/tx7do/kratos-bootstrap"

"kratos-cms/pkg/service"
)

// go build -ldflags "-X main.Service.Version=x.y.z"
var version string

var (
Service = bootstrap.NewServiceInfo(
service.AdminService,
"1.0.0",
"",
)
)
// go build -ldflags "-X main.version=x.y.z"

func newApp(ll log.Logger, rr registry.Registrar, hs *http.Server) *kratos.App {
return kratos.New(
kratos.ID(Service.GetInstanceId()),
kratos.Name(Service.Name),
kratos.Version(Service.Version),
kratos.Metadata(Service.Metadata),
kratos.Logger(ll),
kratos.Server(
hs,
),
kratos.Registrar(rr),
)
return bootstrap.NewApp(ll, rr, hs)
}

func main() {
// bootstrap
cfg, ll, reg := bootstrap.Bootstrap(Service)

app, cleanup, err := initApp(ll, reg, cfg)
if err != nil {
panic(err)
}
defer cleanup()

if err := app.Run(); err != nil {
panic(err)
}
bootstrap.Bootstrap(initApp, trans.Ptr(service.AdminService), trans.Ptr(version))
}
2 changes: 1 addition & 1 deletion backend/app/admin/service/cmd/server/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/go-kratos/kratos/v2/log"
"github.com/go-kratos/kratos/v2/registry"

conf "github.com/tx7do/kratos-bootstrap/gen/api/go/conf/v1"
conf "github.com/tx7do/kratos-bootstrap/api/gen/go/conf/v1"

"kratos-cms/app/admin/service/internal/data"
"kratos-cms/app/admin/service/internal/server"
Expand Down
4 changes: 2 additions & 2 deletions backend/app/admin/service/cmd/server/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 13 additions & 11 deletions backend/app/admin/service/internal/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
"github.com/go-kratos/kratos/v2/log"
"github.com/go-kratos/kratos/v2/registry"

"github.com/tx7do/kratos-bootstrap"
conf "github.com/tx7do/kratos-bootstrap/gen/api/go/conf/v1"
conf "github.com/tx7do/kratos-bootstrap/api/gen/go/conf/v1"
redisClient "github.com/tx7do/kratos-bootstrap/cache/redis"
bRegistry "github.com/tx7do/kratos-bootstrap/registry"
"github.com/tx7do/kratos-bootstrap/rpc"

commentV1 "kratos-cms/gen/api/go/comment/service/v1"
contentV1 "kratos-cms/gen/api/go/content/service/v1"
Expand Down Expand Up @@ -61,12 +63,12 @@ func NewData(redisClient *redis.Client,
// NewRedisClient 创建Redis客户端
func NewRedisClient(cfg *conf.Bootstrap, _ log.Logger) *redis.Client {
//l := log.NewHelper(log.With(logger, "module", "redis/data/admin-service"))
return bootstrap.NewRedisClient(cfg.Data)
return redisClient.NewClient(cfg.Data)
}

// NewDiscovery 创建服务发现客户端
func NewDiscovery(cfg *conf.Bootstrap) registry.Discovery {
return bootstrap.NewConsulRegistry(cfg.Registry)
return bRegistry.NewDiscovery(cfg.Registry)
}

// NewAuthenticator 创建认证器
Expand All @@ -92,29 +94,29 @@ func NewUserTokenRepo(data *Data, authenticator authnEngine.Authenticator, logge
}

func NewUserServiceClient(r registry.Discovery, c *conf.Bootstrap) userV1.UserServiceClient {
return userV1.NewUserServiceClient(bootstrap.CreateGrpcClient(context.Background(), r, service.CoreService, c))
return userV1.NewUserServiceClient(rpc.CreateGrpcClient(context.Background(), r, service.CoreService, c))
}

func NewAttachmentServiceClient(r registry.Discovery, c *conf.Bootstrap) fileV1.AttachmentServiceClient {
return fileV1.NewAttachmentServiceClient(bootstrap.CreateGrpcClient(context.Background(), r, service.CoreService, c))
return fileV1.NewAttachmentServiceClient(rpc.CreateGrpcClient(context.Background(), r, service.CoreService, c))
}

func NewCommentServiceClient(r registry.Discovery, c *conf.Bootstrap) commentV1.CommentServiceClient {
return commentV1.NewCommentServiceClient(bootstrap.CreateGrpcClient(context.Background(), r, service.CoreService, c))
return commentV1.NewCommentServiceClient(rpc.CreateGrpcClient(context.Background(), r, service.CoreService, c))
}

func NewCategoryServiceClient(r registry.Discovery, c *conf.Bootstrap) contentV1.CategoryServiceClient {
return contentV1.NewCategoryServiceClient(bootstrap.CreateGrpcClient(context.Background(), r, service.CoreService, c))
return contentV1.NewCategoryServiceClient(rpc.CreateGrpcClient(context.Background(), r, service.CoreService, c))
}

func NewLinkServiceClient(r registry.Discovery, c *conf.Bootstrap) contentV1.LinkServiceClient {
return contentV1.NewLinkServiceClient(bootstrap.CreateGrpcClient(context.Background(), r, service.CoreService, c))
return contentV1.NewLinkServiceClient(rpc.CreateGrpcClient(context.Background(), r, service.CoreService, c))
}

func NewPostServiceClient(r registry.Discovery, c *conf.Bootstrap) contentV1.PostServiceClient {
return contentV1.NewPostServiceClient(bootstrap.CreateGrpcClient(context.Background(), r, service.CoreService, c))
return contentV1.NewPostServiceClient(rpc.CreateGrpcClient(context.Background(), r, service.CoreService, c))
}

func NewTagServiceClient(r registry.Discovery, c *conf.Bootstrap) contentV1.TagServiceClient {
return contentV1.NewTagServiceClient(bootstrap.CreateGrpcClient(context.Background(), r, service.CoreService, c))
return contentV1.NewTagServiceClient(rpc.CreateGrpcClient(context.Background(), r, service.CoreService, c))
}
6 changes: 3 additions & 3 deletions backend/app/admin/service/internal/server/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (

swaggerUI "github.com/tx7do/kratos-swagger-ui"

bootstrap "github.com/tx7do/kratos-bootstrap"
conf "github.com/tx7do/kratos-bootstrap/gen/api/go/conf/v1"
conf "github.com/tx7do/kratos-bootstrap/api/gen/go/conf/v1"
"github.com/tx7do/kratos-bootstrap/rpc"

"kratos-cms/app/admin/service/cmd/server/assets"
"kratos-cms/app/admin/service/internal/service"
Expand Down Expand Up @@ -64,7 +64,7 @@ func NewHTTPServer(
tagSvc *service.TagService,
attachmentSvc *service.AttachmentService,
) *http.Server {
srv := bootstrap.CreateRestServer(cfg, newRestMiddleware(authenticator, authorizer, logger)...)
srv := rpc.CreateRestServer(cfg, newRestMiddleware(authenticator, authorizer, logger)...)

adminV1.RegisterAuthenticationServiceHTTPServer(srv, authnSvc)
adminV1.RegisterPostServiceHTTPServer(srv, postSvc)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/admin/service/internal/service/attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/go-kratos/kratos/v2/log"
"google.golang.org/protobuf/types/known/emptypb"

pagination "github.com/tx7do/kratos-bootstrap/gen/api/go/pagination/v1"
pagination "github.com/tx7do/kratos-bootstrap/api/gen/go/pagination/v1"
v1 "kratos-cms/gen/api/go/admin/service/v1"
fileV1 "kratos-cms/gen/api/go/file/service/v1"
)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/admin/service/internal/service/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/go-kratos/kratos/v2/log"
"google.golang.org/protobuf/types/known/emptypb"

pagination "github.com/tx7do/kratos-bootstrap/gen/api/go/pagination/v1"
pagination "github.com/tx7do/kratos-bootstrap/api/gen/go/pagination/v1"
v1 "kratos-cms/gen/api/go/admin/service/v1"
contentV1 "kratos-cms/gen/api/go/content/service/v1"
)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/admin/service/internal/service/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/go-kratos/kratos/v2/log"
"google.golang.org/protobuf/types/known/emptypb"

pagination "github.com/tx7do/kratos-bootstrap/gen/api/go/pagination/v1"
pagination "github.com/tx7do/kratos-bootstrap/api/gen/go/pagination/v1"
v1 "kratos-cms/gen/api/go/admin/service/v1"
commentV1 "kratos-cms/gen/api/go/comment/service/v1"
)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/admin/service/internal/service/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/go-kratos/kratos/v2/log"
"google.golang.org/protobuf/types/known/emptypb"

pagination "github.com/tx7do/kratos-bootstrap/gen/api/go/pagination/v1"
pagination "github.com/tx7do/kratos-bootstrap/api/gen/go/pagination/v1"
v1 "kratos-cms/gen/api/go/admin/service/v1"
contentV1 "kratos-cms/gen/api/go/content/service/v1"
)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/admin/service/internal/service/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/go-kratos/kratos/v2/log"
"google.golang.org/protobuf/types/known/emptypb"

pagination "github.com/tx7do/kratos-bootstrap/gen/api/go/pagination/v1"
pagination "github.com/tx7do/kratos-bootstrap/api/gen/go/pagination/v1"
v1 "kratos-cms/gen/api/go/admin/service/v1"
contentV1 "kratos-cms/gen/api/go/content/service/v1"
)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/admin/service/internal/service/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/go-kratos/kratos/v2/log"
"google.golang.org/protobuf/types/known/emptypb"

pagination "github.com/tx7do/kratos-bootstrap/gen/api/go/pagination/v1"
pagination "github.com/tx7do/kratos-bootstrap/api/gen/go/pagination/v1"
v1 "kratos-cms/gen/api/go/admin/service/v1"
contentV1 "kratos-cms/gen/api/go/content/service/v1"
)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/admin/service/internal/service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/tx7do/go-utils/trans"
"google.golang.org/protobuf/types/known/emptypb"

pagination "github.com/tx7do/kratos-bootstrap/gen/api/go/pagination/v1"
pagination "github.com/tx7do/kratos-bootstrap/api/gen/go/pagination/v1"
v1 "kratos-cms/gen/api/go/admin/service/v1"
userV1 "kratos-cms/gen/api/go/user/service/v1"

Expand Down
Loading

0 comments on commit 6d448db

Please sign in to comment.