弃用自定义错误函数,直接使用 fiber.Err;更新 README.md 文档

This commit is contained in:
2025-05-15 10:24:02 +08:00
parent 661616dfc3
commit f5396ce9d8
5 changed files with 4 additions and 69 deletions

View File

@@ -1,41 +1,3 @@
## todo
- 页面 账户总览
- 页面 提取记录
- 页面 使用记录
### 长效业务
- 支付回调处理
- 公众号的到期提示
### 长期
- 修改日志输出提高可读性
- 用户最后登录的数据可以通过 session 表进行查询,不再保存在 user 表里
- callback 结果直接由 api 端提供,不通过前端转发
- debug白银节点提供一些工具接口方便快速操作
- 批量下线端口
- 代理数据表的 secret 字段 aes 加密存储
- 废弃 password 授权模式,迁移到 authorization code 授权模式
- oauth token 验证授权范围
- 实现白银节点的 warp 服务,用来去重与端口分配,保证测试与生产环境不会产生端口竞争
- 统一使用 validator 进行参数验证
- 分离项目脚手架envlogsServer 结构体)
- 业务代码和测试代码共用的控制变量可以优化为环境变量
- 考虑统计接口调用频率并通过接口展示
- 考虑登录时曾经输入过验证码的用户,登录成功后允许一段时间内免输验证码
## 环境变量和脚本
在 init/env 中有定义和默认值
开发环境数据库迁移:
```powershell
pg-schema-diff apply --schema-dir .\scripts\sql --dsn "host=localhost user=test password=test dbname=app port=5432 sslmode=disable TimeZone=Asia/Shanghai"
```
## 枚举字典
### 产品
@@ -45,12 +7,3 @@ pg-schema-diff apply --schema-dir .\scripts\sql --dsn "host=localhost user=test
| proxy/shared-static | pss | 动态代理 |
| proxy/shared-rotate | psr | 隧道代理 |
| proxy/private-static | pps | 独享代理 |
### 订单类型
| 枚举 | 说明 |
|----|------|
| 1 | 充值余额 |
| 2 | 直接购买 |
## 业务逻辑

View File

@@ -1,17 +0,0 @@
package core
import "github.com/gofiber/fiber/v2"
// ErrInvalid 返回 400 状态码的错误
func ErrInvalid(message ...string) error {
return fiber.NewError(fiber.StatusBadRequest, message...)
}
func ErrUnauthorized(message ...string) error {
return fiber.NewError(fiber.StatusUnauthorized, message...)
}
// ErrForbidden 返回 403 状态码的错误
func ErrForbidden(message ...string) error {
return fiber.NewError(fiber.StatusForbidden, message...)
}

View File

@@ -1,6 +1,7 @@
package handlers
import (
"github.com/gofiber/fiber/v2"
"log/slog"
auth2 "platform/web/auth"
proxy2 "platform/web/domains/proxy"
@@ -8,7 +9,6 @@ import (
m "platform/web/models"
q "platform/web/queries"
"github.com/gofiber/fiber/v2"
"gorm.io/gorm/clause"
)

View File

@@ -2,7 +2,6 @@ package handlers
import (
"platform/web/auth"
"platform/web/core"
trade2 "platform/web/domains/trade"
m "platform/web/models"
q "platform/web/queries"
@@ -115,7 +114,7 @@ func UpdatePassword(c *fiber.Ctx) error {
// 验证手机令牌
if req.Phone == "" || req.Code == "" {
return core.ErrInvalid("手机号码和验证码不能为空")
return fiber.NewError(fiber.StatusBadRequest, "手机号码和验证码不能为空")
}
err = s.Verifier.VerifySms(c.Context(), req.Phone, req.Code)
if err != nil {

View File

@@ -5,13 +5,13 @@ import (
"database/sql"
"errors"
"fmt"
"github.com/gofiber/fiber/v2"
"log/slog"
"math"
"math/rand/v2"
"platform/pkg/env"
"platform/pkg/u"
"platform/web/auth"
"platform/web/core"
channel2 "platform/web/domains/channel"
proxy2 "platform/web/domains/proxy"
g "platform/web/globals"
@@ -65,7 +65,7 @@ func (s *channelService) RemoveChannels(ctx context.Context, authCtx *auth.Conte
// 检查权限,如果为用户操作的话,则只能删除自己的通道
for _, channel := range channels {
if authCtx.Payload.Type == auth.PayloadUser && authCtx.Payload.Id != channel.UserID {
return core.ErrForbidden()
return fiber.NewError(fiber.StatusForbidden)
}
}