add
This commit is contained in:
@@ -4,7 +4,7 @@ services:
|
|||||||
container_name: country_db
|
container_name: country_db
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- 20001:5432
|
- 20011:5432
|
||||||
entrypoint:
|
entrypoint:
|
||||||
- /scripts/db-lanuch-entrypoint.sh
|
- /scripts/db-lanuch-entrypoint.sh
|
||||||
environment:
|
environment:
|
||||||
@@ -23,7 +23,7 @@ services:
|
|||||||
container_name: country_api
|
container_name: country_api
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- 20000:80
|
- 20010:80
|
||||||
depends_on:
|
depends_on:
|
||||||
- postgres
|
- postgres
|
||||||
networks:
|
networks:
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ require (
|
|||||||
github.com/lib/pq v1.10.9
|
github.com/lib/pq v1.10.9
|
||||||
github.com/spf13/viper v1.21.0
|
github.com/spf13/viper v1.21.0
|
||||||
go.uber.org/zap v1.27.0
|
go.uber.org/zap v1.27.0
|
||||||
golang.org/x/crypto v0.43.0
|
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -46,6 +45,7 @@ require (
|
|||||||
go.uber.org/multierr v1.10.0 // indirect
|
go.uber.org/multierr v1.10.0 // indirect
|
||||||
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
||||||
golang.org/x/arch v0.20.0 // 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/mod v0.28.0 // indirect
|
||||||
golang.org/x/net v0.45.0 // indirect
|
golang.org/x/net v0.45.0 // indirect
|
||||||
golang.org/x/sync v0.17.0 // indirect
|
golang.org/x/sync v0.17.0 // indirect
|
||||||
|
|||||||
@@ -139,13 +139,14 @@ func ReadHandler(c *gin.Context) {
|
|||||||
// 计算分页偏移量
|
// 计算分页偏移量
|
||||||
offset := (page - 1) * pageSize
|
offset := (page - 1) * pageSize
|
||||||
|
|
||||||
// 拼接分页SQL
|
// 拼接分页SQL(使用fmt.Sprintf更清晰)
|
||||||
querySQL := baseSQL + " ORDER BY country_id LIMIT $"+strconv.Itoa(paramIndex)+" OFFSET $"+strconv.Itoa(paramIndex+1)
|
querySQL := fmt.Sprintf("%s ORDER BY country_id LIMIT $%d OFFSET $%d", baseSQL, paramIndex, paramIndex+1)
|
||||||
args = append(args, pageSize, offset)
|
args = append(args, pageSize, offset)
|
||||||
|
|
||||||
// 查询总条数
|
// 查询总条数(修正参数传递方式)
|
||||||
var total int64
|
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 {
|
if err != nil {
|
||||||
zap.L().Error("❌ 查询总条数失败",
|
zap.L().Error("❌ 查询总条数失败",
|
||||||
zap.String("req_id", reqID),
|
zap.String("req_id", reqID),
|
||||||
|
|||||||
Reference in New Issue
Block a user