This commit is contained in:
vipg
2025-11-11 18:27:51 +08:00
parent 8d6c211767
commit 0ea63d2ba7
3 changed files with 8 additions and 7 deletions

View File

@@ -4,7 +4,7 @@ services:
container_name: country_db
restart: always
ports:
- 20001:5432
- 20011:5432
entrypoint:
- /scripts/db-lanuch-entrypoint.sh
environment:
@@ -23,7 +23,7 @@ services:
container_name: country_api
restart: always
ports:
- 20000:80
- 20010:80
depends_on:
- postgres
networks:

View File

@@ -8,7 +8,6 @@ require (
github.com/lib/pq v1.10.9
github.com/spf13/viper v1.21.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.43.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
)
@@ -46,6 +45,7 @@ require (
go.uber.org/multierr v1.10.0 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/arch v0.20.0 // indirect
golang.org/x/crypto v0.43.0 // indirect
golang.org/x/mod v0.28.0 // indirect
golang.org/x/net v0.45.0 // indirect
golang.org/x/sync v0.17.0 // indirect

View File

@@ -139,13 +139,14 @@ func ReadHandler(c *gin.Context) {
// 计算分页偏移量
offset := (page - 1) * pageSize
// 拼接分页SQL
querySQL := baseSQL + " ORDER BY country_id LIMIT $"+strconv.Itoa(paramIndex)+" OFFSET $"+strconv.Itoa(paramIndex+1)
// 拼接分页SQL使用fmt.Sprintf更清晰
querySQL := fmt.Sprintf("%s ORDER BY country_id LIMIT $%d OFFSET $%d", baseSQL, paramIndex, paramIndex+1)
args = append(args, pageSize, offset)
// 查询总条数
// 查询总条数(修正参数传递方式)
var total int64
err = db.DB.QueryRow(countSQL, args...[:len(args)-2]...).Scan(&total)
countArgs := args[:len(args)-2] // 排除分页参数
err = db.DB.QueryRow(countSQL, countArgs...).Scan(&total)
if err != nil {
zap.L().Error("❌ 查询总条数失败",
zap.String("req_id", reqID),