feat: 添加配置、数据库及中间件包 #1
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
yingmo/PharmacyERP!1
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/setup-base"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request overview
该 PR 为 PharmacyERP 初始化服务端基础设施层能力(配置、日志、数据库、MQ、Gin 中间件与路由),并提供可运行的
cmd/server入口,以便后续业务模块按约定注入路由。Changes:
Reviewed changes
Copilot reviewed 15 out of 17 changed files in this pull request and generated 7 comments.
Show a summary per file
cmd/server/main.gointernal/pkg/config/config.gointernal/pkg/logger/logger.gointernal/pkg/database/database.gointernal/pkg/mq/mq.gointernal/pkg/middleware/auth.gointernal/pkg/middleware/recovery.gointernal/pkg/middleware/request_logger.gointernal/router/router.gointernal/pkg/core/response.gointernal/pkg/core/pagination.gointernal/pkg/core/base_model.gointernal/pkg/ecode/ecode.goconfigs/config.example.yaml.gitignorego.mod/go.sum💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
@ -0,0 +51,4 @@if err := mqClient.Close(); err != nil {log.Error("close rabbitmq failed", zap.Error(err))}}()mq.NewClient returns (nil, nil) when RabbitMQ is disabled, but this defer unconditionally calls mqClient.Close(). That will panic on shutdown when cfg.RabbitMQ.Enabled is false. Guard the defer with
if mqClient != nil(or change NewClient to always return a non-nil no-op client when disabled).@ -4,0 +4,4 @@toolchain go1.22.12require (The
toolchain go1.22.12directive forcesgoto download/use that specific toolchain version, which can break builds in constrained CI environments or developer setups that pin a different toolchain. If the project doesn’t require a fixed toolchain, consider removing the toolchain directive (or aligning it with your CI/runtime expectations).@ -0,0 +164,4 @@}if c.RabbitMQ.Enabled && c.RabbitMQ.URI == "" {return fmt.Errorf("rabbitmq.uri is required when rabbitmq is enabled")}setDefaults() sets rabbitmq.enabled=true but does not set a default rabbitmq.uri, while validate() requires rabbitmq.uri when enabled. If a config file omits the rabbitmq section (or when relying on defaults/env), Load() will fail validation by default. Consider defaulting rabbitmq.enabled to false, or providing a sensible default URI for local dev, or relaxing validation unless the feature is explicitly enabled by the user.
@ -0,0 +23,4 @@Message: msg,Data: nil,})}Fail() always responds with HTTP 200 even for auth failures and server errors. This makes errors indistinguishable at the HTTP layer (e.g., middleware.JWTAuth will return 200 on unauthorized) and is inconsistent with router.NoRoute which uses HTTP 404. Consider adding an HTTP status parameter (or mapping business codes to statuses) so callers can return 401/500/etc when appropriate.
@ -0,0 +15,4 @@zap.Any("panic", rec),zap.ByteString("stack", debug.Stack()),)core.Fail(c, ecode.ErrSystem.Code, "system internal error")Recovery() hardcodes the error message "system internal error" even though ecode.ErrSystem already defines the canonical message. Using ecode.ErrSystem.Msg here avoids duplication and keeps responses consistent if the message changes.
@ -0,0 +107,4 @@return err}}return nilClient.Close() returns immediately if channel.Close() fails, so the AMQP connection may never be closed and resources can leak. Consider attempting to close both channel and connection and returning a combined error (e.g., keep first error, or use multierr).
@ -0,0 +22,4 @@Code: http.StatusNotFound,Message: "route not found",Data: nil,})NoRoute manually constructs a core.Response and uses HTTP 404, while most other error responses go through core.Fail() (which currently always uses HTTP 200). To keep the API response contract consistent, consider routing NoRoute through the same response helper(s) and aligning the HTTP status strategy (either always 200 + business code, or use proper HTTP statuses everywhere).