refactor(bookmark): 重构书签服务入口文件并整合用户权限功能
将 bookmark.go 重命名为 main.go,并调整包引用路径。将 bookmarks 和 user_np 两个模块的处理逻辑合并到同一个服务中,统一注册路由。同时更新了相关 API 的引用路径,确保生成代码与内部实现正确绑定。 此外,移除了独立的 user_np 服务入口文件,其功能已整合至 bookmark 服务中。 配置文件中调整了 user_np 和 vfs 服务的端口及部分接口定义,完善了用户 相关操作的路径参数和请求体结构。
This commit is contained in:
49
cmd/bookmark/main.go
Normal file
49
cmd/bookmark/main.go
Normal file
@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
bookmarks_api "git.zzyxyz.com/zzy/zzyxyz_go_api/gen/bookmarks"
|
||||
user_np_api "git.zzyxyz.com/zzy/zzyxyz_go_api/gen/user_np"
|
||||
"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))
|
||||
}
|
Reference in New Issue
Block a user