Files
zzyxyz_go_api/cmd/bookmark/main.go
zzy b2cc27b8f5 refactor(bookmark): 重构 bookmark 服务生成配置和内部引用
将 bookmark 和 user_np 服务的生成配置分离为 server 和 client 包,
并更新了相应的导入路径。同时更新了 OpenAPI 配置文件中的包名、输出路径及
启用 strict-server 模式以增强类型安全。

此外,同步更新了 VFS 服务的客户端和服务端生成配置,并完善了其 OpenAPI
错误响应定义与二进制内容支持,增强了 API 的规范性和健壮性。

修复了部分权限校验逻辑,并调整了中间件注册方式以适配新的严格模式接口。
2025-09-25 16:15:34 +08:00

50 lines
1.6 KiB
Go

package main
import (
"log"
bookmarks_api "git.zzyxyz.com/zzy/zzyxyz_go_api/gen/bookmarks_server"
user_np_api "git.zzyxyz.com/zzy/zzyxyz_go_api/gen/user_np_server"
"git.zzyxyz.com/zzy/zzyxyz_go_api/internal/bookmarks"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func main() {
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
// 允许所有源的示例配置
config := cors.Config{
AllowAllOrigins: true,
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"},
AllowHeaders: []string{"Origin", "Content-Length", "Content-Type"},
}
router.Use(cors.New(config))
api_router := router.Group("/api")
{
// create a type that satisfies the `api.ServerInterface`,
// which contains an implementation of every operation from the generated code
if server, err := bookmarks.NewBookMarks("./data/bookmark.sqlite3"); err != nil {
log.Fatal("Failed to create bookmarks server:", err)
} else if permission, err := bookmarks.NewBookMarkPermission(); err != nil || permission == nil {
log.Fatal("Failed to create bookmarks permission:", err)
} else {
bookmarks_api.RegisterHandlersWithOptions(api_router, server, *permission)
}
// create a type that satisfies the `api.ServerInterface`,
// which contains an implementation of every operation from the generated code
if server, err := bookmarks.NewUserNP("./data/user_np.sqlite3"); err != nil {
log.Fatal("Failed to create user_np server:", err)
} else {
user_np_api.RegisterHandlers(api_router, server)
}
}
var listener = "localhost:8081"
log.Printf("Starting server at http://%s", listener)
log.Fatal(router.Run(listener))
}