fix: api descript

This commit is contained in:
wwweww
2026-02-28 05:33:16 +08:00
parent 5930fb0dde
commit d2f33b4b96
243 changed files with 37065 additions and 780 deletions
+11
View File
@@ -0,0 +1,11 @@
Name: game-api
Host: 0.0.0.0
Port: 8888
Prometheus:
Host: 0.0.0.0
Port: 4001
Path: /metrics
GameRpcConf:
Target: k8s://juwan/game-rpc-svc:8080
+34
View File
@@ -0,0 +1,34 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package main
import (
"flag"
"fmt"
"juwan-backend/app/game/api/internal/config"
"juwan-backend/app/game/api/internal/handler"
"juwan-backend/app/game/api/internal/svc"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
)
var configFile = flag.String("f", "etc/game-api.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
server := rest.MustNewServer(c.RestConf)
defer server.Stop()
ctx := svc.NewServiceContext(c)
handler.RegisterHandlers(server, ctx)
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
server.Start()
}
+14
View File
@@ -0,0 +1,14 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package config
import (
"github.com/zeromicro/go-zero/rest"
"github.com/zeromicro/go-zero/zrpc"
)
type Config struct {
rest.RestConf
GameRpcConf zrpc.RpcClientConf
}
@@ -0,0 +1,32 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package game
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"juwan-backend/app/game/api/internal/logic/game"
"juwan-backend/app/game/api/internal/svc"
"juwan-backend/app/game/api/internal/types"
)
// 获取游戏详情
func GetGameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.EmptyResp
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := game.NewGetGameLogic(r.Context(), svcCtx)
resp := l.GetGame(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
@@ -0,0 +1,32 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package game
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"juwan-backend/app/game/api/internal/logic/game"
"juwan-backend/app/game/api/internal/svc"
"juwan-backend/app/game/api/internal/types"
)
// 获取游戏列表
func ListGamesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PageReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := game.NewListGamesLogic(r.Context(), svcCtx)
resp, err := l.ListGames(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
+33
View File
@@ -0,0 +1,33 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.9.2
package handler
import (
"net/http"
game "juwan-backend/app/game/api/internal/handler/game"
"juwan-backend/app/game/api/internal/svc"
"github.com/zeromicro/go-zero/rest"
)
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
// 获取游戏列表
Method: http.MethodGet,
Path: "/",
Handler: game.ListGamesHandler(serverCtx),
},
{
// 获取游戏详情
Method: http.MethodGet,
Path: "/:id",
Handler: game.GetGameHandler(serverCtx),
},
},
rest.WithPrefix("/api/v1/games"),
)
}
@@ -0,0 +1,42 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package game
import (
"context"
"juwan-backend/app/game/api/internal/svc"
"juwan-backend/app/game/api/internal/types"
"juwan-backend/app/game/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type GetGameLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 获取游戏详情
func NewGetGameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGameLogic {
return &GetGameLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetGameLogic) GetGame(req *types.GetGameReq) (resp *types.Game) {
// todo: add your logic here and delete this line
game, err := l.svcCtx.GameRpc.GetGamesById(l.ctx, &pb.GetGamesByIdReq{Id: req.Id})
if err != nil {
return nil
}
return &types.Game{
Id: game.Games.Id,
Name: game.Games.Name,
Icon: game.Games.Icon,
Category: game.Games.Category,
}
}
@@ -0,0 +1,34 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package game
import (
"context"
"juwan-backend/app/game/api/internal/svc"
"juwan-backend/app/game/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ListGamesLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 获取游戏列表
func NewListGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListGamesLogic {
return &ListGamesLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListGamesLogic) ListGames(req *types.PageReq) (resp *types.GameListResp, err error) {
// todo: add your logic here and delete this line
return
}
@@ -0,0 +1,23 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package svc
import (
"juwan-backend/app/game/api/internal/config"
"juwan-backend/app/game/rpc/gamepublic"
"github.com/zeromicro/go-zero/zrpc"
)
type ServiceContext struct {
Config config.Config
GameRpc gamepublic.GamePublic
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
GameRpc: gamepublic.NewGamePublic(zrpc.MustNewClient(c.GameRpcConf)),
}
}
+53
View File
@@ -0,0 +1,53 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.9.2
package types
type EmptyResp struct {
}
type Game struct {
Id int64 `json:"id"`
Name string `json:"name"`
Icon string `json:"icon"`
Category string `json:"category"`
}
type GameListResp struct {
Items []Game `json:"items"`
Meta PageMeta `json:"meta"`
}
type GetGameReq struct {
Id int64 `path:"id"`
}
type PageMeta struct {
Total int64 `json:"total"`
Offset int64 `json:"offset"`
Limit int64 `json:"limit"`
}
type PageReq struct {
Offset int64 `form:"offset,default=0"`
Limit int64 `form:"limit,default=20"`
}
type SimpleUser struct {
Id string `json:"id"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar"`
}
type UserProfile struct {
Id string `json:"id"`
Username string `json:"username"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar"`
Role string `json:"role"` // consumer, player, owner, admin
VerifiedRoles []string `json:"verifiedRoles"`
VerificationStatus map[string]string `json:"verificationStatus"`
Phone string `json:"phone,optional"`
Bio string `json:"bio,optional"`
CreatedAt string `json:"createdAt"`
}