- api/common/v1 → api/open/v1,路由前缀 /api/common/v1 → /api/open/v1
- 契约层按子功能拆目录:api/open/v1/tools/{uuid,md5,random,time,ip}/index.go
- 控制器同步拆文件:internal/controller/open/{uuid,md5,random,time,ip}.go
- 命名规则(open 优于 common)与 tools 目录规则记入 AGENTS.md
- 冒烟测试:旧路由 404,新路由 5 端点全部通过
23 lines
564 B
Go
23 lines
564 B
Go
package open
|
|
|
|
import (
|
|
"context"
|
|
|
|
randomapi "service.xpcool.com/api/open/v1/tools/random"
|
|
"service.xpcool.com/common/tools/random"
|
|
)
|
|
|
|
// Random generates a random string of the requested type and length.
|
|
func (c *Controller) Random(ctx context.Context, req *randomapi.RandomReq) (res *randomapi.RandomRes, err error) {
|
|
var value string
|
|
switch req.Type {
|
|
case "digits":
|
|
value = random.Digits(req.Length)
|
|
case "letters":
|
|
value = random.Letters(req.Length)
|
|
default:
|
|
value = random.String(req.Length)
|
|
}
|
|
return &randomapi.RandomRes{Value: value}, nil
|
|
}
|