Refactor: Remove deprecated gRPC service files and implement new API structure

- Deleted old gRPC service definitions in `game_grpc.pb.go` and `public.go`.
- Added new API server implementations for objectstory, player, and shop services.
- Introduced configuration files for new APIs in `etc/*.yaml`.
- Created main entry points for each service in `objectstory.go`, `player.go`, and `shop.go`.
- Removed unused user update handler and user API files.
- Added utility functions for context management and HTTP header parsing.
- Introduced PostgreSQL backup configuration in `backup/postgreSql.yaml`.
This commit is contained in:
wwweww
2026-02-28 18:35:56 +08:00
parent d2f33b4b96
commit 19cc7a778c
349 changed files with 42548 additions and 1453 deletions
+96
View File
@@ -0,0 +1,96 @@
package contextj
import (
"context"
"errors"
"github.com/zeromicro/go-zero/core/logx"
)
var (
ERRILLEGALUSER = errors.New("illegal user")
ERRILLEGALTOKEN = errors.New("illegal token")
ERRILLEGALREQUESTID = errors.New("illegal request id")
ERRILLEGALISADMIN = errors.New("illegal is_admin")
)
func WithRequestId(c context.Context, requestId string) context.Context {
return context.WithValue(c, "request_id", requestId)
}
func RequestIdFrom(c context.Context) (string, error) {
requestID, ok := c.Value("request_id").(string)
if !ok {
return "", errors.New("request_id not found in context")
}
return requestID, nil
}
func WithToken(c context.Context, token string) context.Context {
return context.WithValue(c, "token", token)
}
func TokenFrom(c context.Context) (string, error) {
token, ok := c.Value("token").(string)
if !ok {
return "", errors.New("token not found in context")
}
return token, nil
}
func WithUserID(c context.Context, id int64) context.Context {
return context.WithValue(c, "user_id", id)
}
func UserIDFrom(c context.Context) (int64, error) {
if userID, ok := c.Value("user_id").(int64); !ok {
return 0, errors.New("user_id not found in context")
} else {
return userID, nil
}
}
// request_id is used for tracing and logging, not for authentication or authorization,
// so it can be set by clients or generated by the server.
func WithRequestID(c context.Context, requestID string) context.Context {
return context.WithValue(c, "request_id", requestID)
}
func RequestIDFrom(c context.Context) (string, error) {
if requestID, ok := c.Value("request_id").(string); !ok {
return "", errors.New("request_id not found in context")
} else {
return requestID, nil
}
}
func WithIsAdmin(c context.Context, isAdmin bool) context.Context {
return context.WithValue(c, "is_admin", isAdmin)
}
func IsAdminFrom(c context.Context) (bool, error) {
if isAdmin, ok := c.Value("is_admin").(bool); !ok {
return false, errors.New("is_admin not found in context")
} else {
return isAdmin, nil
}
}
func AdminIdFrom(c context.Context) (adminId int64, err error) {
adminId, err = UserIDFrom(c)
if err != nil {
logx.Errorf("get user id from context: %v", err)
return 0, ERRILLEGALUSER
}
isAdmin, err := IsAdminFrom(c)
if err != nil {
logx.Errorf("get isAdmin from context: %v", err)
return 0, ERRILLEGALUSER
}
if !isAdmin {
logx.Errorf("user %d is not admin", adminId)
return 0, ERRILLEGALUSER
}
return
}