将 bookmark.go 重命名为 main.go,并调整包引用路径。将 bookmarks 和 user_np 两个模块的处理逻辑合并到同一个服务中,统一注册路由。同时更新了相关 API 的引用路径,确保生成代码与内部实现正确绑定。 此外,移除了独立的 user_np 服务入口文件,其功能已整合至 bookmark 服务中。 配置文件中调整了 user_np 和 vfs 服务的端口及部分接口定义,完善了用户 相关操作的路径参数和请求体结构。
74 lines
1.9 KiB
Go
74 lines
1.9 KiB
Go
//go:build mage
|
|
// +build mage
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
// mg contains helpful utility functions, like Deps
|
|
)
|
|
|
|
//go:generate go tool oapi-codegen -config config/bookmark/client.yaml config/bookmark/bookmark.yaml
|
|
//go:generate go tool oapi-codegen -config config/bookmark/server.yaml config/bookmark/bookmark.yaml
|
|
//go:generate go tool oapi-codegen -config config/vfs/server.yaml config/vfs/vfs.yaml
|
|
//go:generate go tool oapi-codegen -config config/vfs/client.yaml config/vfs/vfs.yaml
|
|
//go:generate go tool oapi-codegen -config config/user_np/server.yaml config/user_np/user_np.yaml
|
|
|
|
// Default target to run when none is specified
|
|
// If not set, running mage will list available targets
|
|
// var Default = Build
|
|
|
|
func Build_All() error {
|
|
services := []struct {
|
|
Name string
|
|
Path string
|
|
}{
|
|
{"vfs_api", "."},
|
|
{"bookmark", "./cmd/bookmark"},
|
|
}
|
|
|
|
platforms := []struct {
|
|
OS string
|
|
Arch string
|
|
}{
|
|
{"linux", "amd64"},
|
|
{"windows", "amd64"},
|
|
}
|
|
|
|
for _, service := range services {
|
|
for _, p := range platforms {
|
|
fmt.Printf("Building service %s for %s/%s...\n", service.Name, p.OS, p.Arch)
|
|
|
|
// 设置环境变量
|
|
env := append(os.Environ(),
|
|
fmt.Sprintf("GOOS=%s", p.OS),
|
|
fmt.Sprintf("GOARCH=%s", p.Arch))
|
|
|
|
// 确定输出名称
|
|
outputName := fmt.Sprintf("./bin/%s/%s-%s-%s", p.OS, service.Name, p.OS, p.Arch)
|
|
if p.OS == "windows" {
|
|
outputName += ".exe"
|
|
}
|
|
|
|
// // 执行构建命令
|
|
// cmd := exec.Command("go", "build", "-o", outputName, service.Path)
|
|
// cmd.Env = env
|
|
|
|
// 使用 release 模式构建并显示链接信息
|
|
cmd := exec.Command("go", "build",
|
|
"-ldflags", "-s -w -extldflags -static", // 去除调试信息,减小体积
|
|
"-o", outputName,
|
|
service.Path)
|
|
cmd.Env = env
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
return fmt.Errorf("failed to build %s: %w", service.Name, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|