Merge pull request 'dev' (#1) from dev into main
All checks were successful
/ build-services (app/auth_service/Dockerfile, auth, auth) (push) Successful in 38s
/ build-services (app/ecpm_service/Dockerfile, ecpm, ecpm) (push) Successful in 36s
/ build-services (app/user_service/Dockerfile, user, user) (push) Successful in 39s
/ start-services (push) Successful in 5s
/ build-services (app/ranking_service/Dockerfile, ranking, ranking) (push) Successful in 41s

Reviewed-on: #1
This commit is contained in:
xiabin 2025-02-18 16:24:11 +08:00
commit 03d9f121ed
129 changed files with 6250 additions and 3475 deletions

5
.env Normal file
View File

@ -0,0 +1,5 @@
CONFIG_TYPE=env
LISTEN_ON=0.0.0.0:8080
MODE=dev
MYSQL=user:password@tcp(127.0.0.1:3306)/database
REDIS_HOST=127.0.0.2

47
.gitea/workflows/dev.yaml Normal file
View File

@ -0,0 +1,47 @@
dev: 打包镜像 & 在开发环境启动服务
on: [push]
jobs:
build-services:
runs-on: runner
strategy:
matrix:
include:
- service: user
dockerfile: app/user_service/Dockerfile
image: user
- service: ranking
dockerfile: app/ranking_service/Dockerfile
image: ranking
- service: ecpm
dockerfile: app/ecpm_service/Dockerfile
image: ecpm
- service: auth
dockerfile: app/auth_service/Dockerfile
image: auth
steps:
- uses: https://gitea.youtukeji.com.cn/actions/checkout@v4
- uses: https://gitea.youtukeji.com.cn/actions/setup-go@v5
with:
go-version: '1.24.0'
- name: Verify Go version
run: go version
- name: Build Docker Image
run: docker build -t ${{ matrix.image }} -f ${{ matrix.dockerfile }} .
start-services:
runs-on: runner
needs: build-services # 依赖构建阶段
steps:
- uses: https://gitea.youtukeji.com.cn/actions/checkout@v4
- name: Start Docker Compose
run: |
docker-compose down --remove-orphans
docker-compose up -d --build
env:
COMPOSE_PROJECT_NAME: youtu_grpc

View File

@ -0,0 +1,32 @@
FROM golang:alpine AS builder
LABEL stage=gobuilder
ENV CGO_ENABLED=0
ENV GOPROXY=https://goproxy.cn,direct
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk update --no-cache && apk add --no-cache tzdata
RUN apk add --no-cache git
WORKDIR /build
ADD go.mod .
ADD go.sum .
RUN go env -w GOPRIVATE=gitea.youtukeji.com.cn
RUN go mod download
COPY . .
RUN go build -ldflags="-s -w" -o /app/auth ./app/auth_service/auth_service.go
FROM alpine
COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai
ENV TZ=Asia/Shanghai
WORKDIR /app
COPY --from=builder /app/auth /app/auth
EXPOSE 8888
CMD ["/app/auth"]

View File

@ -4,7 +4,7 @@
// protoc v3.19.4
// source: auth_service.proto
package auth_service
package auth
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
@ -173,6 +173,9 @@ type Code2SessionResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
OpenId string `protobuf:"bytes,1,opt,name=OpenId,proto3" json:"OpenId,omitempty"`
UnionId string `protobuf:"bytes,2,opt,name=UnionId,proto3" json:"UnionId,omitempty"`
UserId uint64 `protobuf:"varint,3,opt,name=UserId,proto3" json:"UserId,omitempty"`
AppId uint32 `protobuf:"varint,4,opt,name=AppId,proto3" json:"AppId,omitempty"`
IsNew bool `protobuf:"varint,5,opt,name=IsNew,proto3" json:"IsNew,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@ -221,6 +224,27 @@ func (x *Code2SessionResponse) GetUnionId() string {
return ""
}
func (x *Code2SessionResponse) GetUserId() uint64 {
if x != nil {
return x.UserId
}
return 0
}
func (x *Code2SessionResponse) GetAppId() uint32 {
if x != nil {
return x.AppId
}
return 0
}
func (x *Code2SessionResponse) GetIsNew() bool {
if x != nil {
return x.IsNew
}
return false
}
type GetAccessTokenRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
AppId string `protobuf:"bytes,1,opt,name=AppId,proto3" json:"AppId,omitempty"`
@ -324,36 +348,39 @@ var file_auth_service_proto_rawDesc = string([]byte{
0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x43, 0x6f,
0x64, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x41, 0x6e, 0x6f, 0x6e, 0x79, 0x6d, 0x6f, 0x75, 0x73, 0x43,
0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x41, 0x6e, 0x6f, 0x6e, 0x79,
0x6d, 0x6f, 0x75, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x22, 0x48, 0x0a, 0x14, 0x43, 0x6f, 0x64, 0x65,
0x32, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
0x12, 0x16, 0x0a, 0x06, 0x4f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x06, 0x4f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x55, 0x6e, 0x69, 0x6f,
0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x55, 0x6e, 0x69, 0x6f, 0x6e,
0x49, 0x64, 0x22, 0x2d, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54,
0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x41,
0x70, 0x70, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x41, 0x70, 0x70, 0x49,
0x64, 0x22, 0x3a, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f,
0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x41,
0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x0b, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x32, 0xf9, 0x01,
0x0a, 0x0c, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x35,
0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x15, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65,
0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e,
0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x55, 0x0a, 0x0c, 0x43, 0x6f, 0x64, 0x65, 0x32, 0x53, 0x65,
0x73, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x2e, 0x43, 0x6f, 0x64, 0x65, 0x32, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f,
0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x5f,
0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x43, 0x6f, 0x64, 0x65, 0x32, 0x53, 0x65, 0x73,
0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5b, 0x0a, 0x0e,
0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x23,
0x2e, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x47, 0x65,
0x74, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x1a, 0x24, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69,
0x6d, 0x6f, 0x75, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x22, 0x8c, 0x01, 0x0a, 0x14, 0x43, 0x6f, 0x64,
0x65, 0x32, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x12, 0x16, 0x0a, 0x06, 0x4f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x06, 0x4f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x55, 0x6e, 0x69,
0x6f, 0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x55, 0x6e, 0x69, 0x6f,
0x6e, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20,
0x01, 0x28, 0x04, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x41,
0x70, 0x70, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x41, 0x70, 0x70, 0x49,
0x64, 0x12, 0x14, 0x0a, 0x05, 0x49, 0x73, 0x4e, 0x65, 0x77, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08,
0x52, 0x05, 0x49, 0x73, 0x4e, 0x65, 0x77, 0x22, 0x2d, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x41, 0x63,
0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x12, 0x14, 0x0a, 0x05, 0x41, 0x70, 0x70, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x05, 0x41, 0x70, 0x70, 0x49, 0x64, 0x22, 0x3a, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63,
0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
0x12, 0x20, 0x0a, 0x0b, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b,
0x65, 0x6e, 0x32, 0xf9, 0x01, 0x0a, 0x0c, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76,
0x69, 0x63, 0x65, 0x12, 0x35, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x15, 0x2e, 0x61, 0x75,
0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x1a, 0x16, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
0x65, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x55, 0x0a, 0x0c, 0x43, 0x6f,
0x64, 0x65, 0x32, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x2e, 0x61, 0x75, 0x74,
0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x43, 0x6f, 0x64, 0x65, 0x32, 0x53,
0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e,
0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x43, 0x6f, 0x64,
0x65, 0x32, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x12, 0x5b, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f,
0x6b, 0x65, 0x6e, 0x12, 0x23, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69,
0x63, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65,
0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x10, 0x5a, 0x0e, 0x2e, 0x2f, 0x61,
0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x24, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x5f,
0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x73,
0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x08,
0x5a, 0x06, 0x2e, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
})
var (

View File

@ -4,7 +4,7 @@
// - protoc v3.19.4
// source: auth_service.proto
package auth_service
package auth
import (
context "context"

View File

@ -1,31 +1,31 @@
package main
import (
"flag"
"fmt"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/auth_service"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/config"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/server"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/auth"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/internal/server"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/pkg/config"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
var configFile = flag.String("f", "etc/auth_service.yaml", "the config file")
const ServiceName = "auth_service"
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
err := config.GetConfig(&c, ServiceName)
if err != nil {
panic(err)
}
ctx := svc.NewServiceContext(c)
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
auth_service.RegisterAuthServiceServer(grpcServer, server.NewAuthServiceServer(ctx))
auth.RegisterAuthServiceServer(grpcServer, server.NewAuthServiceServer(ctx))
if c.Mode == service.DevMode || c.Mode == service.TestMode {
reflection.Register(grpcServer)
@ -33,6 +33,6 @@ func main() {
})
defer s.Stop()
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
fmt.Printf("Starting rpc server at %s...\n", c.RpcServerConf.ListenOn)
s.Start()
}

View File

@ -1,7 +1,7 @@
syntax = "proto3";
package auth_service;
option go_package = "./auth_service";
option go_package = "./auth";
message Request {
string ping = 1;
@ -20,6 +20,9 @@ message Code2SessionRequest{
message Code2SessionResponse{
string OpenId = 1;
string UnionId = 2;
uint64 UserId = 3;
uint32 AppId = 4;
bool IsNew = 5;
}
message GetAccessTokenRequest{

View File

@ -2,23 +2,24 @@
// goctl 1.7.6
// Source: auth_service.proto
package auth_service_client
package authservice
import (
"context"
auth_service2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/auth_service"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/auth"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
)
type (
Code2SessionRequest = auth_service2.Code2SessionRequest
Code2SessionResponse = auth_service2.Code2SessionResponse
GetAccessTokenRequest = auth_service2.GetAccessTokenRequest
GetAccessTokenResponse = auth_service2.GetAccessTokenResponse
Request = auth_service2.Request
Response = auth_service2.Response
Code2SessionRequest = auth.Code2SessionRequest
Code2SessionResponse = auth.Code2SessionResponse
GetAccessTokenRequest = auth.GetAccessTokenRequest
GetAccessTokenResponse = auth.GetAccessTokenResponse
Request = auth.Request
Response = auth.Response
AuthService interface {
Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
@ -38,16 +39,16 @@ func NewAuthService(cli zrpc.Client) AuthService {
}
func (m *defaultAuthService) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
client := auth_service2.NewAuthServiceClient(m.cli.Conn())
client := auth.NewAuthServiceClient(m.cli.Conn())
return client.Ping(ctx, in, opts...)
}
func (m *defaultAuthService) Code2Session(ctx context.Context, in *Code2SessionRequest, opts ...grpc.CallOption) (*Code2SessionResponse, error) {
client := auth_service2.NewAuthServiceClient(m.cli.Conn())
client := auth.NewAuthServiceClient(m.cli.Conn())
return client.Code2Session(ctx, in, opts...)
}
func (m *defaultAuthService) GetAccessToken(ctx context.Context, in *GetAccessTokenRequest, opts ...grpc.CallOption) (*GetAccessTokenResponse, error) {
client := auth_service2.NewAuthServiceClient(m.cli.Conn())
client := auth.NewAuthServiceClient(m.cli.Conn())
return client.GetAccessToken(ctx, in, opts...)
}

View File

@ -1,13 +1,13 @@
Name: auth_service.rpc
Name: auth.rpc
ListenOn: 0.0.0.0:8080
Auth: true
Redis:
Key: auth_service.rpc.key
Key: auth.rpc.key
Host: 127.0.0.1:6379
Etcd:
Hosts:
- 127.0.0.1:2379
Key: auth_service.rpc
Key: auth.rpc
Mode: test
AppData:

View File

@ -0,0 +1,27 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
import (
"time"
)
const TableNameAppUser = "app_user"
// AppUser mapped from table <app_user>
type AppUser struct {
ID uint64 `gorm:"column:id;type:bigint unsigned;primaryKey;autoIncrement:true;index:idx_app_user_id,priority:1" json:"id"`
AppAccountID uint32 `gorm:"column:app_account_id;type:int unsigned;not null;uniqueIndex:app_account_id_open_id,priority:1;comment:app_account表外键" json:"app_account_id"` // app_account表外键
UserID *uint64 `gorm:"column:user_id;type:bigint unsigned" json:"user_id"`
Openid string `gorm:"column:openid;type:varchar(255);not null;uniqueIndex:app_account_id_open_id,priority:2" json:"openid"`
Unionid string `gorm:"column:unionid;type:varchar(255);not null" json:"unionid"`
AnonymousOpenid string `gorm:"column:anonymous_openid;type:varchar(255);not null;comment:匿名openid" json:"anonymous_openid"` // 匿名openid
CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间
}
// TableName AppUser's table name
func (*AppUser) TableName() string {
return TableNameAppUser
}

View File

@ -6,7 +6,6 @@ package query
import (
"context"
"strings"
"gorm.io/gorm"
"gorm.io/gorm/clause"
@ -17,7 +16,7 @@ import (
"gorm.io/plugin/dbresolver"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm/gen/dao/model"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/internal/gen/dao/model"
)
func newAppAccount(db *gorm.DB, opts ...gen.DOOption) appAccount {
@ -41,14 +40,14 @@ func newAppAccount(db *gorm.DB, opts ...gen.DOOption) appAccount {
}
type appAccount struct {
appAccountDo
appAccountDo appAccountDo
ALL field.Asterisk
ID field.Uint32
Type field.Uint32
Type field.Uint32 // 类型(0:抖音,1:微信)
AppID field.String
Secret field.String
Remark field.String
Remark field.String // 备注
DeletedAt field.Field
fieldMap map[string]field.Expr
@ -78,6 +77,16 @@ func (a *appAccount) updateTableName(table string) *appAccount {
return a
}
func (a *appAccount) WithContext(ctx context.Context) *appAccountDo {
return a.appAccountDo.WithContext(ctx)
}
func (a appAccount) TableName() string { return a.appAccountDo.TableName() }
func (a appAccount) Alias() string { return a.appAccountDo.Alias() }
func (a appAccount) Columns(cols ...field.Expr) gen.Columns { return a.appAccountDo.Columns(cols...) }
func (a *appAccount) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := a.fieldMap[fieldName]
if !ok || _f == nil {
@ -109,172 +118,95 @@ func (a appAccount) replaceDB(db *gorm.DB) appAccount {
type appAccountDo struct{ gen.DO }
type IAppAccountDo interface {
gen.SubQuery
Debug() IAppAccountDo
WithContext(ctx context.Context) IAppAccountDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IAppAccountDo
WriteDB() IAppAccountDo
As(alias string) gen.Dao
Session(config *gorm.Session) IAppAccountDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IAppAccountDo
Not(conds ...gen.Condition) IAppAccountDo
Or(conds ...gen.Condition) IAppAccountDo
Select(conds ...field.Expr) IAppAccountDo
Where(conds ...gen.Condition) IAppAccountDo
Order(conds ...field.Expr) IAppAccountDo
Distinct(cols ...field.Expr) IAppAccountDo
Omit(cols ...field.Expr) IAppAccountDo
Join(table schema.Tabler, on ...field.Expr) IAppAccountDo
LeftJoin(table schema.Tabler, on ...field.Expr) IAppAccountDo
RightJoin(table schema.Tabler, on ...field.Expr) IAppAccountDo
Group(cols ...field.Expr) IAppAccountDo
Having(conds ...gen.Condition) IAppAccountDo
Limit(limit int) IAppAccountDo
Offset(offset int) IAppAccountDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IAppAccountDo
Unscoped() IAppAccountDo
Create(values ...*model.AppAccount) error
CreateInBatches(values []*model.AppAccount, batchSize int) error
Save(values ...*model.AppAccount) error
First() (*model.AppAccount, error)
Take() (*model.AppAccount, error)
Last() (*model.AppAccount, error)
Find() ([]*model.AppAccount, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppAccount, err error)
FindInBatches(result *[]*model.AppAccount, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*model.AppAccount) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) IAppAccountDo
Assign(attrs ...field.AssignExpr) IAppAccountDo
Joins(fields ...field.RelationField) IAppAccountDo
Preload(fields ...field.RelationField) IAppAccountDo
FirstOrInit() (*model.AppAccount, error)
FirstOrCreate() (*model.AppAccount, error)
FindByPage(offset int, limit int) (result []*model.AppAccount, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) IAppAccountDo
UnderlyingDB() *gorm.DB
schema.Tabler
GetAppConfig() (result []*model.AppAccount, err error)
}
// GetAppConfig 获取所有小游戏配置
//
// select `app_id`,`secret`,`ecpm_value`,`ecpm_view`,`type` from `app_account` left join douyin_ecpm_config on app_account.id = douyin_ecpm_config.app_account_id
func (a appAccountDo) GetAppConfig() (result []*model.AppAccount, err error) {
var generateSQL strings.Builder
generateSQL.WriteString("select `app_id`,`secret`,`ecpm_value`,`ecpm_view`,`type` from `app_account` left join douyin_ecpm_config on app_account.id = douyin_ecpm_config.app_account_id ")
var executeSQL *gorm.DB
executeSQL = a.UnderlyingDB().Raw(generateSQL.String()).Find(&result) // ignore_security_alert
err = executeSQL.Error
return
}
func (a appAccountDo) Debug() IAppAccountDo {
func (a appAccountDo) Debug() *appAccountDo {
return a.withDO(a.DO.Debug())
}
func (a appAccountDo) WithContext(ctx context.Context) IAppAccountDo {
func (a appAccountDo) WithContext(ctx context.Context) *appAccountDo {
return a.withDO(a.DO.WithContext(ctx))
}
func (a appAccountDo) ReadDB() IAppAccountDo {
func (a appAccountDo) ReadDB() *appAccountDo {
return a.Clauses(dbresolver.Read)
}
func (a appAccountDo) WriteDB() IAppAccountDo {
func (a appAccountDo) WriteDB() *appAccountDo {
return a.Clauses(dbresolver.Write)
}
func (a appAccountDo) Session(config *gorm.Session) IAppAccountDo {
func (a appAccountDo) Session(config *gorm.Session) *appAccountDo {
return a.withDO(a.DO.Session(config))
}
func (a appAccountDo) Clauses(conds ...clause.Expression) IAppAccountDo {
func (a appAccountDo) Clauses(conds ...clause.Expression) *appAccountDo {
return a.withDO(a.DO.Clauses(conds...))
}
func (a appAccountDo) Returning(value interface{}, columns ...string) IAppAccountDo {
func (a appAccountDo) Returning(value interface{}, columns ...string) *appAccountDo {
return a.withDO(a.DO.Returning(value, columns...))
}
func (a appAccountDo) Not(conds ...gen.Condition) IAppAccountDo {
func (a appAccountDo) Not(conds ...gen.Condition) *appAccountDo {
return a.withDO(a.DO.Not(conds...))
}
func (a appAccountDo) Or(conds ...gen.Condition) IAppAccountDo {
func (a appAccountDo) Or(conds ...gen.Condition) *appAccountDo {
return a.withDO(a.DO.Or(conds...))
}
func (a appAccountDo) Select(conds ...field.Expr) IAppAccountDo {
func (a appAccountDo) Select(conds ...field.Expr) *appAccountDo {
return a.withDO(a.DO.Select(conds...))
}
func (a appAccountDo) Where(conds ...gen.Condition) IAppAccountDo {
func (a appAccountDo) Where(conds ...gen.Condition) *appAccountDo {
return a.withDO(a.DO.Where(conds...))
}
func (a appAccountDo) Order(conds ...field.Expr) IAppAccountDo {
func (a appAccountDo) Order(conds ...field.Expr) *appAccountDo {
return a.withDO(a.DO.Order(conds...))
}
func (a appAccountDo) Distinct(cols ...field.Expr) IAppAccountDo {
func (a appAccountDo) Distinct(cols ...field.Expr) *appAccountDo {
return a.withDO(a.DO.Distinct(cols...))
}
func (a appAccountDo) Omit(cols ...field.Expr) IAppAccountDo {
func (a appAccountDo) Omit(cols ...field.Expr) *appAccountDo {
return a.withDO(a.DO.Omit(cols...))
}
func (a appAccountDo) Join(table schema.Tabler, on ...field.Expr) IAppAccountDo {
func (a appAccountDo) Join(table schema.Tabler, on ...field.Expr) *appAccountDo {
return a.withDO(a.DO.Join(table, on...))
}
func (a appAccountDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAppAccountDo {
func (a appAccountDo) LeftJoin(table schema.Tabler, on ...field.Expr) *appAccountDo {
return a.withDO(a.DO.LeftJoin(table, on...))
}
func (a appAccountDo) RightJoin(table schema.Tabler, on ...field.Expr) IAppAccountDo {
func (a appAccountDo) RightJoin(table schema.Tabler, on ...field.Expr) *appAccountDo {
return a.withDO(a.DO.RightJoin(table, on...))
}
func (a appAccountDo) Group(cols ...field.Expr) IAppAccountDo {
func (a appAccountDo) Group(cols ...field.Expr) *appAccountDo {
return a.withDO(a.DO.Group(cols...))
}
func (a appAccountDo) Having(conds ...gen.Condition) IAppAccountDo {
func (a appAccountDo) Having(conds ...gen.Condition) *appAccountDo {
return a.withDO(a.DO.Having(conds...))
}
func (a appAccountDo) Limit(limit int) IAppAccountDo {
func (a appAccountDo) Limit(limit int) *appAccountDo {
return a.withDO(a.DO.Limit(limit))
}
func (a appAccountDo) Offset(offset int) IAppAccountDo {
func (a appAccountDo) Offset(offset int) *appAccountDo {
return a.withDO(a.DO.Offset(offset))
}
func (a appAccountDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAppAccountDo {
func (a appAccountDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *appAccountDo {
return a.withDO(a.DO.Scopes(funcs...))
}
func (a appAccountDo) Unscoped() IAppAccountDo {
func (a appAccountDo) Unscoped() *appAccountDo {
return a.withDO(a.DO.Unscoped())
}
@ -340,22 +272,22 @@ func (a appAccountDo) FindInBatches(result *[]*model.AppAccount, batchSize int,
return a.DO.FindInBatches(result, batchSize, fc)
}
func (a appAccountDo) Attrs(attrs ...field.AssignExpr) IAppAccountDo {
func (a appAccountDo) Attrs(attrs ...field.AssignExpr) *appAccountDo {
return a.withDO(a.DO.Attrs(attrs...))
}
func (a appAccountDo) Assign(attrs ...field.AssignExpr) IAppAccountDo {
func (a appAccountDo) Assign(attrs ...field.AssignExpr) *appAccountDo {
return a.withDO(a.DO.Assign(attrs...))
}
func (a appAccountDo) Joins(fields ...field.RelationField) IAppAccountDo {
func (a appAccountDo) Joins(fields ...field.RelationField) *appAccountDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Joins(_f))
}
return &a
}
func (a appAccountDo) Preload(fields ...field.RelationField) IAppAccountDo {
func (a appAccountDo) Preload(fields ...field.RelationField) *appAccountDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Preload(_f))
}

View File

@ -9,7 +9,7 @@ import (
"fmt"
"testing"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm/gen/dao/model"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/internal/gen/dao/model"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm/clause"

View File

@ -16,7 +16,7 @@ import (
"gorm.io/plugin/dbresolver"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm/gen/dao/model"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/internal/gen/dao/model"
)
func newAppUser(db *gorm.DB, opts ...gen.DOOption) appUser {
@ -29,13 +29,11 @@ func newAppUser(db *gorm.DB, opts ...gen.DOOption) appUser {
_appUser.ALL = field.NewAsterisk(tableName)
_appUser.ID = field.NewUint64(tableName, "id")
_appUser.AppAccountID = field.NewUint32(tableName, "app_account_id")
_appUser.UserID = field.NewUint64(tableName, "user_id")
_appUser.Openid = field.NewString(tableName, "openid")
_appUser.Unionid = field.NewString(tableName, "unionid")
_appUser.Nickname = field.NewString(tableName, "nickname")
_appUser.Avatar = field.NewString(tableName, "avatar")
_appUser.AnonymousOpenid = field.NewString(tableName, "anonymous_openid")
_appUser.CreatedAt = field.NewTime(tableName, "created_at")
_appUser.UpdatedAt = field.NewTime(tableName, "updated_at")
_appUser.fillFieldMap()
@ -43,18 +41,16 @@ func newAppUser(db *gorm.DB, opts ...gen.DOOption) appUser {
}
type appUser struct {
appUserDo
appUserDo appUserDo
ALL field.Asterisk
ID field.Uint64
AppAccountID field.Uint32
AppAccountID field.Uint32 // app_account表外键
UserID field.Uint64
Openid field.String
Unionid field.String
Nickname field.String
Avatar field.String
AnonymousOpenid field.String
CreatedAt field.Time
UpdatedAt field.Time
AnonymousOpenid field.String // 匿名openid
CreatedAt field.Time // 创建时间
fieldMap map[string]field.Expr
}
@ -73,19 +69,25 @@ func (a *appUser) updateTableName(table string) *appUser {
a.ALL = field.NewAsterisk(table)
a.ID = field.NewUint64(table, "id")
a.AppAccountID = field.NewUint32(table, "app_account_id")
a.UserID = field.NewUint64(table, "user_id")
a.Openid = field.NewString(table, "openid")
a.Unionid = field.NewString(table, "unionid")
a.Nickname = field.NewString(table, "nickname")
a.Avatar = field.NewString(table, "avatar")
a.AnonymousOpenid = field.NewString(table, "anonymous_openid")
a.CreatedAt = field.NewTime(table, "created_at")
a.UpdatedAt = field.NewTime(table, "updated_at")
a.fillFieldMap()
return a
}
func (a *appUser) WithContext(ctx context.Context) *appUserDo { return a.appUserDo.WithContext(ctx) }
func (a appUser) TableName() string { return a.appUserDo.TableName() }
func (a appUser) Alias() string { return a.appUserDo.Alias() }
func (a appUser) Columns(cols ...field.Expr) gen.Columns { return a.appUserDo.Columns(cols...) }
func (a *appUser) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := a.fieldMap[fieldName]
if !ok || _f == nil {
@ -96,16 +98,14 @@ func (a *appUser) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
}
func (a *appUser) fillFieldMap() {
a.fieldMap = make(map[string]field.Expr, 9)
a.fieldMap = make(map[string]field.Expr, 7)
a.fieldMap["id"] = a.ID
a.fieldMap["app_account_id"] = a.AppAccountID
a.fieldMap["user_id"] = a.UserID
a.fieldMap["openid"] = a.Openid
a.fieldMap["unionid"] = a.Unionid
a.fieldMap["nickname"] = a.Nickname
a.fieldMap["avatar"] = a.Avatar
a.fieldMap["anonymous_openid"] = a.AnonymousOpenid
a.fieldMap["created_at"] = a.CreatedAt
a.fieldMap["updated_at"] = a.UpdatedAt
}
func (a appUser) clone(db *gorm.DB) appUser {
@ -120,156 +120,95 @@ func (a appUser) replaceDB(db *gorm.DB) appUser {
type appUserDo struct{ gen.DO }
type IAppUserDo interface {
gen.SubQuery
Debug() IAppUserDo
WithContext(ctx context.Context) IAppUserDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IAppUserDo
WriteDB() IAppUserDo
As(alias string) gen.Dao
Session(config *gorm.Session) IAppUserDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IAppUserDo
Not(conds ...gen.Condition) IAppUserDo
Or(conds ...gen.Condition) IAppUserDo
Select(conds ...field.Expr) IAppUserDo
Where(conds ...gen.Condition) IAppUserDo
Order(conds ...field.Expr) IAppUserDo
Distinct(cols ...field.Expr) IAppUserDo
Omit(cols ...field.Expr) IAppUserDo
Join(table schema.Tabler, on ...field.Expr) IAppUserDo
LeftJoin(table schema.Tabler, on ...field.Expr) IAppUserDo
RightJoin(table schema.Tabler, on ...field.Expr) IAppUserDo
Group(cols ...field.Expr) IAppUserDo
Having(conds ...gen.Condition) IAppUserDo
Limit(limit int) IAppUserDo
Offset(offset int) IAppUserDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IAppUserDo
Unscoped() IAppUserDo
Create(values ...*model.AppUser) error
CreateInBatches(values []*model.AppUser, batchSize int) error
Save(values ...*model.AppUser) error
First() (*model.AppUser, error)
Take() (*model.AppUser, error)
Last() (*model.AppUser, error)
Find() ([]*model.AppUser, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppUser, err error)
FindInBatches(result *[]*model.AppUser, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*model.AppUser) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) IAppUserDo
Assign(attrs ...field.AssignExpr) IAppUserDo
Joins(fields ...field.RelationField) IAppUserDo
Preload(fields ...field.RelationField) IAppUserDo
FirstOrInit() (*model.AppUser, error)
FirstOrCreate() (*model.AppUser, error)
FindByPage(offset int, limit int) (result []*model.AppUser, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) IAppUserDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (a appUserDo) Debug() IAppUserDo {
func (a appUserDo) Debug() *appUserDo {
return a.withDO(a.DO.Debug())
}
func (a appUserDo) WithContext(ctx context.Context) IAppUserDo {
func (a appUserDo) WithContext(ctx context.Context) *appUserDo {
return a.withDO(a.DO.WithContext(ctx))
}
func (a appUserDo) ReadDB() IAppUserDo {
func (a appUserDo) ReadDB() *appUserDo {
return a.Clauses(dbresolver.Read)
}
func (a appUserDo) WriteDB() IAppUserDo {
func (a appUserDo) WriteDB() *appUserDo {
return a.Clauses(dbresolver.Write)
}
func (a appUserDo) Session(config *gorm.Session) IAppUserDo {
func (a appUserDo) Session(config *gorm.Session) *appUserDo {
return a.withDO(a.DO.Session(config))
}
func (a appUserDo) Clauses(conds ...clause.Expression) IAppUserDo {
func (a appUserDo) Clauses(conds ...clause.Expression) *appUserDo {
return a.withDO(a.DO.Clauses(conds...))
}
func (a appUserDo) Returning(value interface{}, columns ...string) IAppUserDo {
func (a appUserDo) Returning(value interface{}, columns ...string) *appUserDo {
return a.withDO(a.DO.Returning(value, columns...))
}
func (a appUserDo) Not(conds ...gen.Condition) IAppUserDo {
func (a appUserDo) Not(conds ...gen.Condition) *appUserDo {
return a.withDO(a.DO.Not(conds...))
}
func (a appUserDo) Or(conds ...gen.Condition) IAppUserDo {
func (a appUserDo) Or(conds ...gen.Condition) *appUserDo {
return a.withDO(a.DO.Or(conds...))
}
func (a appUserDo) Select(conds ...field.Expr) IAppUserDo {
func (a appUserDo) Select(conds ...field.Expr) *appUserDo {
return a.withDO(a.DO.Select(conds...))
}
func (a appUserDo) Where(conds ...gen.Condition) IAppUserDo {
func (a appUserDo) Where(conds ...gen.Condition) *appUserDo {
return a.withDO(a.DO.Where(conds...))
}
func (a appUserDo) Order(conds ...field.Expr) IAppUserDo {
func (a appUserDo) Order(conds ...field.Expr) *appUserDo {
return a.withDO(a.DO.Order(conds...))
}
func (a appUserDo) Distinct(cols ...field.Expr) IAppUserDo {
func (a appUserDo) Distinct(cols ...field.Expr) *appUserDo {
return a.withDO(a.DO.Distinct(cols...))
}
func (a appUserDo) Omit(cols ...field.Expr) IAppUserDo {
func (a appUserDo) Omit(cols ...field.Expr) *appUserDo {
return a.withDO(a.DO.Omit(cols...))
}
func (a appUserDo) Join(table schema.Tabler, on ...field.Expr) IAppUserDo {
func (a appUserDo) Join(table schema.Tabler, on ...field.Expr) *appUserDo {
return a.withDO(a.DO.Join(table, on...))
}
func (a appUserDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAppUserDo {
func (a appUserDo) LeftJoin(table schema.Tabler, on ...field.Expr) *appUserDo {
return a.withDO(a.DO.LeftJoin(table, on...))
}
func (a appUserDo) RightJoin(table schema.Tabler, on ...field.Expr) IAppUserDo {
func (a appUserDo) RightJoin(table schema.Tabler, on ...field.Expr) *appUserDo {
return a.withDO(a.DO.RightJoin(table, on...))
}
func (a appUserDo) Group(cols ...field.Expr) IAppUserDo {
func (a appUserDo) Group(cols ...field.Expr) *appUserDo {
return a.withDO(a.DO.Group(cols...))
}
func (a appUserDo) Having(conds ...gen.Condition) IAppUserDo {
func (a appUserDo) Having(conds ...gen.Condition) *appUserDo {
return a.withDO(a.DO.Having(conds...))
}
func (a appUserDo) Limit(limit int) IAppUserDo {
func (a appUserDo) Limit(limit int) *appUserDo {
return a.withDO(a.DO.Limit(limit))
}
func (a appUserDo) Offset(offset int) IAppUserDo {
func (a appUserDo) Offset(offset int) *appUserDo {
return a.withDO(a.DO.Offset(offset))
}
func (a appUserDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAppUserDo {
func (a appUserDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *appUserDo {
return a.withDO(a.DO.Scopes(funcs...))
}
func (a appUserDo) Unscoped() IAppUserDo {
func (a appUserDo) Unscoped() *appUserDo {
return a.withDO(a.DO.Unscoped())
}
@ -335,22 +274,22 @@ func (a appUserDo) FindInBatches(result *[]*model.AppUser, batchSize int, fc fun
return a.DO.FindInBatches(result, batchSize, fc)
}
func (a appUserDo) Attrs(attrs ...field.AssignExpr) IAppUserDo {
func (a appUserDo) Attrs(attrs ...field.AssignExpr) *appUserDo {
return a.withDO(a.DO.Attrs(attrs...))
}
func (a appUserDo) Assign(attrs ...field.AssignExpr) IAppUserDo {
func (a appUserDo) Assign(attrs ...field.AssignExpr) *appUserDo {
return a.withDO(a.DO.Assign(attrs...))
}
func (a appUserDo) Joins(fields ...field.RelationField) IAppUserDo {
func (a appUserDo) Joins(fields ...field.RelationField) *appUserDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Joins(_f))
}
return &a
}
func (a appUserDo) Preload(fields ...field.RelationField) IAppUserDo {
func (a appUserDo) Preload(fields ...field.RelationField) *appUserDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Preload(_f))
}

View File

@ -9,7 +9,7 @@ import (
"fmt"
"testing"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm/gen/dao/model"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/internal/gen/dao/model"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm/clause"

View File

@ -15,50 +15,28 @@ import (
"gorm.io/plugin/dbresolver"
)
var (
Q = new(Query)
AppAccount *appAccount
AppUser *appUser
DouyinEcpmConfig *douyinEcpmConfig
GameScore *gameScore
)
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
*Q = *Use(db, opts...)
AppAccount = &Q.AppAccount
AppUser = &Q.AppUser
DouyinEcpmConfig = &Q.DouyinEcpmConfig
GameScore = &Q.GameScore
}
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
AppAccount: newAppAccount(db, opts...),
AppUser: newAppUser(db, opts...),
DouyinEcpmConfig: newDouyinEcpmConfig(db, opts...),
GameScore: newGameScore(db, opts...),
db: db,
AppAccount: newAppAccount(db, opts...),
AppUser: newAppUser(db, opts...),
}
}
type Query struct {
db *gorm.DB
AppAccount appAccount
AppUser appUser
DouyinEcpmConfig douyinEcpmConfig
GameScore gameScore
AppAccount appAccount
AppUser appUser
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
AppAccount: q.AppAccount.clone(db),
AppUser: q.AppUser.clone(db),
DouyinEcpmConfig: q.DouyinEcpmConfig.clone(db),
GameScore: q.GameScore.clone(db),
db: db,
AppAccount: q.AppAccount.clone(db),
AppUser: q.AppUser.clone(db),
}
}
@ -72,27 +50,21 @@ func (q *Query) WriteDB() *Query {
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
return &Query{
db: db,
AppAccount: q.AppAccount.replaceDB(db),
AppUser: q.AppUser.replaceDB(db),
DouyinEcpmConfig: q.DouyinEcpmConfig.replaceDB(db),
GameScore: q.GameScore.replaceDB(db),
db: db,
AppAccount: q.AppAccount.replaceDB(db),
AppUser: q.AppUser.replaceDB(db),
}
}
type queryCtx struct {
AppAccount IAppAccountDo
AppUser IAppUserDo
DouyinEcpmConfig IDouyinEcpmConfigDo
GameScore IGameScoreDo
AppAccount *appAccountDo
AppUser *appUserDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
AppAccount: q.AppAccount.WithContext(ctx),
AppUser: q.AppUser.WithContext(ctx),
DouyinEcpmConfig: q.DouyinEcpmConfig.WithContext(ctx),
GameScore: q.GameScore.WithContext(ctx),
AppAccount: q.AppAccount.WithContext(ctx),
AppUser: q.AppUser.WithContext(ctx),
}
}

View File

@ -79,8 +79,6 @@ func Test_WithContext(t *testing.T) {
for _, ctx := range []context.Context{
qCtx.AppAccount.UnderlyingDB().Statement.Context,
qCtx.AppUser.UnderlyingDB().Statement.Context,
qCtx.DouyinEcpmConfig.UnderlyingDB().Statement.Context,
qCtx.GameScore.UnderlyingDB().Statement.Context,
} {
if v := ctx.Value(key); v != value {
t.Errorf("get value from context fail, expect %q, got %q", value, v)

View File

@ -0,0 +1,15 @@
version: "0.1"
database:
dsn : "root:youtu!0113@tcp(192.168.0.47:3306)/ecpm?charset=utf8mb4&parseTime=True&loc=Local"
db : "mysql"
tables :
- "app_user"
- "app_account"
outPath : "./dao/query"
outFile : ""
withUnitTest : true
modelPkgName : "model"
fieldNullable : true
fieldWithIndexTag : true
fieldWithTypeTag : true
fieldSignable : true

View File

@ -2,8 +2,9 @@ package logic
import (
"context"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/auth_service"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/auth"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/user"
"github.com/zeromicro/go-zero/core/logx"
)
@ -22,7 +23,8 @@ func NewCode2SessionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Code
}
}
func (l *Code2SessionLogic) Code2Session(in *auth_service.Code2SessionRequest) (*auth_service.Code2SessionResponse, error) {
func (l *Code2SessionLogic) Code2Session(in *auth.Code2SessionRequest) (*auth.Code2SessionResponse, error) {
//获取cli调用抖音或者微信api
cli, err := l.svcCtx.Cli.Get(in.AppId)
if err != nil {
return nil, err
@ -31,8 +33,42 @@ func (l *Code2SessionLogic) Code2Session(in *auth_service.Code2SessionRequest) (
if err != nil {
return nil, err
}
return &auth_service.Code2SessionResponse{
//获取appId
ac := l.svcCtx.Query.AppAccount
acModel, err := ac.WithContext(l.ctx).Where(ac.AppID.Eq(in.AppId)).First()
if err != nil {
return nil, err
}
//获取用户id
au := l.svcCtx.Query.AppUser
auModel, err := au.WithContext(l.ctx).Where(au.AppAccountID.Eq(acModel.ID), au.Openid.Eq(res.OpenID)).FirstOrCreate()
if err != nil {
return nil, err
}
var isNew bool
//如果没有用户id则创建一个空用户
if auModel.UserID == nil {
userId, err := l.svcCtx.UserManagerClient.CreateEmptyUser(l.ctx, &user.Empty{})
if err != nil {
return nil, err
}
auModel.UserID = &userId.UserId
} else {
userModel, err := l.svcCtx.UserManagerClient.FindById(l.ctx, &user.UserId{UserId: *auModel.UserID})
if err != nil {
return nil, err
}
isNew = userModel.IsNew
}
return &auth.Code2SessionResponse{
AppId: acModel.ID,
OpenId: res.OpenID,
UnionId: res.UnionID,
UserId: *auModel.UserID,
IsNew: isNew,
}, nil
}

View File

@ -2,8 +2,8 @@ package logic
import (
"context"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/auth_service"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/auth"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
@ -22,7 +22,7 @@ func NewGetAccessTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
}
}
func (l *GetAccessTokenLogic) GetAccessToken(in *auth_service.GetAccessTokenRequest) (*auth_service.GetAccessTokenResponse, error) {
func (l *GetAccessTokenLogic) GetAccessToken(in *auth.GetAccessTokenRequest) (*auth.GetAccessTokenResponse, error) {
cli, err := l.svcCtx.Cli.Get(in.AppId)
if err != nil {
return nil, err
@ -31,5 +31,5 @@ func (l *GetAccessTokenLogic) GetAccessToken(in *auth_service.GetAccessTokenRequ
if err != nil {
return nil, err
}
return &auth_service.GetAccessTokenResponse{AccessToken: accessToken}, nil
return &auth.GetAccessTokenResponse{AccessToken: accessToken}, nil
}

View File

@ -2,8 +2,8 @@ package logic
import (
"context"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/auth_service"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/auth"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
@ -22,6 +22,6 @@ func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
}
}
func (l *PingLogic) Ping(in *auth_service.Request) (*auth_service.Response, error) {
return &auth_service.Response{Pong: in.Ping}, nil
func (l *PingLogic) Ping(in *auth.Request) (*auth.Response, error) {
return &auth.Response{Pong: in.Ping}, nil
}

View File

@ -6,14 +6,15 @@ package server
import (
"context"
auth_service2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/auth_service"
logic2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/logic"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/auth"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/internal/logic"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/internal/svc"
)
type AuthServiceServer struct {
svcCtx *svc.ServiceContext
auth_service2.UnimplementedAuthServiceServer
auth.UnimplementedAuthServiceServer
}
func NewAuthServiceServer(svcCtx *svc.ServiceContext) *AuthServiceServer {
@ -22,17 +23,17 @@ func NewAuthServiceServer(svcCtx *svc.ServiceContext) *AuthServiceServer {
}
}
func (s *AuthServiceServer) Ping(ctx context.Context, in *auth_service2.Request) (*auth_service2.Response, error) {
l := logic2.NewPingLogic(ctx, s.svcCtx)
func (s *AuthServiceServer) Ping(ctx context.Context, in *auth.Request) (*auth.Response, error) {
l := logic.NewPingLogic(ctx, s.svcCtx)
return l.Ping(in)
}
func (s *AuthServiceServer) Code2Session(ctx context.Context, in *auth_service2.Code2SessionRequest) (*auth_service2.Code2SessionResponse, error) {
l := logic2.NewCode2SessionLogic(ctx, s.svcCtx)
func (s *AuthServiceServer) Code2Session(ctx context.Context, in *auth.Code2SessionRequest) (*auth.Code2SessionResponse, error) {
l := logic.NewCode2SessionLogic(ctx, s.svcCtx)
return l.Code2Session(in)
}
func (s *AuthServiceServer) GetAccessToken(ctx context.Context, in *auth_service2.GetAccessTokenRequest) (*auth_service2.GetAccessTokenResponse, error) {
l := logic2.NewGetAccessTokenLogic(ctx, s.svcCtx)
func (s *AuthServiceServer) GetAccessToken(ctx context.Context, in *auth.GetAccessTokenRequest) (*auth.GetAccessTokenResponse, error) {
l := logic.NewGetAccessTokenLogic(ctx, s.svcCtx)
return l.GetAccessToken(in)
}

View File

@ -2,28 +2,107 @@ package svc
import (
"context"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/config"
cli2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/pkg"
"encoding/json"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/internal/gen/dao/query"
cli2 "gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/pkg"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/userservice"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/pkg/config"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/pkg/my_gorm"
"github.com/redis/go-redis/v9"
"github.com/silenceper/wechat/v2/cache"
redisCache "github.com/silenceper/wechat/v2/cache"
"github.com/spf13/viper"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/discov"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/zrpc"
clientv3 "go.etcd.io/etcd/client/v3"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
type ServiceContext struct {
Config config.Config
Cli cli2.Helper
Config config.Config
Cli cli2.Helper
UserManagerClient userservice.UserService
Query *query.Query
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
svc := &ServiceContext{
Config: c,
}
clientConf := zrpc.RpcClientConf{}
err := conf.FillDefault(&clientConf) // 填充默认值,比如 trace 透传等,参考服务配置说明
if err != nil {
panic(err)
}
clientConf.Token = "user_service.rpc.key"
clientConf.App = "user_service.rpc"
clientConf.Etcd = discov.EtcdConf{ // 通过 etcd 服务发现
Hosts: []string{viper.GetString(config.EtcdAddrKey)},
Key: "user_service.rpc",
}
//初始化redis client
redisClient := redis.NewClient(&redis.Options{
Addr: c.Redis[0].Host,
})
//初始化数据库
db, err := my_gorm.NewDBWithCache(mysql.Open(c.Mysql), &gorm.Config{}, redisClient)
if err != nil {
panic(err)
}
svc.Query = query.Use(db)
svc.UserManagerClient = userservice.NewUserService(zrpc.MustNewClient(clientConf))
svc.InitClient()
return svc
}
func (svc *ServiceContext) InitClient(c config.Config) {
type AppData struct {
AppId string `json:"appId"`
AppSecret string `json:"appSecret"`
Type string `json:"type"`
}
dwCache := redisCache.NewRedis(context.Background(), &redisCache.RedisOpts{Host: c.Redis.Host})
type AppDataList []AppData
const AppDataWatchKey = "/youtu/appData"
func (svc *ServiceContext) InitClient() {
dwCache := redisCache.NewRedis(context.Background(), &redisCache.RedisOpts{Host: svc.Config.Redis[0].Host})
cli, err := clientv3.NewFromURL(viper.GetString(config.EtcdAddrKey))
if err != nil {
panic(err)
}
go func() {
ch := make(chan []byte)
go config.EtcdGetOneAndWatch(context.TODO(), cli, AppDataWatchKey, ch)
//从通道中尝试取值(监视的信息)
for res := range ch {
var appDataArr AppDataList
err = json.Unmarshal(res, &appDataArr)
if err != nil {
logx.Errorf("etcd watch %s json.Unmarshal: %v", AppDataWatchKey, err)
continue
}
svc.SaveDW(appDataArr, dwCache)
}
}()
}
func (svc *ServiceContext) SaveDW(arr []AppData, dwCache cache.Cache) {
svc.Cli.Clear()
//配置小程序cli抖音&微信)
for _, v := range c.AppData {
for _, v := range arr {
var c cli2.DWClient
switch v.Type {
case cli2.DouyinClientType:

View File

@ -3,8 +3,8 @@ package cli
import (
"context"
"errors"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/pkg/douyin/access-token"
douyinopenapi "gitea.youtukeji.com.cn/youtu/openapi-helper/douyin"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/pkg/douyin/access-token"
"github.com/silenceper/wechat/v2/cache"
)

View File

@ -14,8 +14,8 @@ const (
code2Session = "https://minigame.zijieapi.com/mgplatform/api/apps/jscode2session" // 小程序登录地址
)
// DouYinOpenApiConfig 实例化配置
type DouYinOpenApiConfig struct {
// OpenApiConfig 实例化配置
type OpenApiConfig struct {
AppId string
AppSecret string
AccessToken accessToken.AccessToken
@ -25,32 +25,32 @@ type DouYinOpenApiConfig struct {
Salt string
}
// DouYinOpenApi 基类
type DouYinOpenApi struct {
Config DouYinOpenApiConfig
// OpenApi 基类
type OpenApi struct {
Config OpenApiConfig
BaseApi string
}
// NewDouYinOpenApi 实例化一个抖音openapi实例
func NewDouYinOpenApi(config DouYinOpenApiConfig) *DouYinOpenApi {
func NewDouYinOpenApi(config OpenApiConfig) *OpenApi {
if config.Cache == nil {
config.Cache = cache.NewMemory()
}
if config.AccessToken == nil {
config.AccessToken = accessToken.NewDefaultAccessToken(config.AppId, config.AppSecret, config.Cache, config.IsSandbox)
}
return &DouYinOpenApi{
return &OpenApi{
Config: config,
}
}
// GetApiUrl 获取api地址
func (d *DouYinOpenApi) GetApiUrl(url string) string {
func (d *OpenApi) GetApiUrl(url string) string {
return fmt.Sprintf("%s%s", d.BaseApi, url)
}
// Get 获取数据
func (d *DouYinOpenApi) Get(url string, params any) (data []byte, err error) {
func (d *OpenApi) Get(url string, params any) (data []byte, err error) {
paramsStr, err := util2.StructToQueryParams(params)
if err != nil {
return
@ -69,7 +69,7 @@ func (d *DouYinOpenApi) Get(url string, params any) (data []byte, err error) {
}
// PostJson 封装公共的请求方法
func (d *DouYinOpenApi) PostJson(api string, params any, response any) (err error) {
func (d *OpenApi) PostJson(api string, params any, response any) (err error) {
body, err := util2.PostJSON(api, params)
if err != nil {
return
@ -108,7 +108,7 @@ type Code2SessionResponseData struct {
}
// Code2Session 小程序登录
func (d *DouYinOpenApi) Code2Session(code, anonymousCode string) (code2SessionResponse Code2SessionResponse, err error) {
func (d *OpenApi) Code2Session(code, anonymousCode string) (code2SessionResponse Code2SessionResponse, err error) {
params := Code2SessionParams{
Appid: d.Config.AppId,
Secret: d.Config.AppSecret,
@ -147,6 +147,6 @@ type GetEcpmParams struct {
}
// GetAccessToken 获取accessToken
func (d *DouYinOpenApi) GetAccessToken() (string, error) {
func (d *OpenApi) GetAccessToken() (string, error) {
return d.Config.AccessToken.GetAccessToken()
}

View File

@ -1,90 +0,0 @@
package douyin
import (
accessToken "gitea.youtukeji.com.cn/youtu/openapi-helper/douyin/access-token"
"github.com/silenceper/wechat/v2/cache"
"testing"
"time"
)
// 声明测试常量
const (
AppId = "tt8b32fd8f14071db707"
AppSecret = "44018e80b1bde34395a52de67ce1e0c37c572d80"
Token = ""
Salt = ""
)
// 声明一个缓存实例
var Cache cache.Cache
// 声明全局openApi实例
var OpenApi *DouYinOpenApi
func init() {
Cache = cache.NewMemory()
OpenApi = NewDouYinOpenApi(DouYinOpenApiConfig{
AppId: AppId,
AppSecret: AppSecret,
IsSandbox: false,
Token: Token,
Salt: Salt,
})
}
// 测试获取新的token
func TestDouyinOpenapi_NewDefaultAccessToken(t *testing.T) {
token := accessToken.NewDefaultAccessToken(AppId, AppSecret, Cache, true)
getAccessToken, err := token.GetAccessToken()
if err != nil {
t.Errorf("got a error: %s", err.Error())
return
}
t.Logf("got a value: %s", getAccessToken)
}
// 基准测试看获取token的次数?
func BenchmarkDouyinOpenapi_NewDefaultAccessToken(b *testing.B) {
token := accessToken.NewDefaultAccessToken(AppId, AppSecret, Cache, true)
for i := 0; i < b.N; i++ {
getAccessToken, err := token.GetAccessToken()
b.Logf("get token: %s %+v", getAccessToken, err)
}
}
// 测试小程序登录
func TestDouYinOpenApi_Code2Session(t *testing.T) {
session, err := OpenApi.Code2Session("1111", "")
if err != nil {
t.Errorf("got a error %s", err.Error())
return
}
t.Logf("got a value %+v", session)
}
func TestDouYinOpenApi_GetEcpm(t *testing.T) {
// 获取动态的 access_token
token := accessToken.NewDefaultAccessToken(AppId, AppSecret, Cache, true)
at, err := token.GetAccessToken()
if err != nil {
t.Errorf("got a error: %s", err.Error())
return
}
list, err := OpenApi.GetEcpm(GetEcpmParams{
AppId: AppId,
OpenId: "_000aG3MQTzVW-yCUH-ndwv90JIyvdTSD0gf",
AccessToken: at,
DateHour: time.Now().Format(time.DateOnly),
PageSize: 500,
PageNo: 1,
})
if err != nil {
t.Errorf("got a error %s", err.Error())
return
}
t.Logf("got a value %+v", list)
}

View File

@ -1,38 +0,0 @@
package main
import (
"flag"
"fmt"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/douyin_ecpm_calculation_service/douyin_ecpm_calculation_service"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/douyin_ecpm_calculation_service/internal/config"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/douyin_ecpm_calculation_service/internal/server"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/douyin_ecpm_calculation_service/internal/svc"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
var configFile = flag.String("f", "etc/douyin_ecpm_calculation_service.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
ctx := svc.NewServiceContext(c)
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
douyin_ecpm_calculation_service.RegisterDouyinEcpmCalculationServiceServer(grpcServer, server.NewDouyinEcpmCalculationServiceServer(ctx))
if c.Mode == service.DevMode || c.Mode == service.TestMode {
reflection.Register(grpcServer)
}
})
defer s.Stop()
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
s.Start()
}

View File

@ -1,299 +0,0 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.4
// protoc v3.19.4
// source: douyin_ecpm_calculation_service.proto
package douyin_ecpm_calculation_service
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type Request struct {
state protoimpl.MessageState `protogen:"open.v1"`
Ping string `protobuf:"bytes,1,opt,name=ping,proto3" json:"ping,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Request) Reset() {
*x = Request{}
mi := &file_douyin_ecpm_calculation_service_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Request) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Request) ProtoMessage() {}
func (x *Request) ProtoReflect() protoreflect.Message {
mi := &file_douyin_ecpm_calculation_service_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Request.ProtoReflect.Descriptor instead.
func (*Request) Descriptor() ([]byte, []int) {
return file_douyin_ecpm_calculation_service_proto_rawDescGZIP(), []int{0}
}
func (x *Request) GetPing() string {
if x != nil {
return x.Ping
}
return ""
}
type Response struct {
state protoimpl.MessageState `protogen:"open.v1"`
Pong string `protobuf:"bytes,1,opt,name=pong,proto3" json:"pong,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Response) Reset() {
*x = Response{}
mi := &file_douyin_ecpm_calculation_service_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Response) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Response) ProtoMessage() {}
func (x *Response) ProtoReflect() protoreflect.Message {
mi := &file_douyin_ecpm_calculation_service_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Response.ProtoReflect.Descriptor instead.
func (*Response) Descriptor() ([]byte, []int) {
return file_douyin_ecpm_calculation_service_proto_rawDescGZIP(), []int{1}
}
func (x *Response) GetPong() string {
if x != nil {
return x.Pong
}
return ""
}
type GetEcpmRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
AppId string `protobuf:"bytes,1,opt,name=appId,proto3" json:"appId,omitempty"`
OpenId string `protobuf:"bytes,2,opt,name=openId,proto3" json:"openId,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetEcpmRequest) Reset() {
*x = GetEcpmRequest{}
mi := &file_douyin_ecpm_calculation_service_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetEcpmRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetEcpmRequest) ProtoMessage() {}
func (x *GetEcpmRequest) ProtoReflect() protoreflect.Message {
mi := &file_douyin_ecpm_calculation_service_proto_msgTypes[2]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetEcpmRequest.ProtoReflect.Descriptor instead.
func (*GetEcpmRequest) Descriptor() ([]byte, []int) {
return file_douyin_ecpm_calculation_service_proto_rawDescGZIP(), []int{2}
}
func (x *GetEcpmRequest) GetAppId() string {
if x != nil {
return x.AppId
}
return ""
}
func (x *GetEcpmRequest) GetOpenId() string {
if x != nil {
return x.OpenId
}
return ""
}
type GetEcpmResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Ok bool `protobuf:"varint,1,opt,name=ok,proto3" json:"ok,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetEcpmResponse) Reset() {
*x = GetEcpmResponse{}
mi := &file_douyin_ecpm_calculation_service_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetEcpmResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetEcpmResponse) ProtoMessage() {}
func (x *GetEcpmResponse) ProtoReflect() protoreflect.Message {
mi := &file_douyin_ecpm_calculation_service_proto_msgTypes[3]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetEcpmResponse.ProtoReflect.Descriptor instead.
func (*GetEcpmResponse) Descriptor() ([]byte, []int) {
return file_douyin_ecpm_calculation_service_proto_rawDescGZIP(), []int{3}
}
func (x *GetEcpmResponse) GetOk() bool {
if x != nil {
return x.Ok
}
return false
}
var File_douyin_ecpm_calculation_service_proto protoreflect.FileDescriptor
var file_douyin_ecpm_calculation_service_proto_rawDesc = string([]byte{
0x0a, 0x25, 0x64, 0x6f, 0x75, 0x79, 0x69, 0x6e, 0x5f, 0x65, 0x63, 0x70, 0x6d, 0x5f, 0x63, 0x61,
0x6c, 0x63, 0x75, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1f, 0x64, 0x6f, 0x75, 0x79, 0x69, 0x6e, 0x5f,
0x65, 0x63, 0x70, 0x6d, 0x5f, 0x63, 0x61, 0x6c, 0x63, 0x75, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x22, 0x1d, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x04, 0x70, 0x69, 0x6e, 0x67, 0x22, 0x1e, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x04, 0x70, 0x6f, 0x6e, 0x67, 0x22, 0x3e, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x45, 0x63,
0x70, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70,
0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x12,
0x16, 0x0a, 0x06, 0x6f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
0x06, 0x6f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x22, 0x21, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x45, 0x63,
0x70, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x6f, 0x6b,
0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x02, 0x6f, 0x6b, 0x32, 0xec, 0x01, 0x0a, 0x1f, 0x64,
0x6f, 0x75, 0x79, 0x69, 0x6e, 0x5f, 0x65, 0x63, 0x70, 0x6d, 0x5f, 0x63, 0x61, 0x6c, 0x63, 0x75,
0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x5b,
0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x28, 0x2e, 0x64, 0x6f, 0x75, 0x79, 0x69, 0x6e, 0x5f,
0x65, 0x63, 0x70, 0x6d, 0x5f, 0x63, 0x61, 0x6c, 0x63, 0x75, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x1a, 0x29, 0x2e, 0x64, 0x6f, 0x75, 0x79, 0x69, 0x6e, 0x5f, 0x65, 0x63, 0x70, 0x6d, 0x5f, 0x63,
0x61, 0x6c, 0x63, 0x75, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69,
0x63, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6c, 0x0a, 0x07, 0x47,
0x65, 0x74, 0x45, 0x63, 0x70, 0x6d, 0x12, 0x2f, 0x2e, 0x64, 0x6f, 0x75, 0x79, 0x69, 0x6e, 0x5f,
0x65, 0x63, 0x70, 0x6d, 0x5f, 0x63, 0x61, 0x6c, 0x63, 0x75, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x45, 0x63, 0x70, 0x6d,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x30, 0x2e, 0x64, 0x6f, 0x75, 0x79, 0x69, 0x6e,
0x5f, 0x65, 0x63, 0x70, 0x6d, 0x5f, 0x63, 0x61, 0x6c, 0x63, 0x75, 0x6c, 0x61, 0x74, 0x69, 0x6f,
0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x45, 0x63, 0x70,
0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x23, 0x5a, 0x21, 0x2e, 0x2f, 0x64,
0x6f, 0x75, 0x79, 0x69, 0x6e, 0x5f, 0x65, 0x63, 0x70, 0x6d, 0x5f, 0x63, 0x61, 0x6c, 0x63, 0x75,
0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
})
var (
file_douyin_ecpm_calculation_service_proto_rawDescOnce sync.Once
file_douyin_ecpm_calculation_service_proto_rawDescData []byte
)
func file_douyin_ecpm_calculation_service_proto_rawDescGZIP() []byte {
file_douyin_ecpm_calculation_service_proto_rawDescOnce.Do(func() {
file_douyin_ecpm_calculation_service_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_douyin_ecpm_calculation_service_proto_rawDesc), len(file_douyin_ecpm_calculation_service_proto_rawDesc)))
})
return file_douyin_ecpm_calculation_service_proto_rawDescData
}
var file_douyin_ecpm_calculation_service_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
var file_douyin_ecpm_calculation_service_proto_goTypes = []any{
(*Request)(nil), // 0: douyin_ecpm_calculation_service.Request
(*Response)(nil), // 1: douyin_ecpm_calculation_service.Response
(*GetEcpmRequest)(nil), // 2: douyin_ecpm_calculation_service.GetEcpmRequest
(*GetEcpmResponse)(nil), // 3: douyin_ecpm_calculation_service.GetEcpmResponse
}
var file_douyin_ecpm_calculation_service_proto_depIdxs = []int32{
0, // 0: douyin_ecpm_calculation_service.douyin_ecpm_calculation_service.Ping:input_type -> douyin_ecpm_calculation_service.Request
2, // 1: douyin_ecpm_calculation_service.douyin_ecpm_calculation_service.GetEcpm:input_type -> douyin_ecpm_calculation_service.GetEcpmRequest
1, // 2: douyin_ecpm_calculation_service.douyin_ecpm_calculation_service.Ping:output_type -> douyin_ecpm_calculation_service.Response
3, // 3: douyin_ecpm_calculation_service.douyin_ecpm_calculation_service.GetEcpm:output_type -> douyin_ecpm_calculation_service.GetEcpmResponse
2, // [2:4] is the sub-list for method output_type
0, // [0:2] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_douyin_ecpm_calculation_service_proto_init() }
func file_douyin_ecpm_calculation_service_proto_init() {
if File_douyin_ecpm_calculation_service_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_douyin_ecpm_calculation_service_proto_rawDesc), len(file_douyin_ecpm_calculation_service_proto_rawDesc)),
NumEnums: 0,
NumMessages: 4,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_douyin_ecpm_calculation_service_proto_goTypes,
DependencyIndexes: file_douyin_ecpm_calculation_service_proto_depIdxs,
MessageInfos: file_douyin_ecpm_calculation_service_proto_msgTypes,
}.Build()
File_douyin_ecpm_calculation_service_proto = out.File
file_douyin_ecpm_calculation_service_proto_goTypes = nil
file_douyin_ecpm_calculation_service_proto_depIdxs = nil
}

View File

@ -1,160 +0,0 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc v3.19.4
// source: douyin_ecpm_calculation_service.proto
package douyin_ecpm_calculation_service
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
DouyinEcpmCalculationService_Ping_FullMethodName = "/douyin_ecpm_calculation_service.douyin_ecpm_calculation_service/Ping"
DouyinEcpmCalculationService_GetEcpm_FullMethodName = "/douyin_ecpm_calculation_service.douyin_ecpm_calculation_service/GetEcpm"
)
// DouyinEcpmCalculationServiceClient is the client API for DouyinEcpmCalculationService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type DouyinEcpmCalculationServiceClient interface {
Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
GetEcpm(ctx context.Context, in *GetEcpmRequest, opts ...grpc.CallOption) (*GetEcpmResponse, error)
}
type douyinEcpmCalculationServiceClient struct {
cc grpc.ClientConnInterface
}
func NewDouyinEcpmCalculationServiceClient(cc grpc.ClientConnInterface) DouyinEcpmCalculationServiceClient {
return &douyinEcpmCalculationServiceClient{cc}
}
func (c *douyinEcpmCalculationServiceClient) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Response)
err := c.cc.Invoke(ctx, DouyinEcpmCalculationService_Ping_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *douyinEcpmCalculationServiceClient) GetEcpm(ctx context.Context, in *GetEcpmRequest, opts ...grpc.CallOption) (*GetEcpmResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetEcpmResponse)
err := c.cc.Invoke(ctx, DouyinEcpmCalculationService_GetEcpm_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// DouyinEcpmCalculationServiceServer is the server API for DouyinEcpmCalculationService service.
// All implementations must embed UnimplementedDouyinEcpmCalculationServiceServer
// for forward compatibility.
type DouyinEcpmCalculationServiceServer interface {
Ping(context.Context, *Request) (*Response, error)
GetEcpm(context.Context, *GetEcpmRequest) (*GetEcpmResponse, error)
mustEmbedUnimplementedDouyinEcpmCalculationServiceServer()
}
// UnimplementedDouyinEcpmCalculationServiceServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedDouyinEcpmCalculationServiceServer struct{}
func (UnimplementedDouyinEcpmCalculationServiceServer) Ping(context.Context, *Request) (*Response, error) {
return nil, status.Errorf(codes.Unimplemented, "method Ping not implemented")
}
func (UnimplementedDouyinEcpmCalculationServiceServer) GetEcpm(context.Context, *GetEcpmRequest) (*GetEcpmResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetEcpm not implemented")
}
func (UnimplementedDouyinEcpmCalculationServiceServer) mustEmbedUnimplementedDouyinEcpmCalculationServiceServer() {
}
func (UnimplementedDouyinEcpmCalculationServiceServer) testEmbeddedByValue() {}
// UnsafeDouyinEcpmCalculationServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to DouyinEcpmCalculationServiceServer will
// result in compilation errors.
type UnsafeDouyinEcpmCalculationServiceServer interface {
mustEmbedUnimplementedDouyinEcpmCalculationServiceServer()
}
func RegisterDouyinEcpmCalculationServiceServer(s grpc.ServiceRegistrar, srv DouyinEcpmCalculationServiceServer) {
// If the following call pancis, it indicates UnimplementedDouyinEcpmCalculationServiceServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&DouyinEcpmCalculationService_ServiceDesc, srv)
}
func _DouyinEcpmCalculationService_Ping_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Request)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(DouyinEcpmCalculationServiceServer).Ping(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: DouyinEcpmCalculationService_Ping_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(DouyinEcpmCalculationServiceServer).Ping(ctx, req.(*Request))
}
return interceptor(ctx, in, info, handler)
}
func _DouyinEcpmCalculationService_GetEcpm_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetEcpmRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(DouyinEcpmCalculationServiceServer).GetEcpm(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: DouyinEcpmCalculationService_GetEcpm_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(DouyinEcpmCalculationServiceServer).GetEcpm(ctx, req.(*GetEcpmRequest))
}
return interceptor(ctx, in, info, handler)
}
// DouyinEcpmCalculationService_ServiceDesc is the grpc.ServiceDesc for DouyinEcpmCalculationService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var DouyinEcpmCalculationService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "douyin_ecpm_calculation_service.douyin_ecpm_calculation_service",
HandlerType: (*DouyinEcpmCalculationServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Ping",
Handler: _DouyinEcpmCalculationService_Ping_Handler,
},
{
MethodName: "GetEcpm",
Handler: _DouyinEcpmCalculationService_GetEcpm_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "douyin_ecpm_calculation_service.proto",
}

View File

@ -1,45 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.7.6
// Source: douyin_ecpm_calculation_service.proto
package douyin_ecpm_calculation_service_client
import (
"context"
douyin_ecpm_calculation_service2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/douyin_ecpm_calculation_service/douyin_ecpm_calculation_service"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
)
type (
GetEcpmRequest = douyin_ecpm_calculation_service2.GetEcpmRequest
GetEcpmResponse = douyin_ecpm_calculation_service2.GetEcpmResponse
Request = douyin_ecpm_calculation_service2.Request
Response = douyin_ecpm_calculation_service2.Response
DouyinEcpmCalculationService interface {
Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
GetEcpm(ctx context.Context, in *GetEcpmRequest, opts ...grpc.CallOption) (*GetEcpmResponse, error)
}
defaultDouyinEcpmCalculationService struct {
cli zrpc.Client
}
)
func NewDouyinEcpmCalculationService(cli zrpc.Client) DouyinEcpmCalculationService {
return &defaultDouyinEcpmCalculationService{
cli: cli,
}
}
func (m *defaultDouyinEcpmCalculationService) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
client := douyin_ecpm_calculation_service2.NewDouyinEcpmCalculationServiceClient(m.cli.Conn())
return client.Ping(ctx, in, opts...)
}
func (m *defaultDouyinEcpmCalculationService) GetEcpm(ctx context.Context, in *GetEcpmRequest, opts ...grpc.CallOption) (*GetEcpmResponse, error) {
client := douyin_ecpm_calculation_service2.NewDouyinEcpmCalculationServiceClient(m.cli.Conn())
return client.GetEcpm(ctx, in, opts...)
}

View File

@ -1,6 +0,0 @@
Name: douyin_ecpm_calculation_service.rpc
ListenOn: 0.0.0.0:8081
Etcd:
Hosts:
- 127.0.0.1:2379
Key: douyin_ecpm_calculation_service.rpc

View File

@ -1,27 +0,0 @@
package logic
import (
"context"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/douyin_ecpm_calculation_service/douyin_ecpm_calculation_service"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/douyin_ecpm_calculation_service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type PingLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
return &PingLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *PingLogic) Ping(in *douyin_ecpm_calculation_service.Request) (*douyin_ecpm_calculation_service.Response, error) {
return &douyin_ecpm_calculation_service.Response{Pong: in.Ping}, nil
}

View File

@ -1,33 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.7.6
// Source: douyin_ecpm_calculation_service.proto
package server
import (
"context"
douyin_ecpm_calculation_service2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/douyin_ecpm_calculation_service/douyin_ecpm_calculation_service"
logic2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/douyin_ecpm_calculation_service/internal/logic"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/douyin_ecpm_calculation_service/internal/svc"
)
type DouyinEcpmCalculationServiceServer struct {
svcCtx *svc.ServiceContext
douyin_ecpm_calculation_service2.UnimplementedDouyinEcpmCalculationServiceServer
}
func NewDouyinEcpmCalculationServiceServer(svcCtx *svc.ServiceContext) *DouyinEcpmCalculationServiceServer {
return &DouyinEcpmCalculationServiceServer{
svcCtx: svcCtx,
}
}
func (s *DouyinEcpmCalculationServiceServer) Ping(ctx context.Context, in *douyin_ecpm_calculation_service2.Request) (*douyin_ecpm_calculation_service2.Response, error) {
l := logic2.NewPingLogic(ctx, s.svcCtx)
return l.Ping(in)
}
func (s *DouyinEcpmCalculationServiceServer) GetEcpm(ctx context.Context, in *douyin_ecpm_calculation_service2.GetEcpmRequest) (*douyin_ecpm_calculation_service2.GetEcpmResponse, error) {
l := logic2.NewGetEcpmLogic(ctx, s.svcCtx)
return l.GetEcpm(in)
}

View File

@ -0,0 +1,33 @@
FROM golang:alpine AS builder
LABEL stage=gobuilder
ENV CGO_ENABLED=0
ENV GOPROXY=https://goproxy.cn,direct
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk update --no-cache && apk add --no-cache tzdata
RUN apk add --no-cache git
WORKDIR /build
ADD go.mod .
ADD go.sum .
RUN go env -w GOPRIVATE=gitea.youtukeji.com.cn
RUN go mod download
COPY . .
RUN go build -ldflags="-s -w" -o /app/ecpm ./app/ecpm_service/ecpm_service.go
FROM alpine
COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai
ENV TZ=Asia/Shanghai
WORKDIR /app
COPY --from=builder /app/ecpm /app/ecpm
EXPOSE 8888
CMD ["/app/ecpm"]

View File

@ -0,0 +1,289 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.4
// protoc v3.19.4
// source: ecpm_service.proto
package ecpm
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type Request struct {
state protoimpl.MessageState `protogen:"open.v1"`
Ping string `protobuf:"bytes,1,opt,name=ping,proto3" json:"ping,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Request) Reset() {
*x = Request{}
mi := &file_ecpm_service_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Request) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Request) ProtoMessage() {}
func (x *Request) ProtoReflect() protoreflect.Message {
mi := &file_ecpm_service_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Request.ProtoReflect.Descriptor instead.
func (*Request) Descriptor() ([]byte, []int) {
return file_ecpm_service_proto_rawDescGZIP(), []int{0}
}
func (x *Request) GetPing() string {
if x != nil {
return x.Ping
}
return ""
}
type Response struct {
state protoimpl.MessageState `protogen:"open.v1"`
Pong string `protobuf:"bytes,1,opt,name=pong,proto3" json:"pong,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Response) Reset() {
*x = Response{}
mi := &file_ecpm_service_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Response) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Response) ProtoMessage() {}
func (x *Response) ProtoReflect() protoreflect.Message {
mi := &file_ecpm_service_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Response.ProtoReflect.Descriptor instead.
func (*Response) Descriptor() ([]byte, []int) {
return file_ecpm_service_proto_rawDescGZIP(), []int{1}
}
func (x *Response) GetPong() string {
if x != nil {
return x.Pong
}
return ""
}
type GetEcpmRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
AppId string `protobuf:"bytes,1,opt,name=appId,proto3" json:"appId,omitempty"`
OpenId string `protobuf:"bytes,2,opt,name=openId,proto3" json:"openId,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetEcpmRequest) Reset() {
*x = GetEcpmRequest{}
mi := &file_ecpm_service_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetEcpmRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetEcpmRequest) ProtoMessage() {}
func (x *GetEcpmRequest) ProtoReflect() protoreflect.Message {
mi := &file_ecpm_service_proto_msgTypes[2]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetEcpmRequest.ProtoReflect.Descriptor instead.
func (*GetEcpmRequest) Descriptor() ([]byte, []int) {
return file_ecpm_service_proto_rawDescGZIP(), []int{2}
}
func (x *GetEcpmRequest) GetAppId() string {
if x != nil {
return x.AppId
}
return ""
}
func (x *GetEcpmRequest) GetOpenId() string {
if x != nil {
return x.OpenId
}
return ""
}
type GetEcpmResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Ok bool `protobuf:"varint,1,opt,name=ok,proto3" json:"ok,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetEcpmResponse) Reset() {
*x = GetEcpmResponse{}
mi := &file_ecpm_service_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetEcpmResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetEcpmResponse) ProtoMessage() {}
func (x *GetEcpmResponse) ProtoReflect() protoreflect.Message {
mi := &file_ecpm_service_proto_msgTypes[3]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetEcpmResponse.ProtoReflect.Descriptor instead.
func (*GetEcpmResponse) Descriptor() ([]byte, []int) {
return file_ecpm_service_proto_rawDescGZIP(), []int{3}
}
func (x *GetEcpmResponse) GetOk() bool {
if x != nil {
return x.Ok
}
return false
}
var File_ecpm_service_proto protoreflect.FileDescriptor
var file_ecpm_service_proto_rawDesc = string([]byte{
0x0a, 0x12, 0x65, 0x63, 0x70, 0x6d, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0c, 0x65, 0x63, 0x70, 0x6d, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69,
0x63, 0x65, 0x22, 0x1d, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a,
0x04, 0x70, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x69, 0x6e,
0x67, 0x22, 0x1e, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a,
0x04, 0x70, 0x6f, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x6f, 0x6e,
0x67, 0x22, 0x3e, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x45, 0x63, 0x70, 0x6d, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x70, 0x65,
0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6f, 0x70, 0x65, 0x6e, 0x49,
0x64, 0x22, 0x21, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x45, 0x63, 0x70, 0x6d, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x6f, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08,
0x52, 0x02, 0x6f, 0x6b, 0x32, 0x8d, 0x01, 0x0a, 0x0c, 0x65, 0x63, 0x70, 0x6d, 0x5f, 0x73, 0x65,
0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x35, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x15, 0x2e,
0x65, 0x63, 0x70, 0x6d, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x65, 0x63, 0x70, 0x6d, 0x5f, 0x73, 0x65, 0x72, 0x76,
0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x46, 0x0a, 0x07,
0x47, 0x65, 0x74, 0x45, 0x63, 0x70, 0x6d, 0x12, 0x1c, 0x2e, 0x65, 0x63, 0x70, 0x6d, 0x5f, 0x73,
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x45, 0x63, 0x70, 0x6d, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x65, 0x63, 0x70, 0x6d, 0x5f, 0x73, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x45, 0x63, 0x70, 0x6d, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x42, 0x08, 0x5a, 0x06, 0x2e, 0x2f, 0x65, 0x63, 0x70, 0x6d, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
})
var (
file_ecpm_service_proto_rawDescOnce sync.Once
file_ecpm_service_proto_rawDescData []byte
)
func file_ecpm_service_proto_rawDescGZIP() []byte {
file_ecpm_service_proto_rawDescOnce.Do(func() {
file_ecpm_service_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_ecpm_service_proto_rawDesc), len(file_ecpm_service_proto_rawDesc)))
})
return file_ecpm_service_proto_rawDescData
}
var file_ecpm_service_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
var file_ecpm_service_proto_goTypes = []any{
(*Request)(nil), // 0: ecpm_service.Request
(*Response)(nil), // 1: ecpm_service.Response
(*GetEcpmRequest)(nil), // 2: ecpm_service.GetEcpmRequest
(*GetEcpmResponse)(nil), // 3: ecpm_service.GetEcpmResponse
}
var file_ecpm_service_proto_depIdxs = []int32{
0, // 0: ecpm_service.ecpm_service.Ping:input_type -> ecpm_service.Request
2, // 1: ecpm_service.ecpm_service.GetEcpm:input_type -> ecpm_service.GetEcpmRequest
1, // 2: ecpm_service.ecpm_service.Ping:output_type -> ecpm_service.Response
3, // 3: ecpm_service.ecpm_service.GetEcpm:output_type -> ecpm_service.GetEcpmResponse
2, // [2:4] is the sub-list for method output_type
0, // [0:2] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_ecpm_service_proto_init() }
func file_ecpm_service_proto_init() {
if File_ecpm_service_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_ecpm_service_proto_rawDesc), len(file_ecpm_service_proto_rawDesc)),
NumEnums: 0,
NumMessages: 4,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_ecpm_service_proto_goTypes,
DependencyIndexes: file_ecpm_service_proto_depIdxs,
MessageInfos: file_ecpm_service_proto_msgTypes,
}.Build()
File_ecpm_service_proto = out.File
file_ecpm_service_proto_goTypes = nil
file_ecpm_service_proto_depIdxs = nil
}

View File

@ -0,0 +1,159 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc v3.19.4
// source: ecpm_service.proto
package ecpm
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
EcpmService_Ping_FullMethodName = "/ecpm_service.ecpm_service/Ping"
EcpmService_GetEcpm_FullMethodName = "/ecpm_service.ecpm_service/GetEcpm"
)
// EcpmServiceClient is the client API for EcpmService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type EcpmServiceClient interface {
Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
GetEcpm(ctx context.Context, in *GetEcpmRequest, opts ...grpc.CallOption) (*GetEcpmResponse, error)
}
type ecpmServiceClient struct {
cc grpc.ClientConnInterface
}
func NewEcpmServiceClient(cc grpc.ClientConnInterface) EcpmServiceClient {
return &ecpmServiceClient{cc}
}
func (c *ecpmServiceClient) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Response)
err := c.cc.Invoke(ctx, EcpmService_Ping_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *ecpmServiceClient) GetEcpm(ctx context.Context, in *GetEcpmRequest, opts ...grpc.CallOption) (*GetEcpmResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetEcpmResponse)
err := c.cc.Invoke(ctx, EcpmService_GetEcpm_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// EcpmServiceServer is the server API for EcpmService service.
// All implementations must embed UnimplementedEcpmServiceServer
// for forward compatibility.
type EcpmServiceServer interface {
Ping(context.Context, *Request) (*Response, error)
GetEcpm(context.Context, *GetEcpmRequest) (*GetEcpmResponse, error)
mustEmbedUnimplementedEcpmServiceServer()
}
// UnimplementedEcpmServiceServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedEcpmServiceServer struct{}
func (UnimplementedEcpmServiceServer) Ping(context.Context, *Request) (*Response, error) {
return nil, status.Errorf(codes.Unimplemented, "method Ping not implemented")
}
func (UnimplementedEcpmServiceServer) GetEcpm(context.Context, *GetEcpmRequest) (*GetEcpmResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetEcpm not implemented")
}
func (UnimplementedEcpmServiceServer) mustEmbedUnimplementedEcpmServiceServer() {}
func (UnimplementedEcpmServiceServer) testEmbeddedByValue() {}
// UnsafeEcpmServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to EcpmServiceServer will
// result in compilation errors.
type UnsafeEcpmServiceServer interface {
mustEmbedUnimplementedEcpmServiceServer()
}
func RegisterEcpmServiceServer(s grpc.ServiceRegistrar, srv EcpmServiceServer) {
// If the following call pancis, it indicates UnimplementedEcpmServiceServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&EcpmService_ServiceDesc, srv)
}
func _EcpmService_Ping_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Request)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(EcpmServiceServer).Ping(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: EcpmService_Ping_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(EcpmServiceServer).Ping(ctx, req.(*Request))
}
return interceptor(ctx, in, info, handler)
}
func _EcpmService_GetEcpm_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetEcpmRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(EcpmServiceServer).GetEcpm(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: EcpmService_GetEcpm_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(EcpmServiceServer).GetEcpm(ctx, req.(*GetEcpmRequest))
}
return interceptor(ctx, in, info, handler)
}
// EcpmService_ServiceDesc is the grpc.ServiceDesc for EcpmService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var EcpmService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "ecpm_service.ecpm_service",
HandlerType: (*EcpmServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Ping",
Handler: _EcpmService_Ping_Handler,
},
{
MethodName: "GetEcpm",
Handler: _EcpmService_GetEcpm_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "ecpm_service.proto",
}

View File

@ -0,0 +1,43 @@
package main
import (
"flag"
"fmt"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ecpm_service/ecpm"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ecpm_service/internal/server"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ecpm_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/pkg/config"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
const ServiceName = "ecpm_service"
func main() {
flag.Parse()
var c config.Config
err := config.GetConfig(&c, ServiceName)
if err != nil {
panic(err)
}
c.RpcServerConf.Name = ServiceName + ".rpc"
ctx := svc.NewServiceContext(c)
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
ecpm.RegisterEcpmServiceServer(grpcServer, server.NewEcpmServiceServer(ctx))
if c.Mode == service.DevMode || c.Mode == service.TestMode {
reflection.Register(grpcServer)
}
})
defer s.Stop()
fmt.Printf("Starting rpc server at %s...\n", c.RpcServerConf.ListenOn)
s.Start()
}

View File

@ -1,7 +1,7 @@
syntax = "proto3";
package douyin_ecpm_calculation_service;
option go_package="./douyin_ecpm_calculation_service";
package ecpm_service;
option go_package="./ecpm";
message Request {
string ping = 1;
@ -20,7 +20,7 @@ message GetEcpmResponse{
bool ok =1;
}
service douyin_ecpm_calculation_service {
service ecpm_service {
rpc Ping(Request) returns(Response);

View File

@ -0,0 +1,46 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.7.6
// Source: ecpm_service.proto
package ecpmservice
import (
"context"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ecpm_service/ecpm"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
)
type (
GetEcpmRequest = ecpm.GetEcpmRequest
GetEcpmResponse = ecpm.GetEcpmResponse
Request = ecpm.Request
Response = ecpm.Response
EcpmService interface {
Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
GetEcpm(ctx context.Context, in *GetEcpmRequest, opts ...grpc.CallOption) (*GetEcpmResponse, error)
}
defaultEcpmService struct {
cli zrpc.Client
}
)
func NewEcpmService(cli zrpc.Client) EcpmService {
return &defaultEcpmService{
cli: cli,
}
}
func (m *defaultEcpmService) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
client := ecpm.NewEcpmServiceClient(m.cli.Conn())
return client.Ping(ctx, in, opts...)
}
func (m *defaultEcpmService) GetEcpm(ctx context.Context, in *GetEcpmRequest, opts ...grpc.CallOption) (*GetEcpmResponse, error) {
client := ecpm.NewEcpmServiceClient(m.cli.Conn())
return client.GetEcpm(ctx, in, opts...)
}

View File

@ -0,0 +1,6 @@
Name: ecpm.rpc
ListenOn: 0.0.0.0:8081
Etcd:
Hosts:
- 127.0.0.1:2379
Key: ecpm.rpc

View File

@ -5,9 +5,9 @@ import (
"encoding/json"
"errors"
"fmt"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/auth_service"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/douyin_ecpm_calculation_service/douyin_ecpm_calculation_service"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/douyin_ecpm_calculation_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/auth"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ecpm_service/ecpm"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ecpm_service/internal/svc"
"io"
"net/http"
"strconv"
@ -30,9 +30,9 @@ func NewGetEcpmLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetEcpmLo
}
}
func (l *GetEcpmLogic) GetEcpm(in *douyin_ecpm_calculation_service.GetEcpmRequest) (response *douyin_ecpm_calculation_service.GetEcpmResponse, err error) {
func (l *GetEcpmLogic) GetEcpm(in *ecpm.GetEcpmRequest) (response *ecpm.GetEcpmResponse, err error) {
//获取抖音accessToken
res, err := l.svcCtx.AuthServiceClient.GetAccessToken(l.ctx, &auth_service.GetAccessTokenRequest{
res, err := l.svcCtx.AuthServiceClient.GetAccessToken(l.ctx, &auth.GetAccessTokenRequest{
AppId: in.AppId,
})
if err != nil {
@ -46,7 +46,7 @@ func (l *GetEcpmLogic) GetEcpm(in *douyin_ecpm_calculation_service.GetEcpmReques
}
//计算ECPM具体值
ecpm := CalcEcpm(list)
ecpmVal := CalcEcpm(list)
//获取后端配置的ECPM值
config, ok := l.svcCtx.EcpmConfig.Get(in.AppId)
@ -55,14 +55,14 @@ func (l *GetEcpmLogic) GetEcpm(in *douyin_ecpm_calculation_service.GetEcpmReques
}
//判断是否满足条件
if ecpm > config.Value && len(list) > config.View {
if ecpmVal > config.ECPM && len(list) > config.IPU {
response.Ok = true
}
return
}
// 计算ECPM值
// CalcEcpm 计算ECPM值
func CalcEcpm(res []Record) (ecpm float64) {
// 计算 ECPM
totalRecords := len(res)

View File

@ -2,8 +2,8 @@ package logic
import (
"context"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/svc"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/ranking_management"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ecpm_service/ecpm"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ecpm_service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
@ -22,6 +22,6 @@ func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
}
}
func (l *PingLogic) Ping(in *ranking_management.Request) (*ranking_management.Response, error) {
return &ranking_management.Response{Pong: in.Ping}, nil
func (l *PingLogic) Ping(in *ecpm.Request) (*ecpm.Response, error) {
return &ecpm.Response{Pong: in.Ping}, nil
}

View File

@ -0,0 +1,34 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.7.6
// Source: ecpm_service.proto
package server
import (
"context"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ecpm_service/ecpm"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ecpm_service/internal/logic"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ecpm_service/internal/svc"
)
type EcpmServiceServer struct {
svcCtx *svc.ServiceContext
ecpm.UnimplementedEcpmServiceServer
}
func NewEcpmServiceServer(svcCtx *svc.ServiceContext) *EcpmServiceServer {
return &EcpmServiceServer{
svcCtx: svcCtx,
}
}
func (s *EcpmServiceServer) Ping(ctx context.Context, in *ecpm.Request) (*ecpm.Response, error) {
l := logic.NewPingLogic(ctx, s.svcCtx)
return l.Ping(in)
}
func (s *EcpmServiceServer) GetEcpm(ctx context.Context, in *ecpm.GetEcpmRequest) (*ecpm.GetEcpmResponse, error) {
l := logic.NewGetEcpmLogic(ctx, s.svcCtx)
return l.GetEcpm(in)
}

View File

@ -16,9 +16,9 @@ func NewEcpmConfig() *EcpmConfigCli {
}
type Ecpm struct {
AppId string `json:"app_id"`
Value float64 `json:"value"`
View int `json:"view"`
AppId string `json:"appId"`
ECPM float64 `json:"eCPM"`
IPU int `json:"IPU"`
}
func (c *EcpmConfigCli) Get(appId string) (*Ecpm, bool) {

View File

@ -2,8 +2,9 @@ package svc
import (
"context"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/auth_service"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/douyin_ecpm_calculation_service/internal/config"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/auth_service/authservice"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/pkg/config"
"github.com/spf13/viper"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/discov"
"github.com/zeromicro/go-zero/zrpc"
@ -12,7 +13,7 @@ import (
type ServiceContext struct {
Config config.Config
AuthServiceClient auth_service.AuthServiceClient
AuthServiceClient authservice.AuthService
etcdCli *clientv3.Client
EcpmConfig *EcpmConfigCli
}
@ -31,12 +32,14 @@ func NewServiceContext(c config.Config) *ServiceContext {
return svc
}
const EcpmConfigWatchKey = "ecpm_config"
const EcpmConfigWatchKey = "/youtu/ecpm/config"
func (svc *ServiceContext) initEtcd() {
svc.EcpmConfig = NewEcpmConfig()
//初始化etcd客户端
cli, err := clientv3.NewFromURL(svc.Config.Etcd.Hosts[0])
cli, err := clientv3.NewFromURL(viper.GetString(config.EtcdAddrKey))
if err != nil {
panic(err)
}
@ -64,7 +67,6 @@ func (svc *ServiceContext) initEtcd() {
}()
svc.etcdCli = cli
svc.EcpmConfig = NewEcpmConfig()
}
// initAuthServiceClient inits the AuthServiceClient.
@ -77,9 +79,9 @@ func (svc *ServiceContext) initAuthServiceClient() {
clientConf.Token = "auth_service.rpc.key"
clientConf.App = "auth_service.rpc"
clientConf.Etcd = discov.EtcdConf{ // 通过 etcd 服务发现
Hosts: svc.Config.Etcd.Hosts,
Hosts: []string{viper.GetString(config.EtcdAddrKey)},
Key: "auth_service.rpc",
}
svc.AuthServiceClient = auth_service.NewAuthServiceClient(zrpc.MustNewClient(clientConf).Conn())
svc.AuthServiceClient = authservice.NewAuthService(zrpc.MustNewClient(clientConf))
}

View File

@ -1,82 +0,0 @@
package logic
import (
"context"
"errors"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/logic/rankings"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/svc"
ranking_management2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/ranking_management"
"gorm.io/gorm"
"strconv"
"github.com/zeromicro/go-zero/core/logx"
)
type GetRankingListLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetRankingListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRankingListLogic {
return &GetRankingListLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *GetRankingListLogic) GetRankingList(in *ranking_management2.GetRankingListRequest) (resp *ranking_management2.GetRankingListResponse, err error) {
cacheData, err := l.svcCtx.RedisRanking.GetList(l.ctx, rankings.GetRankingsCacheKey(in.AppId, in.Type), 0, 99)
if err != nil {
return nil, err
}
var flag bool
resp.RankingData = make([]*ranking_management2.RankingList, 0, len(cacheData))
var userRank *ranking_management2.RankingList
for i, datum := range cacheData {
userId, err := strconv.Atoi(datum.Member.(string))
if err != nil {
continue
}
//查询用户数据FindOne带缓存
user, err := l.svcCtx.Query.AppUser.Where(l.svcCtx.Query.AppUser.ID.Eq(uint64(userId))).Take()
if err != nil {
return nil, err
}
data := &ranking_management2.RankingList{
Nickname: user.Nickname,
Avatar: user.Avatar,
Score: uint32(uint64(datum.Score) >> 32),
Rank: uint32(i) + 1,
Self: user.ID == in.UserId,
}
if user.ID == in.UserId {
flag = true
userRank = data
}
resp.RankingData = append(resp.RankingData, data)
}
if !flag {
tmp, err := l.svcCtx.Query.GameScore.GetUserRank(in.AppId, in.UserId, in.Type)
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, err
}
userRank = &ranking_management2.RankingList{
Nickname: tmp.Nickname,
Avatar: tmp.Avatar,
Score: tmp.Score,
Rank: tmp.Rank,
Self: tmp.Self,
UserId: tmp.UserId,
}
userRank.Self = true
}
resp.RankingData = append(resp.RankingData, userRank)
return
}

View File

@ -1,39 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.7.6
// Source: ranking_management.proto
package server
import (
"context"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/logic"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/svc"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/ranking_management"
)
type RankingManagementServer struct {
svcCtx *svc.ServiceContext
ranking_management.UnimplementedRankingManagementServer
}
func NewRankingManagementServer(svcCtx *svc.ServiceContext) *RankingManagementServer {
return &RankingManagementServer{
svcCtx: svcCtx,
}
}
func (s *RankingManagementServer) Ping(ctx context.Context, in *ranking_management.Request) (*ranking_management.Response, error) {
l := logic.NewPingLogic(ctx, s.svcCtx)
return l.Ping(in)
}
func (s *RankingManagementServer) SetUserGameScore(ctx context.Context, in *ranking_management.SetUserGameScoreRequest) (*ranking_management.BaseResult, error) {
l := logic.NewSetUserGameScoreLogic(ctx, s.svcCtx)
return l.SetUserGameScore(in)
}
func (s *RankingManagementServer) GetRankingList(ctx context.Context, in *ranking_management.GetRankingListRequest) (*ranking_management.GetRankingListResponse, error) {
l := logic.NewGetRankingListLogic(ctx, s.svcCtx)
return l.GetRankingList(in)
}

View File

@ -1,70 +0,0 @@
package svc
import (
"context"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/config"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/logic/rankings"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm/gen/dao/query"
"github.com/redis/go-redis/v9"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
type ServiceContext struct {
Config config.Config
Query *query.Query
RedisRanking *rankings.Ranking
}
func NewServiceContext(c config.Config) *ServiceContext {
svc := &ServiceContext{
Config: c,
}
//初始化redis client
redisClient := redis.NewClient(&redis.Options{
Addr: c.RedisHost,
})
//初始化数据库
//todo
db, err := my_gorm.NewDBWithCache(mysql.Open(c.Mysql.Dsn), &gorm.Config{}, redisClient)
if err != nil {
panic(err)
}
svc.Query = query.Use(db)
//初始化排行榜对象
svc.InitRankings(redisClient)
return svc
}
func (svc *ServiceContext) InitRankings(redisClient *redis.Client) {
//初始化排行榜对象
svc.RedisRanking = rankings.NewRanking(redisClient)
//获取所有不同的排行榜
gs := svc.Query.GameScore
r, err := gs.FindDistinctRanking()
if err != nil {
panic(err)
}
//获取所有排行榜
for _, ranking := range r {
scores, err := gs.Where(gs.AppAccount.Eq(ranking.AppAccount), gs.T.Eq(ranking.T)).Find()
if err != nil {
panic(err)
}
data := make([]redis.Z, 0, len(scores))
for _, score := range scores {
data = append(data, redis.Z{
Score: float64(uint64(score.Score)<<32 + uint64(score.UpdatedAt.Unix())),
Member: score.AppUserID,
})
}
svc.RedisRanking.SetList(context.Background(), rankings.GetRankingsCacheKey(ranking.AppAccount, ranking.T), data...)
}
}

View File

@ -1,38 +0,0 @@
package main
import (
"flag"
"fmt"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/config"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/server"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/svc"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/ranking_management"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
var configFile = flag.String("f", "etc/ranking_management.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
ctx := svc.NewServiceContext(c)
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
ranking_management.RegisterRankingManagementServer(grpcServer, server.NewRankingManagementServer(ctx))
if c.Mode == service.DevMode || c.Mode == service.TestMode {
reflection.Register(grpcServer)
}
})
defer s.Stop()
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
s.Start()
}

View File

@ -1,548 +0,0 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.4
// protoc v3.19.4
// source: ranking_management.proto
package ranking_management
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type Request struct {
state protoimpl.MessageState `protogen:"open.v1"`
Ping string `protobuf:"bytes,1,opt,name=ping,proto3" json:"ping,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Request) Reset() {
*x = Request{}
mi := &file_ranking_management_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Request) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Request) ProtoMessage() {}
func (x *Request) ProtoReflect() protoreflect.Message {
mi := &file_ranking_management_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Request.ProtoReflect.Descriptor instead.
func (*Request) Descriptor() ([]byte, []int) {
return file_ranking_management_proto_rawDescGZIP(), []int{0}
}
func (x *Request) GetPing() string {
if x != nil {
return x.Ping
}
return ""
}
type Response struct {
state protoimpl.MessageState `protogen:"open.v1"`
Pong string `protobuf:"bytes,1,opt,name=pong,proto3" json:"pong,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Response) Reset() {
*x = Response{}
mi := &file_ranking_management_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Response) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Response) ProtoMessage() {}
func (x *Response) ProtoReflect() protoreflect.Message {
mi := &file_ranking_management_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Response.ProtoReflect.Descriptor instead.
func (*Response) Descriptor() ([]byte, []int) {
return file_ranking_management_proto_rawDescGZIP(), []int{1}
}
func (x *Response) GetPong() string {
if x != nil {
return x.Pong
}
return ""
}
// 定义SetUserGameScoreRequest消息类型
type SetUserGameScoreRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Score uint32 `protobuf:"varint,1,opt,name=score,proto3" json:"score,omitempty"` // 对应json的"score"
Type uint32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"` // 对应json的"type", 带默认值0
UserId uint64 `protobuf:"varint,3,opt,name=userId,proto3" json:"userId,omitempty"` // 用户id
AppId uint32 `protobuf:"varint,4,opt,name=appId,proto3" json:"appId,omitempty"` // 小程序id
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *SetUserGameScoreRequest) Reset() {
*x = SetUserGameScoreRequest{}
mi := &file_ranking_management_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *SetUserGameScoreRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SetUserGameScoreRequest) ProtoMessage() {}
func (x *SetUserGameScoreRequest) ProtoReflect() protoreflect.Message {
mi := &file_ranking_management_proto_msgTypes[2]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SetUserGameScoreRequest.ProtoReflect.Descriptor instead.
func (*SetUserGameScoreRequest) Descriptor() ([]byte, []int) {
return file_ranking_management_proto_rawDescGZIP(), []int{2}
}
func (x *SetUserGameScoreRequest) GetScore() uint32 {
if x != nil {
return x.Score
}
return 0
}
func (x *SetUserGameScoreRequest) GetType() uint32 {
if x != nil {
return x.Type
}
return 0
}
func (x *SetUserGameScoreRequest) GetUserId() uint64 {
if x != nil {
return x.UserId
}
return 0
}
func (x *SetUserGameScoreRequest) GetAppId() uint32 {
if x != nil {
return x.AppId
}
return 0
}
// 定义RankingData消息类型
type RankingList struct {
state protoimpl.MessageState `protogen:"open.v1"`
Nickname string `protobuf:"bytes,1,opt,name=nickname,proto3" json:"nickname,omitempty"` // 昵称对应db:"nickname"
Avatar string `protobuf:"bytes,2,opt,name=avatar,proto3" json:"avatar,omitempty"` // 头像对应db:"avatar"
Score uint32 `protobuf:"varint,3,opt,name=score,proto3" json:"score,omitempty"` // 得分对应db:"score"
UserId uint64 `protobuf:"varint,4,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` // 用户ID对应db:"app_user_id"
Rank uint32 `protobuf:"varint,5,opt,name=rank,proto3" json:"rank,omitempty"` // 排名对应db:"rank"
Self bool `protobuf:"varint,6,opt,name=self,proto3" json:"self,omitempty"` // 是否自我判断
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *RankingList) Reset() {
*x = RankingList{}
mi := &file_ranking_management_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *RankingList) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*RankingList) ProtoMessage() {}
func (x *RankingList) ProtoReflect() protoreflect.Message {
mi := &file_ranking_management_proto_msgTypes[3]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use RankingList.ProtoReflect.Descriptor instead.
func (*RankingList) Descriptor() ([]byte, []int) {
return file_ranking_management_proto_rawDescGZIP(), []int{3}
}
func (x *RankingList) GetNickname() string {
if x != nil {
return x.Nickname
}
return ""
}
func (x *RankingList) GetAvatar() string {
if x != nil {
return x.Avatar
}
return ""
}
func (x *RankingList) GetScore() uint32 {
if x != nil {
return x.Score
}
return 0
}
func (x *RankingList) GetUserId() uint64 {
if x != nil {
return x.UserId
}
return 0
}
func (x *RankingList) GetRank() uint32 {
if x != nil {
return x.Rank
}
return 0
}
func (x *RankingList) GetSelf() bool {
if x != nil {
return x.Self
}
return false
}
type GetRankingListResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
RankingData []*RankingList `protobuf:"bytes,1,rep,name=rankingData,proto3" json:"rankingData,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetRankingListResponse) Reset() {
*x = GetRankingListResponse{}
mi := &file_ranking_management_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetRankingListResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetRankingListResponse) ProtoMessage() {}
func (x *GetRankingListResponse) ProtoReflect() protoreflect.Message {
mi := &file_ranking_management_proto_msgTypes[4]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetRankingListResponse.ProtoReflect.Descriptor instead.
func (*GetRankingListResponse) Descriptor() ([]byte, []int) {
return file_ranking_management_proto_rawDescGZIP(), []int{4}
}
func (x *GetRankingListResponse) GetRankingData() []*RankingList {
if x != nil {
return x.RankingData
}
return nil
}
type GetRankingListRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
AppId uint32 `protobuf:"varint,1,opt,name=appId,proto3" json:"appId,omitempty"`
Type uint32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"`
UserId uint64 `protobuf:"varint,3,opt,name=userId,proto3" json:"userId,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetRankingListRequest) Reset() {
*x = GetRankingListRequest{}
mi := &file_ranking_management_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetRankingListRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetRankingListRequest) ProtoMessage() {}
func (x *GetRankingListRequest) ProtoReflect() protoreflect.Message {
mi := &file_ranking_management_proto_msgTypes[5]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetRankingListRequest.ProtoReflect.Descriptor instead.
func (*GetRankingListRequest) Descriptor() ([]byte, []int) {
return file_ranking_management_proto_rawDescGZIP(), []int{5}
}
func (x *GetRankingListRequest) GetAppId() uint32 {
if x != nil {
return x.AppId
}
return 0
}
func (x *GetRankingListRequest) GetType() uint32 {
if x != nil {
return x.Type
}
return 0
}
func (x *GetRankingListRequest) GetUserId() uint64 {
if x != nil {
return x.UserId
}
return 0
}
// 定义Base响应结构
type BaseResult struct {
state protoimpl.MessageState `protogen:"open.v1"`
ErrorCode int32 `protobuf:"varint,1,opt,name=error_code,json=errorCode,proto3" json:"error_code,omitempty"` // 错误码
ErrorMsg string `protobuf:"bytes,2,opt,name=error_msg,json=errorMsg,proto3" json:"error_msg,omitempty"` // 错误信息
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *BaseResult) Reset() {
*x = BaseResult{}
mi := &file_ranking_management_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *BaseResult) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*BaseResult) ProtoMessage() {}
func (x *BaseResult) ProtoReflect() protoreflect.Message {
mi := &file_ranking_management_proto_msgTypes[6]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use BaseResult.ProtoReflect.Descriptor instead.
func (*BaseResult) Descriptor() ([]byte, []int) {
return file_ranking_management_proto_rawDescGZIP(), []int{6}
}
func (x *BaseResult) GetErrorCode() int32 {
if x != nil {
return x.ErrorCode
}
return 0
}
func (x *BaseResult) GetErrorMsg() string {
if x != nil {
return x.ErrorMsg
}
return ""
}
var File_ranking_management_proto protoreflect.FileDescriptor
var file_ranking_management_proto_rawDesc = string([]byte{
0x0a, 0x18, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65,
0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x12, 0x72, 0x61, 0x6e, 0x6b,
0x69, 0x6e, 0x67, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x1d,
0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x69, 0x6e,
0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x69, 0x6e, 0x67, 0x22, 0x1e, 0x0a,
0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x6e,
0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x6f, 0x6e, 0x67, 0x22, 0x71, 0x0a,
0x17, 0x53, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72,
0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72,
0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x12,
0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x74, 0x79,
0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01,
0x28, 0x04, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70,
0x70, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64,
0x22, 0x98, 0x01, 0x0a, 0x0b, 0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74,
0x12, 0x1a, 0x0a, 0x08, 0x6e, 0x69, 0x63, 0x6b, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x08, 0x6e, 0x69, 0x63, 0x6b, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06,
0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x76,
0x61, 0x74, 0x61, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x03, 0x20,
0x01, 0x28, 0x0d, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73,
0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x75, 0x73, 0x65,
0x72, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x61, 0x6e, 0x6b, 0x18, 0x05, 0x20, 0x01, 0x28,
0x0d, 0x52, 0x04, 0x72, 0x61, 0x6e, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x65, 0x6c, 0x66, 0x18,
0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04, 0x73, 0x65, 0x6c, 0x66, 0x22, 0x5b, 0x0a, 0x16, 0x47,
0x65, 0x74, 0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x0b, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67,
0x44, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x72, 0x61, 0x6e,
0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e,
0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x0b, 0x72, 0x61, 0x6e,
0x6b, 0x69, 0x6e, 0x67, 0x44, 0x61, 0x74, 0x61, 0x22, 0x59, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x52,
0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d,
0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18,
0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x75,
0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x75, 0x73, 0x65,
0x72, 0x49, 0x64, 0x22, 0x48, 0x0a, 0x0a, 0x42, 0x61, 0x73, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c,
0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18,
0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65,
0x12, 0x1b, 0x0a, 0x09, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x08, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x4d, 0x73, 0x67, 0x32, 0xa1, 0x02,
0x0a, 0x12, 0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65,
0x6d, 0x65, 0x6e, 0x74, 0x12, 0x41, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x1b, 0x2e, 0x72,
0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e,
0x74, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x72, 0x61, 0x6e, 0x6b,
0x69, 0x6e, 0x67, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x52,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5f, 0x0a, 0x10, 0x53, 0x65, 0x74, 0x55, 0x73,
0x65, 0x72, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x2b, 0x2e, 0x72, 0x61,
0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74,
0x2e, 0x53, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72,
0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69,
0x6e, 0x67, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x42, 0x61,
0x73, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x67, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x52,
0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x29, 0x2e, 0x72, 0x61, 0x6e,
0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e,
0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f,
0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61,
0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x42, 0x16, 0x5a, 0x14, 0x2e, 0x2f, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x6d,
0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
})
var (
file_ranking_management_proto_rawDescOnce sync.Once
file_ranking_management_proto_rawDescData []byte
)
func file_ranking_management_proto_rawDescGZIP() []byte {
file_ranking_management_proto_rawDescOnce.Do(func() {
file_ranking_management_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_ranking_management_proto_rawDesc), len(file_ranking_management_proto_rawDesc)))
})
return file_ranking_management_proto_rawDescData
}
var file_ranking_management_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
var file_ranking_management_proto_goTypes = []any{
(*Request)(nil), // 0: ranking_management.Request
(*Response)(nil), // 1: ranking_management.Response
(*SetUserGameScoreRequest)(nil), // 2: ranking_management.SetUserGameScoreRequest
(*RankingList)(nil), // 3: ranking_management.RankingList
(*GetRankingListResponse)(nil), // 4: ranking_management.GetRankingListResponse
(*GetRankingListRequest)(nil), // 5: ranking_management.GetRankingListRequest
(*BaseResult)(nil), // 6: ranking_management.BaseResult
}
var file_ranking_management_proto_depIdxs = []int32{
3, // 0: ranking_management.GetRankingListResponse.rankingData:type_name -> ranking_management.RankingList
0, // 1: ranking_management.Ranking_management.Ping:input_type -> ranking_management.Request
2, // 2: ranking_management.Ranking_management.SetUserGameScore:input_type -> ranking_management.SetUserGameScoreRequest
5, // 3: ranking_management.Ranking_management.GetRankingList:input_type -> ranking_management.GetRankingListRequest
1, // 4: ranking_management.Ranking_management.Ping:output_type -> ranking_management.Response
6, // 5: ranking_management.Ranking_management.SetUserGameScore:output_type -> ranking_management.BaseResult
4, // 6: ranking_management.Ranking_management.GetRankingList:output_type -> ranking_management.GetRankingListResponse
4, // [4:7] is the sub-list for method output_type
1, // [1:4] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_ranking_management_proto_init() }
func file_ranking_management_proto_init() {
if File_ranking_management_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_ranking_management_proto_rawDesc), len(file_ranking_management_proto_rawDesc)),
NumEnums: 0,
NumMessages: 7,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_ranking_management_proto_goTypes,
DependencyIndexes: file_ranking_management_proto_depIdxs,
MessageInfos: file_ranking_management_proto_msgTypes,
}.Build()
File_ranking_management_proto = out.File
file_ranking_management_proto_goTypes = nil
file_ranking_management_proto_depIdxs = nil
}

View File

@ -1,197 +0,0 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc v3.19.4
// source: ranking_management.proto
package ranking_management
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
RankingManagement_Ping_FullMethodName = "/ranking_management.Ranking_management/Ping"
RankingManagement_SetUserGameScore_FullMethodName = "/ranking_management.Ranking_management/SetUserGameScore"
RankingManagement_GetRankingList_FullMethodName = "/ranking_management.Ranking_management/GetRankingList"
)
// RankingManagementClient is the client API for RankingManagement service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type RankingManagementClient interface {
Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
SetUserGameScore(ctx context.Context, in *SetUserGameScoreRequest, opts ...grpc.CallOption) (*BaseResult, error)
GetRankingList(ctx context.Context, in *GetRankingListRequest, opts ...grpc.CallOption) (*GetRankingListResponse, error)
}
type rankingManagementClient struct {
cc grpc.ClientConnInterface
}
func NewRankingManagementClient(cc grpc.ClientConnInterface) RankingManagementClient {
return &rankingManagementClient{cc}
}
func (c *rankingManagementClient) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Response)
err := c.cc.Invoke(ctx, RankingManagement_Ping_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *rankingManagementClient) SetUserGameScore(ctx context.Context, in *SetUserGameScoreRequest, opts ...grpc.CallOption) (*BaseResult, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(BaseResult)
err := c.cc.Invoke(ctx, RankingManagement_SetUserGameScore_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *rankingManagementClient) GetRankingList(ctx context.Context, in *GetRankingListRequest, opts ...grpc.CallOption) (*GetRankingListResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetRankingListResponse)
err := c.cc.Invoke(ctx, RankingManagement_GetRankingList_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// RankingManagementServer is the server API for RankingManagement service.
// All implementations must embed UnimplementedRankingManagementServer
// for forward compatibility.
type RankingManagementServer interface {
Ping(context.Context, *Request) (*Response, error)
SetUserGameScore(context.Context, *SetUserGameScoreRequest) (*BaseResult, error)
GetRankingList(context.Context, *GetRankingListRequest) (*GetRankingListResponse, error)
mustEmbedUnimplementedRankingManagementServer()
}
// UnimplementedRankingManagementServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedRankingManagementServer struct{}
func (UnimplementedRankingManagementServer) Ping(context.Context, *Request) (*Response, error) {
return nil, status.Errorf(codes.Unimplemented, "method Ping not implemented")
}
func (UnimplementedRankingManagementServer) SetUserGameScore(context.Context, *SetUserGameScoreRequest) (*BaseResult, error) {
return nil, status.Errorf(codes.Unimplemented, "method SetUserGameScore not implemented")
}
func (UnimplementedRankingManagementServer) GetRankingList(context.Context, *GetRankingListRequest) (*GetRankingListResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetRankingList not implemented")
}
func (UnimplementedRankingManagementServer) mustEmbedUnimplementedRankingManagementServer() {}
func (UnimplementedRankingManagementServer) testEmbeddedByValue() {}
// UnsafeRankingManagementServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to RankingManagementServer will
// result in compilation errors.
type UnsafeRankingManagementServer interface {
mustEmbedUnimplementedRankingManagementServer()
}
func RegisterRankingManagementServer(s grpc.ServiceRegistrar, srv RankingManagementServer) {
// If the following call pancis, it indicates UnimplementedRankingManagementServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&RankingManagement_ServiceDesc, srv)
}
func _RankingManagement_Ping_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Request)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RankingManagementServer).Ping(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: RankingManagement_Ping_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RankingManagementServer).Ping(ctx, req.(*Request))
}
return interceptor(ctx, in, info, handler)
}
func _RankingManagement_SetUserGameScore_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SetUserGameScoreRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RankingManagementServer).SetUserGameScore(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: RankingManagement_SetUserGameScore_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RankingManagementServer).SetUserGameScore(ctx, req.(*SetUserGameScoreRequest))
}
return interceptor(ctx, in, info, handler)
}
func _RankingManagement_GetRankingList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetRankingListRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RankingManagementServer).GetRankingList(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: RankingManagement_GetRankingList_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RankingManagementServer).GetRankingList(ctx, req.(*GetRankingListRequest))
}
return interceptor(ctx, in, info, handler)
}
// RankingManagement_ServiceDesc is the grpc.ServiceDesc for RankingManagement service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var RankingManagement_ServiceDesc = grpc.ServiceDesc{
ServiceName: "ranking_management.Ranking_management",
HandlerType: (*RankingManagementServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Ping",
Handler: _RankingManagement_Ping_Handler,
},
{
MethodName: "SetUserGameScore",
Handler: _RankingManagement_SetUserGameScore_Handler,
},
{
MethodName: "GetRankingList",
Handler: _RankingManagement_GetRankingList_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "ranking_management.proto",
}

View File

@ -1,55 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.7.6
// Source: ranking_management.proto
package ranking_management_client
import (
"context"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/ranking_management"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
)
type (
BaseResult = ranking_management.BaseResult
GetRankingListRequest = ranking_management.GetRankingListRequest
GetRankingListResponse = ranking_management.GetRankingListResponse
RankingList = ranking_management.RankingList
Request = ranking_management.Request
Response = ranking_management.Response
SetUserGameScoreRequest = ranking_management.SetUserGameScoreRequest
RankingManagement interface {
Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
SetUserGameScore(ctx context.Context, in *SetUserGameScoreRequest, opts ...grpc.CallOption) (*BaseResult, error)
GetRankingList(ctx context.Context, in *GetRankingListRequest, opts ...grpc.CallOption) (*GetRankingListResponse, error)
}
defaultRankingManagement struct {
cli zrpc.Client
}
)
func NewRankingManagement(cli zrpc.Client) RankingManagement {
return &defaultRankingManagement{
cli: cli,
}
}
func (m *defaultRankingManagement) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
client := ranking_management.NewRankingManagementClient(m.cli.Conn())
return client.Ping(ctx, in, opts...)
}
func (m *defaultRankingManagement) SetUserGameScore(ctx context.Context, in *SetUserGameScoreRequest, opts ...grpc.CallOption) (*BaseResult, error) {
client := ranking_management.NewRankingManagementClient(m.cli.Conn())
return client.SetUserGameScore(ctx, in, opts...)
}
func (m *defaultRankingManagement) GetRankingList(ctx context.Context, in *GetRankingListRequest, opts ...grpc.CallOption) (*GetRankingListResponse, error) {
client := ranking_management.NewRankingManagementClient(m.cli.Conn())
return client.GetRankingList(ctx, in, opts...)
}

View File

@ -0,0 +1,33 @@
FROM golang:alpine AS builder
LABEL stage=gobuilder
ENV CGO_ENABLED=0
ENV GOPROXY=https://goproxy.cn,direct
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk update --no-cache && apk add --no-cache tzdata
RUN apk add --no-cache git
WORKDIR /build
ADD go.mod .
ADD go.sum .
RUN go env -w GOPRIVATE=gitea.youtukeji.com.cn
RUN go mod download
COPY . .
RUN go build -ldflags="-s -w" -o /app/ranking ./app/ranking_service/ranking_service.go
FROM alpine
COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai
ENV TZ=Asia/Shanghai
WORKDIR /app
COPY --from=builder /app/ranking /app/ranking
EXPOSE 8888
CMD ["/app/ranking"]

View File

@ -1,9 +1,9 @@
Name: ranking_management.rpc
Name: ranking.rpc
ListenOn: 0.0.0.0:8080
Etcd:
Hosts:
- 127.0.0.1:2379
Key: ranking_management.rpc
Key: ranking.rpc
RedisHost: 127.0.0.1:6379
Mysql:
Dsn: root:youtu!0113@tcp(localhost:3306)/ecpm?charset=utf8mb4&parseTime=True&loc=Local

View File

@ -13,11 +13,11 @@ const TableNameGameScore = "game_score"
// GameScore mapped from table <game_score>
type GameScore struct {
ID uint64 `gorm:"column:id;type:bigint unsigned;primaryKey;autoIncrement:true" json:"id"`
AppAccount uint32 `gorm:"column:app_account;type:int unsigned;not null;uniqueIndex:rank_list,priority:1;comment:小游戏id" json:"app_account"` // 小游戏id
AppUserID uint64 `gorm:"column:app_user_id;type:bigint unsigned;not null;uniqueIndex:rank_list,priority:3;index:user_id,priority:1;comment:用户id" json:"app_user_id"` // 用户id
Score uint32 `gorm:"column:score;type:int unsigned;not null;comment:得分" json:"score"` // 得分
T uint32 `gorm:"column:t;type:tinyint unsigned;not null;uniqueIndex:rank_list,priority:2;comment:得分类型(区分相同小游戏中的不同模式得分)" json:"t"` // 得分类型(区分相同小游戏中的不同模式得分)
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;not null;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间
AppAccount uint32 `gorm:"column:app_account;type:int unsigned;not null;uniqueIndex:rank_list,priority:1;comment:小游戏id" json:"app_account"` // 小游戏id
UserID uint64 `gorm:"column:user_id;type:bigint unsigned;not null;uniqueIndex:rank_list,priority:3;index:user_id,priority:1;comment:用户id" json:"user_id"` // 用户id
Score uint32 `gorm:"column:score;type:int unsigned;not null;comment:得分" json:"score"` // 得分
T uint32 `gorm:"column:t;type:tinyint unsigned;not null;uniqueIndex:rank_list,priority:2;comment:得分类型(区分相同小游戏中的不同模式得分)" json:"t"` // 得分类型(区分相同小游戏中的不同模式得分)
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;not null;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间
}
// TableName GameScore's table name

View File

@ -6,7 +6,6 @@ package query
import (
"context"
"strings"
"gorm.io/gorm"
"gorm.io/gorm/clause"
@ -17,8 +16,7 @@ import (
"gorm.io/plugin/dbresolver"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm/gen/dao/model"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm/gen/querier"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/gen/dao/model"
)
func newGameScore(db *gorm.DB, opts ...gen.DOOption) gameScore {
@ -31,7 +29,7 @@ func newGameScore(db *gorm.DB, opts ...gen.DOOption) gameScore {
_gameScore.ALL = field.NewAsterisk(tableName)
_gameScore.ID = field.NewUint64(tableName, "id")
_gameScore.AppAccount = field.NewUint32(tableName, "app_account")
_gameScore.AppUserID = field.NewUint64(tableName, "app_user_id")
_gameScore.UserID = field.NewUint64(tableName, "user_id")
_gameScore.Score = field.NewUint32(tableName, "score")
_gameScore.T = field.NewUint32(tableName, "t")
_gameScore.UpdatedAt = field.NewTime(tableName, "updated_at")
@ -42,15 +40,15 @@ func newGameScore(db *gorm.DB, opts ...gen.DOOption) gameScore {
}
type gameScore struct {
gameScoreDo
gameScoreDo gameScoreDo
ALL field.Asterisk
ID field.Uint64
AppAccount field.Uint32
AppUserID field.Uint64
Score field.Uint32
T field.Uint32
UpdatedAt field.Time
AppAccount field.Uint32 // 小游戏id
UserID field.Uint64 // 用户id
Score field.Uint32 // 得分
T field.Uint32 // 得分类型(区分相同小游戏中的不同模式得分)
UpdatedAt field.Time // 更新时间
fieldMap map[string]field.Expr
}
@ -69,7 +67,7 @@ func (g *gameScore) updateTableName(table string) *gameScore {
g.ALL = field.NewAsterisk(table)
g.ID = field.NewUint64(table, "id")
g.AppAccount = field.NewUint32(table, "app_account")
g.AppUserID = field.NewUint64(table, "app_user_id")
g.UserID = field.NewUint64(table, "user_id")
g.Score = field.NewUint32(table, "score")
g.T = field.NewUint32(table, "t")
g.UpdatedAt = field.NewTime(table, "updated_at")
@ -79,6 +77,16 @@ func (g *gameScore) updateTableName(table string) *gameScore {
return g
}
func (g *gameScore) WithContext(ctx context.Context) *gameScoreDo {
return g.gameScoreDo.WithContext(ctx)
}
func (g gameScore) TableName() string { return g.gameScoreDo.TableName() }
func (g gameScore) Alias() string { return g.gameScoreDo.Alias() }
func (g gameScore) Columns(cols ...field.Expr) gen.Columns { return g.gameScoreDo.Columns(cols...) }
func (g *gameScore) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := g.fieldMap[fieldName]
if !ok || _f == nil {
@ -92,7 +100,7 @@ func (g *gameScore) fillFieldMap() {
g.fieldMap = make(map[string]field.Expr, 6)
g.fieldMap["id"] = g.ID
g.fieldMap["app_account"] = g.AppAccount
g.fieldMap["app_user_id"] = g.AppUserID
g.fieldMap["user_id"] = g.UserID
g.fieldMap["score"] = g.Score
g.fieldMap["t"] = g.T
g.fieldMap["updated_at"] = g.UpdatedAt
@ -110,211 +118,95 @@ func (g gameScore) replaceDB(db *gorm.DB) gameScore {
type gameScoreDo struct{ gen.DO }
type IGameScoreDo interface {
gen.SubQuery
Debug() IGameScoreDo
WithContext(ctx context.Context) IGameScoreDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IGameScoreDo
WriteDB() IGameScoreDo
As(alias string) gen.Dao
Session(config *gorm.Session) IGameScoreDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IGameScoreDo
Not(conds ...gen.Condition) IGameScoreDo
Or(conds ...gen.Condition) IGameScoreDo
Select(conds ...field.Expr) IGameScoreDo
Where(conds ...gen.Condition) IGameScoreDo
Order(conds ...field.Expr) IGameScoreDo
Distinct(cols ...field.Expr) IGameScoreDo
Omit(cols ...field.Expr) IGameScoreDo
Join(table schema.Tabler, on ...field.Expr) IGameScoreDo
LeftJoin(table schema.Tabler, on ...field.Expr) IGameScoreDo
RightJoin(table schema.Tabler, on ...field.Expr) IGameScoreDo
Group(cols ...field.Expr) IGameScoreDo
Having(conds ...gen.Condition) IGameScoreDo
Limit(limit int) IGameScoreDo
Offset(offset int) IGameScoreDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IGameScoreDo
Unscoped() IGameScoreDo
Create(values ...*model.GameScore) error
CreateInBatches(values []*model.GameScore, batchSize int) error
Save(values ...*model.GameScore) error
First() (*model.GameScore, error)
Take() (*model.GameScore, error)
Last() (*model.GameScore, error)
Find() ([]*model.GameScore, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.GameScore, err error)
FindInBatches(result *[]*model.GameScore, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*model.GameScore) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) IGameScoreDo
Assign(attrs ...field.AssignExpr) IGameScoreDo
Joins(fields ...field.RelationField) IGameScoreDo
Preload(fields ...field.RelationField) IGameScoreDo
FirstOrInit() (*model.GameScore, error)
FirstOrCreate() (*model.GameScore, error)
FindByPage(offset int, limit int) (result []*model.GameScore, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) IGameScoreDo
UnderlyingDB() *gorm.DB
schema.Tabler
GetUserRank(appId uint32, userId uint64, t uint32) (result querier.RankingData, err error)
FindDistinctRanking() (result []*model.GameScore, err error)
}
// SELECT
//
// app_user.nickname,
// app_user.avatar,
// gs.score,
// gs.app_user_id,
// gs.t_rank
// FROM
// (
// SELECT
// game_score.score,
// game_score.app_user_id,
// game_score.app_account,
// rank() OVER (ORDER BY game_score.score DESC) t_rank
// FROM
// game_score
// WHERE
// game_score.t = @t
// AND game_score.app_account = @appId
// ) AS gs
// LEFT JOIN app_user ON app_user.id = gs.app_user_id
// WHERE
// gs.app_user_id = @userId
// LIMIT 1;
func (g gameScoreDo) GetUserRank(appId uint32, userId uint64, t uint32) (result querier.RankingData, err error) {
var params []interface{}
var generateSQL strings.Builder
params = append(params, t)
params = append(params, appId)
params = append(params, userId)
generateSQL.WriteString("SELECT app_user.nickname, app_user.avatar, gs.score, gs.app_user_id, gs.t_rank FROM ( SELECT game_score.score, game_score.app_user_id, game_score.app_account, rank() OVER (ORDER BY game_score.score DESC) t_rank FROM game_score WHERE game_score.t = ? AND game_score.app_account = ? ) AS gs LEFT JOIN app_user ON app_user.id = gs.app_user_id WHERE gs.app_user_id = ? LIMIT 1; ")
var executeSQL *gorm.DB
executeSQL = g.UnderlyingDB().Raw(generateSQL.String(), params...).Take(&result) // ignore_security_alert
err = executeSQL.Error
return
}
// select DISTINCT app_account,t from game_score
func (g gameScoreDo) FindDistinctRanking() (result []*model.GameScore, err error) {
var generateSQL strings.Builder
generateSQL.WriteString("select DISTINCT app_account,t from game_score ")
var executeSQL *gorm.DB
executeSQL = g.UnderlyingDB().Raw(generateSQL.String()).Find(&result) // ignore_security_alert
err = executeSQL.Error
return
}
func (g gameScoreDo) Debug() IGameScoreDo {
func (g gameScoreDo) Debug() *gameScoreDo {
return g.withDO(g.DO.Debug())
}
func (g gameScoreDo) WithContext(ctx context.Context) IGameScoreDo {
func (g gameScoreDo) WithContext(ctx context.Context) *gameScoreDo {
return g.withDO(g.DO.WithContext(ctx))
}
func (g gameScoreDo) ReadDB() IGameScoreDo {
func (g gameScoreDo) ReadDB() *gameScoreDo {
return g.Clauses(dbresolver.Read)
}
func (g gameScoreDo) WriteDB() IGameScoreDo {
func (g gameScoreDo) WriteDB() *gameScoreDo {
return g.Clauses(dbresolver.Write)
}
func (g gameScoreDo) Session(config *gorm.Session) IGameScoreDo {
func (g gameScoreDo) Session(config *gorm.Session) *gameScoreDo {
return g.withDO(g.DO.Session(config))
}
func (g gameScoreDo) Clauses(conds ...clause.Expression) IGameScoreDo {
func (g gameScoreDo) Clauses(conds ...clause.Expression) *gameScoreDo {
return g.withDO(g.DO.Clauses(conds...))
}
func (g gameScoreDo) Returning(value interface{}, columns ...string) IGameScoreDo {
func (g gameScoreDo) Returning(value interface{}, columns ...string) *gameScoreDo {
return g.withDO(g.DO.Returning(value, columns...))
}
func (g gameScoreDo) Not(conds ...gen.Condition) IGameScoreDo {
func (g gameScoreDo) Not(conds ...gen.Condition) *gameScoreDo {
return g.withDO(g.DO.Not(conds...))
}
func (g gameScoreDo) Or(conds ...gen.Condition) IGameScoreDo {
func (g gameScoreDo) Or(conds ...gen.Condition) *gameScoreDo {
return g.withDO(g.DO.Or(conds...))
}
func (g gameScoreDo) Select(conds ...field.Expr) IGameScoreDo {
func (g gameScoreDo) Select(conds ...field.Expr) *gameScoreDo {
return g.withDO(g.DO.Select(conds...))
}
func (g gameScoreDo) Where(conds ...gen.Condition) IGameScoreDo {
func (g gameScoreDo) Where(conds ...gen.Condition) *gameScoreDo {
return g.withDO(g.DO.Where(conds...))
}
func (g gameScoreDo) Order(conds ...field.Expr) IGameScoreDo {
func (g gameScoreDo) Order(conds ...field.Expr) *gameScoreDo {
return g.withDO(g.DO.Order(conds...))
}
func (g gameScoreDo) Distinct(cols ...field.Expr) IGameScoreDo {
func (g gameScoreDo) Distinct(cols ...field.Expr) *gameScoreDo {
return g.withDO(g.DO.Distinct(cols...))
}
func (g gameScoreDo) Omit(cols ...field.Expr) IGameScoreDo {
func (g gameScoreDo) Omit(cols ...field.Expr) *gameScoreDo {
return g.withDO(g.DO.Omit(cols...))
}
func (g gameScoreDo) Join(table schema.Tabler, on ...field.Expr) IGameScoreDo {
func (g gameScoreDo) Join(table schema.Tabler, on ...field.Expr) *gameScoreDo {
return g.withDO(g.DO.Join(table, on...))
}
func (g gameScoreDo) LeftJoin(table schema.Tabler, on ...field.Expr) IGameScoreDo {
func (g gameScoreDo) LeftJoin(table schema.Tabler, on ...field.Expr) *gameScoreDo {
return g.withDO(g.DO.LeftJoin(table, on...))
}
func (g gameScoreDo) RightJoin(table schema.Tabler, on ...field.Expr) IGameScoreDo {
func (g gameScoreDo) RightJoin(table schema.Tabler, on ...field.Expr) *gameScoreDo {
return g.withDO(g.DO.RightJoin(table, on...))
}
func (g gameScoreDo) Group(cols ...field.Expr) IGameScoreDo {
func (g gameScoreDo) Group(cols ...field.Expr) *gameScoreDo {
return g.withDO(g.DO.Group(cols...))
}
func (g gameScoreDo) Having(conds ...gen.Condition) IGameScoreDo {
func (g gameScoreDo) Having(conds ...gen.Condition) *gameScoreDo {
return g.withDO(g.DO.Having(conds...))
}
func (g gameScoreDo) Limit(limit int) IGameScoreDo {
func (g gameScoreDo) Limit(limit int) *gameScoreDo {
return g.withDO(g.DO.Limit(limit))
}
func (g gameScoreDo) Offset(offset int) IGameScoreDo {
func (g gameScoreDo) Offset(offset int) *gameScoreDo {
return g.withDO(g.DO.Offset(offset))
}
func (g gameScoreDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IGameScoreDo {
func (g gameScoreDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *gameScoreDo {
return g.withDO(g.DO.Scopes(funcs...))
}
func (g gameScoreDo) Unscoped() IGameScoreDo {
func (g gameScoreDo) Unscoped() *gameScoreDo {
return g.withDO(g.DO.Unscoped())
}
@ -380,22 +272,22 @@ func (g gameScoreDo) FindInBatches(result *[]*model.GameScore, batchSize int, fc
return g.DO.FindInBatches(result, batchSize, fc)
}
func (g gameScoreDo) Attrs(attrs ...field.AssignExpr) IGameScoreDo {
func (g gameScoreDo) Attrs(attrs ...field.AssignExpr) *gameScoreDo {
return g.withDO(g.DO.Attrs(attrs...))
}
func (g gameScoreDo) Assign(attrs ...field.AssignExpr) IGameScoreDo {
func (g gameScoreDo) Assign(attrs ...field.AssignExpr) *gameScoreDo {
return g.withDO(g.DO.Assign(attrs...))
}
func (g gameScoreDo) Joins(fields ...field.RelationField) IGameScoreDo {
func (g gameScoreDo) Joins(fields ...field.RelationField) *gameScoreDo {
for _, _f := range fields {
g = *g.withDO(g.DO.Joins(_f))
}
return &g
}
func (g gameScoreDo) Preload(fields ...field.RelationField) IGameScoreDo {
func (g gameScoreDo) Preload(fields ...field.RelationField) *gameScoreDo {
for _, _f := range fields {
g = *g.withDO(g.DO.Preload(_f))
}

View File

@ -9,7 +9,7 @@ import (
"fmt"
"testing"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm/gen/dao/model"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/gen/dao/model"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm/clause"

View File

@ -0,0 +1,93 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"database/sql"
"gorm.io/gorm"
"gorm.io/gen"
"gorm.io/plugin/dbresolver"
)
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
GameScore: newGameScore(db, opts...),
}
}
type Query struct {
db *gorm.DB
GameScore gameScore
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
GameScore: q.GameScore.clone(db),
}
}
func (q *Query) ReadDB() *Query {
return q.ReplaceDB(q.db.Clauses(dbresolver.Read))
}
func (q *Query) WriteDB() *Query {
return q.ReplaceDB(q.db.Clauses(dbresolver.Write))
}
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
return &Query{
db: db,
GameScore: q.GameScore.replaceDB(db),
}
}
type queryCtx struct {
GameScore *gameScoreDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
GameScore: q.GameScore.WithContext(ctx),
}
}
func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error {
return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...)
}
func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx {
tx := q.db.Begin(opts...)
return &QueryTx{Query: q.clone(tx), Error: tx.Error}
}
type QueryTx struct {
*Query
Error error
}
func (q *QueryTx) Commit() error {
return q.db.Commit().Error
}
func (q *QueryTx) Rollback() error {
return q.db.Rollback().Error
}
func (q *QueryTx) SavePoint(name string) error {
return q.db.SavePoint(name).Error
}
func (q *QueryTx) RollbackTo(name string) error {
return q.db.RollbackTo(name).Error
}

View File

@ -0,0 +1,118 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"fmt"
"reflect"
"sync"
"testing"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
type Input struct {
Args []interface{}
}
type Expectation struct {
Ret []interface{}
}
type TestCase struct {
Input
Expectation
}
const _gen_test_db_name = "gen_test.db"
var _gen_test_db *gorm.DB
var _gen_test_once sync.Once
func init() {
InitializeDB()
_gen_test_db.AutoMigrate(&_another{})
}
func InitializeDB() {
_gen_test_once.Do(func() {
var err error
_gen_test_db, err = gorm.Open(sqlite.Open(_gen_test_db_name), &gorm.Config{})
if err != nil {
panic(fmt.Errorf("open sqlite %q fail: %w", _gen_test_db_name, err))
}
})
}
func assert(t *testing.T, methodName string, res, exp interface{}) {
if !reflect.DeepEqual(res, exp) {
t.Errorf("%v() gotResult = %v, want %v", methodName, res, exp)
}
}
type _another struct {
ID uint64 `gorm:"primaryKey"`
}
func (*_another) TableName() string { return "another_for_unit_test" }
func Test_Available(t *testing.T) {
if !Use(_gen_test_db).Available() {
t.Errorf("query.Available() == false")
}
}
func Test_WithContext(t *testing.T) {
query := Use(_gen_test_db)
if !query.Available() {
t.Errorf("query Use(_gen_test_db) fail: query.Available() == false")
}
type Content string
var key, value Content = "gen_tag", "unit_test"
qCtx := query.WithContext(context.WithValue(context.Background(), key, value))
for _, ctx := range []context.Context{
qCtx.GameScore.UnderlyingDB().Statement.Context,
} {
if v := ctx.Value(key); v != value {
t.Errorf("get value from context fail, expect %q, got %q", value, v)
}
}
}
func Test_Transaction(t *testing.T) {
query := Use(_gen_test_db)
if !query.Available() {
t.Errorf("query Use(_gen_test_db) fail: query.Available() == false")
}
err := query.Transaction(func(tx *Query) error { return nil })
if err != nil {
t.Errorf("query.Transaction execute fail: %s", err)
}
tx := query.Begin()
err = tx.SavePoint("point")
if err != nil {
t.Errorf("query tx SavePoint fail: %s", err)
}
err = tx.RollbackTo("point")
if err != nil {
t.Errorf("query tx RollbackTo fail: %s", err)
}
err = tx.Commit()
if err != nil {
t.Errorf("query tx Commit fail: %s", err)
}
err = query.Begin().Rollback()
if err != nil {
t.Errorf("query tx Rollback fail: %s", err)
}
}

View File

@ -0,0 +1,14 @@
version: "0.1"
database:
dsn : "root:youtu!0113@tcp(192.168.0.47:3306)/ecpm?charset=utf8mb4&parseTime=True&loc=Local"
db : "mysql"
tables :
- "game_score"
outPath : "./dao/query"
outFile : ""
withUnitTest : true
modelPkgName : "model"
fieldNullable : true
fieldWithIndexTag : true
fieldWithTypeTag : true
fieldSignable : true

View File

@ -0,0 +1,89 @@
package logic
import (
"context"
"errors"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/gen/dao/model"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/logic/rankings"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/ranking"
"github.com/redis/go-redis/v9"
"strconv"
"time"
"github.com/zeromicro/go-zero/core/logx"
)
type AddUserGameScoreLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAddUserGameScoreLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddUserGameScoreLogic {
return &AddUserGameScoreLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *AddUserGameScoreLogic) AddUserGameScore(in *ranking.AddUserGameScoreRequest) (*ranking.BaseResult, error) {
cacheKey := rankings.GetRankingsCacheKey(in.AppId, in.Type)
//todo 需要寻找新的方案
fScore, err := l.svcCtx.RedisRanking.GetScore(l.ctx, cacheKey, strconv.Itoa(int(in.UserId)))
if err != nil && !errors.Is(err, redis.Nil) {
return nil, err
}
//转为uint64
score := uint32(uint64(fScore) >> 32)
score += in.Score
gs := l.svcCtx.Query.GameScore
if errors.Is(err, redis.Nil) {
err = gs.WithContext(l.ctx).Create(&model.GameScore{
AppAccount: in.AppId,
UserID: in.UserId,
T: in.Type,
Score: score, // 初始值会被 ON CONFLICT 中的表达式覆盖
})
} else {
_, err = gs.WithContext(l.ctx).Where(
gs.AppAccount.Eq(in.AppId),
gs.T.Eq(in.Type),
gs.UserID.Eq(in.UserId),
).Update(gs.Score, score)
}
if err != nil {
return nil, err
}
l.svcCtx.RedisRanking.SetList(l.ctx, cacheKey, redis.Z{
Score: float64(uint64(score)<<32 + uint64(time.Now().Unix())),
Member: in.UserId,
})
//err = l.svcCtx.Query.Transaction(func(tx *query.Query) error {
// gs := tx.GameScore
//
// // 使用冲突处理子句
// return gs.WithContext(l.ctx).Clauses(clause.OnConflict{
// Columns: []clause.Column{
// {Name: "app_account"}, // 确保这些字段有唯一约束
// {Name: "user_id"},
// {Name: "t"},
// },
// DoUpdates: clause.Assignments(map[string]interface{}{
// "score": gorm.Expr("game_score.score + ?", in.Score),
// }),
// }).Create(&model.GameScore{
// AppAccount: in.AppId,
// UserID: in.UserId,
// T: in.Type,
// Score: in.Score, // 初始值会被 ON CONFLICT 中的表达式覆盖
// })
//})
return &ranking.BaseResult{}, nil
}

View File

@ -0,0 +1,45 @@
package logic
import (
"context"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/logic/rankings"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/ranking"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/user"
"github.com/zeromicro/go-zero/core/logx"
)
type AtomicGetHigherUserLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAtomicGetHigherUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AtomicGetHigherUserLogic {
return &AtomicGetHigherUserLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *AtomicGetHigherUserLogic) AtomicGetHigherUser(in *ranking.AtomicGetHigherUserRequest) (*ranking.RankingList, error) {
cacheKey := rankings.GetRankingsCacheKey(in.AppId, in.Type)
userId, score, err := l.svcCtx.RedisRanking.AtomicGetHigherUser(l.ctx, cacheKey, float64(in.Score))
if err != nil {
return nil, err
}
//查询用户数据FindOne带缓存
userModel, err := l.svcCtx.UserServiceClient.GetUserById(l.ctx, &user.UserId{UserId: userId})
if err != nil {
return nil, err
}
return &ranking.RankingList{
Nickname: userModel.Nickname,
Avatar: userModel.Avatar,
Score: score,
}, nil
}

View File

@ -0,0 +1,105 @@
package logic
import (
"context"
"errors"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/logic/rankings"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/ranking"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/user"
"github.com/redis/go-redis/v9"
"gorm.io/gorm"
"strconv"
"github.com/zeromicro/go-zero/core/logx"
)
type GetRankingListLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetRankingListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRankingListLogic {
return &GetRankingListLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *GetRankingListLogic) GetRankingList(in *ranking.GetRankingListRequest) (resp *ranking.GetRankingListResponse, err error) {
resp = new(ranking.GetRankingListResponse)
cacheKey := rankings.GetRankingsCacheKey(in.AppId, in.Type)
cacheData, err := l.svcCtx.RedisRanking.GetList(l.ctx, cacheKey, 0, 98)
if err != nil {
return nil, err
}
var flag bool
resp.RankingData = make([]*ranking.RankingList, 0, len(cacheData))
var userRank *ranking.RankingList
userIds := make([]uint64, 0, len(cacheData))
for _, datum := range cacheData {
userId, err := strconv.ParseUint(datum.Member.(string), 10, 64)
if err != nil {
continue
}
userIds = append(userIds, userId)
}
res, err := l.svcCtx.UserServiceClient.GetUserIds(l.ctx, &user.UserIds{UserId: userIds})
if err != nil {
return nil, err
}
for i, datum := range res.UserList {
data := &ranking.RankingList{
Nickname: datum.Nickname,
Avatar: datum.Avatar,
Score: uint32(uint64(cacheData[i].Score) >> 32),
Rank: uint32(i) + 1,
Self: datum.ID == in.UserId,
}
if datum.ID == in.UserId {
flag = true
userRank = data
}
resp.RankingData = append(resp.RankingData, data)
}
if !flag {
rank, err := l.svcCtx.RedisRanking.GetRank(l.ctx, cacheKey, strconv.FormatUint(in.UserId, 10))
if err != nil {
//如果没有找到,则创建一个空的数据
if errors.Is(err, redis.Nil) {
resp.RankingData = append(resp.RankingData, &ranking.RankingList{Self: true})
return resp, nil
}
return nil, err
}
score, err := l.svcCtx.RedisRanking.GetScore(l.ctx, cacheKey, strconv.FormatUint(in.UserId, 10))
if err != nil {
return nil, err
}
tmp, err := l.svcCtx.UserServiceClient.GetUserById(l.ctx, &user.UserId{UserId: in.UserId})
//tmp, err := l.svcCtx.Query.GameScore.GetUserRank(in.AppId, in.UserId, in.Type)
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, err
}
userRank = &ranking.RankingList{
Nickname: tmp.Nickname,
Avatar: tmp.Avatar,
Score: uint32(score),
Rank: uint32(rank),
Self: true,
UserId: in.UserId,
}
}
resp.RankingData = append(resp.RankingData, userRank)
return
}

View File

@ -0,0 +1,27 @@
package logic
import (
"context"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/ranking"
"github.com/zeromicro/go-zero/core/logx"
)
type PingLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
return &PingLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *PingLogic) Ping(in *ranking.Request) (*ranking.Response, error) {
return &ranking.Response{Pong: in.Ping}, nil
}

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"github.com/redis/go-redis/v9"
"strconv"
)
// Ranking 排行榜结构体
@ -43,3 +44,45 @@ func (r *Ranking) GetRank(ctx context.Context, key, member string) (rank int64,
func (r *Ranking) GetScore(ctx context.Context, key, member string) (score float64, err error) {
return r.c.ZScore(ctx, key, member).Result()
}
// IncrScore 增加分数
func (r *Ranking) IncrScore(ctx context.Context, key, member string, increment float64) (score float64, err error) {
return r.c.ZIncrBy(ctx, key, increment, member).Result()
}
// Remove 删除排行榜
func (r *Ranking) Remove(ctx context.Context, key string) (err error) {
return r.c.Del(ctx, key).Err()
}
// 使用 Lua 保证原子性操作
var getHigherByScoreScript = redis.NewScript(`
local members = redis.call('ZRANGEBYSCORE', KEYS[1], ARGV[1],'+inf','LIMIT', 0, 1, 'WITHSCORES')
if #members == 0 then return nil end
return members
`)
// AtomicGetHigherUser 获取排行榜的前一名
func (r *Ranking) AtomicGetHigherUser(ctx context.Context, key string, score float64) (userId uint64, scoreRes uint32, err error) {
s, err := getHigherByScoreScript.Run(ctx, r.c, []string{key}, score).Slice()
if err != nil {
return
}
if s == nil {
return
}
if len(s) != 2 {
return 0, 0, fmt.Errorf("redis type error len(s) !=2")
}
userId, err = strconv.ParseUint(s[0].(string), 10, 64)
if err != nil {
return
}
tmp, err := strconv.ParseUint(s[1].(string), 10, 64)
if err != nil {
return
}
return userId, uint32(tmp >> 32), nil
}

View File

@ -0,0 +1,40 @@
package logic
import (
"context"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/logic/rankings"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/ranking"
"github.com/zeromicro/go-zero/core/logx"
)
type RemoveRankingLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewRemoveRankingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RemoveRankingLogic {
return &RemoveRankingLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *RemoveRankingLogic) RemoveRanking(in *ranking.RemoveRankingRequest) (*ranking.BaseResult, error) {
cacheKey := rankings.GetRankingsCacheKey(in.AppId, in.Type)
err := l.svcCtx.RedisRanking.Remove(l.ctx, cacheKey)
if err != nil {
return nil, err
}
gs := l.svcCtx.Query.GameScore
_, err = gs.WithContext(l.ctx).Where(gs.AppAccount.Eq(in.AppId), gs.T.Eq(in.Type)).Delete()
if err != nil {
return nil, err
}
return &ranking.BaseResult{}, nil
}

View File

@ -3,10 +3,10 @@ package logic
import (
"context"
"errors"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/logic/rankings"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/svc"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/ranking_management"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm/gen/dao/model"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/gen/dao/model"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/logic/rankings"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/ranking"
"github.com/redis/go-redis/v9"
"gorm.io/gorm"
"time"
@ -28,14 +28,14 @@ func NewSetUserGameScoreLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
}
}
func (l *SetUserGameScoreLogic) SetUserGameScore(in *ranking_management.SetUserGameScoreRequest) (*ranking_management.BaseResult, error) {
func (l *SetUserGameScoreLogic) SetUserGameScore(in *ranking.SetUserGameScoreRequest) (*ranking.BaseResult, error) {
gs := l.svcCtx.Query.GameScore
// 查询旧分数
oldScore, err := gs.
WithContext(l.ctx).
Where(
gs.AppUserID.Eq(in.UserId),
gs.UserID.Eq(in.UserId),
gs.AppAccount.Eq(in.AppId),
gs.T.Eq(in.Type),
).
@ -51,12 +51,12 @@ func (l *SetUserGameScoreLogic) SetUserGameScore(in *ranking_management.SetUserG
// 判断是否需要更新(只保留最高分)
if in.Score <= oldScore.Score {
return &ranking_management.BaseResult{}, nil
return &ranking.BaseResult{}, nil
}
oldScore.Score = in.Score
oldScore.T = in.Type
oldScore.AppUserID = in.UserId
oldScore.UserID = in.UserId
oldScore.AppAccount = in.AppId
// 更新数据库
@ -70,5 +70,5 @@ func (l *SetUserGameScoreLogic) SetUserGameScore(in *ranking_management.SetUserG
Score: float64(uint64(in.Score)<<32 + uint64(time.Now().Unix())),
})
return &ranking_management.BaseResult{}, nil
return &ranking.BaseResult{}, nil
}

View File

@ -0,0 +1,54 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.7.6
// Source: ranking_service.proto
package server
import (
"context"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/logic"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/ranking"
)
type RankingServiceServer struct {
svcCtx *svc.ServiceContext
ranking.UnimplementedRankingServiceServer
}
func NewRankingServiceServer(svcCtx *svc.ServiceContext) *RankingServiceServer {
return &RankingServiceServer{
svcCtx: svcCtx,
}
}
func (s *RankingServiceServer) Ping(ctx context.Context, in *ranking.Request) (*ranking.Response, error) {
l := logic.NewPingLogic(ctx, s.svcCtx)
return l.Ping(in)
}
func (s *RankingServiceServer) SetUserGameScore(ctx context.Context, in *ranking.SetUserGameScoreRequest) (*ranking.BaseResult, error) {
l := logic.NewSetUserGameScoreLogic(ctx, s.svcCtx)
return l.SetUserGameScore(in)
}
func (s *RankingServiceServer) GetRankingList(ctx context.Context, in *ranking.GetRankingListRequest) (*ranking.GetRankingListResponse, error) {
l := logic.NewGetRankingListLogic(ctx, s.svcCtx)
return l.GetRankingList(in)
}
func (s *RankingServiceServer) AddUserGameScore(ctx context.Context, in *ranking.AddUserGameScoreRequest) (*ranking.BaseResult, error) {
l := logic.NewAddUserGameScoreLogic(ctx, s.svcCtx)
return l.AddUserGameScore(in)
}
func (s *RankingServiceServer) RemoveRanking(ctx context.Context, in *ranking.RemoveRankingRequest) (*ranking.BaseResult, error) {
l := logic.NewRemoveRankingLogic(ctx, s.svcCtx)
return l.RemoveRanking(in)
}
func (s *RankingServiceServer) AtomicGetHigherUser(ctx context.Context, in *ranking.AtomicGetHigherUserRequest) (*ranking.RankingList, error) {
l := logic.NewAtomicGetHigherUserLogic(ctx, s.svcCtx)
return l.AtomicGetHigherUser(in)
}

View File

@ -0,0 +1,90 @@
package svc
import (
"context"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/gen/dao/query"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/logic/rankings"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/userservice"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/pkg/config"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/pkg/my_gorm"
"github.com/redis/go-redis/v9"
"github.com/spf13/viper"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/discov"
"github.com/zeromicro/go-zero/zrpc"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
type ServiceContext struct {
Config config.Config
Query *query.Query
RedisRanking *rankings.Ranking
UserServiceClient userservice.UserService
}
func NewServiceContext(c config.Config) *ServiceContext {
svc := &ServiceContext{
Config: c,
}
//初始化redis client
redisClient := redis.NewClient(&redis.Options{
Addr: c.Redis[0].Host,
})
//初始化数据库
db, err := my_gorm.NewDBWithCache(mysql.Open(c.Mysql), &gorm.Config{}, redisClient)
if err != nil {
panic(err)
}
svc.Query = query.Use(db)
// 初始化用户客户端
clientConf := zrpc.RpcClientConf{}
err = conf.FillDefault(&clientConf) // 填充默认值,比如 trace 透传等,参考服务配置说明
if err != nil {
panic(err)
}
clientConf.Token = "user_service.rpc.key"
clientConf.App = "user_service.rpc"
clientConf.Etcd = discov.EtcdConf{ // 通过 etcd 服务发现
Hosts: []string{viper.GetString(config.EtcdAddrKey)},
Key: "user_service.rpc",
}
svc.UserServiceClient = userservice.NewUserService(zrpc.MustNewClient(clientConf))
//初始化排行榜对象
svc.InitRankings(redisClient)
return svc
}
func (svc *ServiceContext) InitRankings(redisClient *redis.Client) {
//初始化排行榜对象
svc.RedisRanking = rankings.NewRanking(redisClient)
//获取所有不同的排行榜
gs := svc.Query.GameScore
r, err := gs.WithContext(context.TODO()).Select(gs.AppAccount, gs.T).Distinct().Find()
if err != nil {
panic(err)
}
//获取所有排行榜
for _, ranking := range r {
scores, err := gs.WithContext(context.TODO()).Where(gs.AppAccount.Eq(ranking.AppAccount), gs.T.Eq(ranking.T)).Find()
if err != nil {
panic(err)
}
data := make([]redis.Z, 0, len(scores))
for _, score := range scores {
data = append(data, redis.Z{
Score: float64(uint64(score.Score)<<32 + uint64(score.UpdatedAt.Unix())),
Member: score.UserID,
})
}
svc.RedisRanking.SetList(context.Background(), rankings.GetRankingsCacheKey(ranking.AppAccount, ranking.T), data...)
}
}

View File

@ -0,0 +1,768 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.4
// protoc v3.19.4
// source: ranking_service.proto
package ranking
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type Request struct {
state protoimpl.MessageState `protogen:"open.v1"`
Ping string `protobuf:"bytes,1,opt,name=ping,proto3" json:"ping,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Request) Reset() {
*x = Request{}
mi := &file_ranking_service_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Request) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Request) ProtoMessage() {}
func (x *Request) ProtoReflect() protoreflect.Message {
mi := &file_ranking_service_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Request.ProtoReflect.Descriptor instead.
func (*Request) Descriptor() ([]byte, []int) {
return file_ranking_service_proto_rawDescGZIP(), []int{0}
}
func (x *Request) GetPing() string {
if x != nil {
return x.Ping
}
return ""
}
type Response struct {
state protoimpl.MessageState `protogen:"open.v1"`
Pong string `protobuf:"bytes,1,opt,name=pong,proto3" json:"pong,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Response) Reset() {
*x = Response{}
mi := &file_ranking_service_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Response) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Response) ProtoMessage() {}
func (x *Response) ProtoReflect() protoreflect.Message {
mi := &file_ranking_service_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Response.ProtoReflect.Descriptor instead.
func (*Response) Descriptor() ([]byte, []int) {
return file_ranking_service_proto_rawDescGZIP(), []int{1}
}
func (x *Response) GetPong() string {
if x != nil {
return x.Pong
}
return ""
}
// 定义SetUserGameScoreRequest消息类型
type SetUserGameScoreRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Score uint32 `protobuf:"varint,1,opt,name=score,proto3" json:"score,omitempty"` // 对应json的"score"
Type uint32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"` // 对应json的"type", 带默认值0
UserId uint64 `protobuf:"varint,3,opt,name=userId,proto3" json:"userId,omitempty"` // 用户id
AppId uint32 `protobuf:"varint,4,opt,name=appId,proto3" json:"appId,omitempty"` // 小程序id
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *SetUserGameScoreRequest) Reset() {
*x = SetUserGameScoreRequest{}
mi := &file_ranking_service_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *SetUserGameScoreRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SetUserGameScoreRequest) ProtoMessage() {}
func (x *SetUserGameScoreRequest) ProtoReflect() protoreflect.Message {
mi := &file_ranking_service_proto_msgTypes[2]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SetUserGameScoreRequest.ProtoReflect.Descriptor instead.
func (*SetUserGameScoreRequest) Descriptor() ([]byte, []int) {
return file_ranking_service_proto_rawDescGZIP(), []int{2}
}
func (x *SetUserGameScoreRequest) GetScore() uint32 {
if x != nil {
return x.Score
}
return 0
}
func (x *SetUserGameScoreRequest) GetType() uint32 {
if x != nil {
return x.Type
}
return 0
}
func (x *SetUserGameScoreRequest) GetUserId() uint64 {
if x != nil {
return x.UserId
}
return 0
}
func (x *SetUserGameScoreRequest) GetAppId() uint32 {
if x != nil {
return x.AppId
}
return 0
}
// 定义RankingData消息类型
type RankingList struct {
state protoimpl.MessageState `protogen:"open.v1"`
Nickname string `protobuf:"bytes,1,opt,name=nickname,proto3" json:"nickname,omitempty"` // 昵称对应db:"nickname"
Avatar string `protobuf:"bytes,2,opt,name=avatar,proto3" json:"avatar,omitempty"` // 头像对应db:"avatar"
Score uint32 `protobuf:"varint,3,opt,name=score,proto3" json:"score,omitempty"` // 得分对应db:"score"
UserId uint64 `protobuf:"varint,4,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` // 用户ID对应db:"app_user_id"
Rank uint32 `protobuf:"varint,5,opt,name=rank,proto3" json:"rank,omitempty"` // 排名对应db:"rank"
Self bool `protobuf:"varint,6,opt,name=self,proto3" json:"self,omitempty"` // 是否自我判断
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *RankingList) Reset() {
*x = RankingList{}
mi := &file_ranking_service_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *RankingList) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*RankingList) ProtoMessage() {}
func (x *RankingList) ProtoReflect() protoreflect.Message {
mi := &file_ranking_service_proto_msgTypes[3]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use RankingList.ProtoReflect.Descriptor instead.
func (*RankingList) Descriptor() ([]byte, []int) {
return file_ranking_service_proto_rawDescGZIP(), []int{3}
}
func (x *RankingList) GetNickname() string {
if x != nil {
return x.Nickname
}
return ""
}
func (x *RankingList) GetAvatar() string {
if x != nil {
return x.Avatar
}
return ""
}
func (x *RankingList) GetScore() uint32 {
if x != nil {
return x.Score
}
return 0
}
func (x *RankingList) GetUserId() uint64 {
if x != nil {
return x.UserId
}
return 0
}
func (x *RankingList) GetRank() uint32 {
if x != nil {
return x.Rank
}
return 0
}
func (x *RankingList) GetSelf() bool {
if x != nil {
return x.Self
}
return false
}
type GetRankingListResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
RankingData []*RankingList `protobuf:"bytes,1,rep,name=rankingData,proto3" json:"rankingData,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetRankingListResponse) Reset() {
*x = GetRankingListResponse{}
mi := &file_ranking_service_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetRankingListResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetRankingListResponse) ProtoMessage() {}
func (x *GetRankingListResponse) ProtoReflect() protoreflect.Message {
mi := &file_ranking_service_proto_msgTypes[4]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetRankingListResponse.ProtoReflect.Descriptor instead.
func (*GetRankingListResponse) Descriptor() ([]byte, []int) {
return file_ranking_service_proto_rawDescGZIP(), []int{4}
}
func (x *GetRankingListResponse) GetRankingData() []*RankingList {
if x != nil {
return x.RankingData
}
return nil
}
type GetRankingListRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
AppId uint32 `protobuf:"varint,1,opt,name=appId,proto3" json:"appId,omitempty"`
Type uint32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"`
UserId uint64 `protobuf:"varint,3,opt,name=userId,proto3" json:"userId,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetRankingListRequest) Reset() {
*x = GetRankingListRequest{}
mi := &file_ranking_service_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetRankingListRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetRankingListRequest) ProtoMessage() {}
func (x *GetRankingListRequest) ProtoReflect() protoreflect.Message {
mi := &file_ranking_service_proto_msgTypes[5]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetRankingListRequest.ProtoReflect.Descriptor instead.
func (*GetRankingListRequest) Descriptor() ([]byte, []int) {
return file_ranking_service_proto_rawDescGZIP(), []int{5}
}
func (x *GetRankingListRequest) GetAppId() uint32 {
if x != nil {
return x.AppId
}
return 0
}
func (x *GetRankingListRequest) GetType() uint32 {
if x != nil {
return x.Type
}
return 0
}
func (x *GetRankingListRequest) GetUserId() uint64 {
if x != nil {
return x.UserId
}
return 0
}
// 定义Base响应结构
type BaseResult struct {
state protoimpl.MessageState `protogen:"open.v1"`
ErrorCode int32 `protobuf:"varint,1,opt,name=error_code,json=errorCode,proto3" json:"error_code,omitempty"` // 错误码
ErrorMsg string `protobuf:"bytes,2,opt,name=error_msg,json=errorMsg,proto3" json:"error_msg,omitempty"` // 错误信息
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *BaseResult) Reset() {
*x = BaseResult{}
mi := &file_ranking_service_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *BaseResult) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*BaseResult) ProtoMessage() {}
func (x *BaseResult) ProtoReflect() protoreflect.Message {
mi := &file_ranking_service_proto_msgTypes[6]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use BaseResult.ProtoReflect.Descriptor instead.
func (*BaseResult) Descriptor() ([]byte, []int) {
return file_ranking_service_proto_rawDescGZIP(), []int{6}
}
func (x *BaseResult) GetErrorCode() int32 {
if x != nil {
return x.ErrorCode
}
return 0
}
func (x *BaseResult) GetErrorMsg() string {
if x != nil {
return x.ErrorMsg
}
return ""
}
type AddUserGameScoreRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Type uint32 `protobuf:"varint,1,opt,name=type,proto3" json:"type,omitempty"`
AppId uint32 `protobuf:"varint,2,opt,name=appId,proto3" json:"appId,omitempty"`
UserId uint64 `protobuf:"varint,3,opt,name=userId,proto3" json:"userId,omitempty"`
Score uint32 `protobuf:"varint,4,opt,name=score,proto3" json:"score,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *AddUserGameScoreRequest) Reset() {
*x = AddUserGameScoreRequest{}
mi := &file_ranking_service_proto_msgTypes[7]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *AddUserGameScoreRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AddUserGameScoreRequest) ProtoMessage() {}
func (x *AddUserGameScoreRequest) ProtoReflect() protoreflect.Message {
mi := &file_ranking_service_proto_msgTypes[7]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use AddUserGameScoreRequest.ProtoReflect.Descriptor instead.
func (*AddUserGameScoreRequest) Descriptor() ([]byte, []int) {
return file_ranking_service_proto_rawDescGZIP(), []int{7}
}
func (x *AddUserGameScoreRequest) GetType() uint32 {
if x != nil {
return x.Type
}
return 0
}
func (x *AddUserGameScoreRequest) GetAppId() uint32 {
if x != nil {
return x.AppId
}
return 0
}
func (x *AddUserGameScoreRequest) GetUserId() uint64 {
if x != nil {
return x.UserId
}
return 0
}
func (x *AddUserGameScoreRequest) GetScore() uint32 {
if x != nil {
return x.Score
}
return 0
}
type RemoveRankingRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
AppId uint32 `protobuf:"varint,1,opt,name=appId,proto3" json:"appId,omitempty"`
Type uint32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *RemoveRankingRequest) Reset() {
*x = RemoveRankingRequest{}
mi := &file_ranking_service_proto_msgTypes[8]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *RemoveRankingRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*RemoveRankingRequest) ProtoMessage() {}
func (x *RemoveRankingRequest) ProtoReflect() protoreflect.Message {
mi := &file_ranking_service_proto_msgTypes[8]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use RemoveRankingRequest.ProtoReflect.Descriptor instead.
func (*RemoveRankingRequest) Descriptor() ([]byte, []int) {
return file_ranking_service_proto_rawDescGZIP(), []int{8}
}
func (x *RemoveRankingRequest) GetAppId() uint32 {
if x != nil {
return x.AppId
}
return 0
}
func (x *RemoveRankingRequest) GetType() uint32 {
if x != nil {
return x.Type
}
return 0
}
type AtomicGetHigherUserRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
AppId uint32 `protobuf:"varint,1,opt,name=appId,proto3" json:"appId,omitempty"`
Score uint32 `protobuf:"varint,2,opt,name=score,proto3" json:"score,omitempty"`
Type uint32 `protobuf:"varint,3,opt,name=type,proto3" json:"type,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *AtomicGetHigherUserRequest) Reset() {
*x = AtomicGetHigherUserRequest{}
mi := &file_ranking_service_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *AtomicGetHigherUserRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AtomicGetHigherUserRequest) ProtoMessage() {}
func (x *AtomicGetHigherUserRequest) ProtoReflect() protoreflect.Message {
mi := &file_ranking_service_proto_msgTypes[9]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use AtomicGetHigherUserRequest.ProtoReflect.Descriptor instead.
func (*AtomicGetHigherUserRequest) Descriptor() ([]byte, []int) {
return file_ranking_service_proto_rawDescGZIP(), []int{9}
}
func (x *AtomicGetHigherUserRequest) GetAppId() uint32 {
if x != nil {
return x.AppId
}
return 0
}
func (x *AtomicGetHigherUserRequest) GetScore() uint32 {
if x != nil {
return x.Score
}
return 0
}
func (x *AtomicGetHigherUserRequest) GetType() uint32 {
if x != nil {
return x.Type
}
return 0
}
var File_ranking_service_proto protoreflect.FileDescriptor
var file_ranking_service_proto_rawDesc = string([]byte{
0x0a, 0x15, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0f, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67,
0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x22, 0x1d, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x04, 0x70, 0x69, 0x6e, 0x67, 0x22, 0x1e, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x04, 0x70, 0x6f, 0x6e, 0x67, 0x22, 0x71, 0x0a, 0x17, 0x53, 0x65, 0x74, 0x55, 0x73,
0x65, 0x72, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28,
0x0d, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65,
0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06,
0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x75, 0x73,
0x65, 0x72, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x18, 0x04, 0x20,
0x01, 0x28, 0x0d, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x22, 0x98, 0x01, 0x0a, 0x0b, 0x52,
0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x6e, 0x69,
0x63, 0x6b, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6e, 0x69,
0x63, 0x6b, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x12, 0x14,
0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x73,
0x63, 0x6f, 0x72, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18,
0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x12, 0x0a,
0x04, 0x72, 0x61, 0x6e, 0x6b, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x72, 0x61, 0x6e,
0x6b, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x65, 0x6c, 0x66, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52,
0x04, 0x73, 0x65, 0x6c, 0x66, 0x22, 0x58, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x6b,
0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
0x3e, 0x0a, 0x0b, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x44, 0x61, 0x74, 0x61, 0x18, 0x01,
0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73,
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69,
0x73, 0x74, 0x52, 0x0b, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x44, 0x61, 0x74, 0x61, 0x22,
0x59, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73,
0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x49,
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x12, 0x12,
0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x74, 0x79,
0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01,
0x28, 0x04, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x48, 0x0a, 0x0a, 0x42, 0x61,
0x73, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x72, 0x72, 0x6f,
0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x65, 0x72,
0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x65, 0x72, 0x72, 0x6f, 0x72,
0x5f, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x65, 0x72, 0x72, 0x6f,
0x72, 0x4d, 0x73, 0x67, 0x22, 0x71, 0x0a, 0x17, 0x41, 0x64, 0x64, 0x55, 0x73, 0x65, 0x72, 0x47,
0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x74,
0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01,
0x28, 0x0d, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65,
0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49,
0x64, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d,
0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x22, 0x40, 0x0a, 0x14, 0x52, 0x65, 0x6d, 0x6f, 0x76,
0x65, 0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05,
0x61, 0x70, 0x70, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20,
0x01, 0x28, 0x0d, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x5c, 0x0a, 0x1a, 0x41, 0x74, 0x6f,
0x6d, 0x69, 0x63, 0x47, 0x65, 0x74, 0x48, 0x69, 0x67, 0x68, 0x65, 0x72, 0x55, 0x73, 0x65, 0x72,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64,
0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x12, 0x14, 0x0a,
0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x73, 0x63,
0x6f, 0x72, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28,
0x0d, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x32, 0x9e, 0x04, 0x0a, 0x0f, 0x72, 0x61, 0x6e, 0x6b,
0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x3b, 0x0a, 0x04, 0x50,
0x69, 0x6e, 0x67, 0x12, 0x18, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65,
0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e,
0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x59, 0x0a, 0x10, 0x53, 0x65, 0x74, 0x55,
0x73, 0x65, 0x72, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x28, 0x2e, 0x72,
0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x53,
0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67,
0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x52, 0x65, 0x73,
0x75, 0x6c, 0x74, 0x12, 0x61, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e,
0x67, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x26, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f,
0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x6b, 0x69,
0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e,
0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e,
0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x59, 0x0a, 0x10, 0x41, 0x64, 0x64, 0x55, 0x73, 0x65,
0x72, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x28, 0x2e, 0x72, 0x61, 0x6e,
0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x41, 0x64, 0x64,
0x55, 0x73, 0x65, 0x72, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73,
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c,
0x74, 0x12, 0x53, 0x0a, 0x0d, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x61, 0x6e, 0x6b, 0x69,
0x6e, 0x67, 0x12, 0x25, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x61, 0x6e, 0x6b, 0x69,
0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x72, 0x61, 0x6e, 0x6b,
0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65,
0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x60, 0x0a, 0x13, 0x41, 0x74, 0x6f, 0x6d, 0x69, 0x63,
0x47, 0x65, 0x74, 0x48, 0x69, 0x67, 0x68, 0x65, 0x72, 0x55, 0x73, 0x65, 0x72, 0x12, 0x2b, 0x2e,
0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e,
0x41, 0x74, 0x6f, 0x6d, 0x69, 0x63, 0x47, 0x65, 0x74, 0x48, 0x69, 0x67, 0x68, 0x65, 0x72, 0x55,
0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x72, 0x61, 0x6e,
0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x61, 0x6e,
0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x42, 0x0b, 0x5a, 0x09, 0x2e, 0x2f, 0x72, 0x61,
0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
})
var (
file_ranking_service_proto_rawDescOnce sync.Once
file_ranking_service_proto_rawDescData []byte
)
func file_ranking_service_proto_rawDescGZIP() []byte {
file_ranking_service_proto_rawDescOnce.Do(func() {
file_ranking_service_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_ranking_service_proto_rawDesc), len(file_ranking_service_proto_rawDesc)))
})
return file_ranking_service_proto_rawDescData
}
var file_ranking_service_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
var file_ranking_service_proto_goTypes = []any{
(*Request)(nil), // 0: ranking_service.Request
(*Response)(nil), // 1: ranking_service.Response
(*SetUserGameScoreRequest)(nil), // 2: ranking_service.SetUserGameScoreRequest
(*RankingList)(nil), // 3: ranking_service.RankingList
(*GetRankingListResponse)(nil), // 4: ranking_service.GetRankingListResponse
(*GetRankingListRequest)(nil), // 5: ranking_service.GetRankingListRequest
(*BaseResult)(nil), // 6: ranking_service.BaseResult
(*AddUserGameScoreRequest)(nil), // 7: ranking_service.AddUserGameScoreRequest
(*RemoveRankingRequest)(nil), // 8: ranking_service.RemoveRankingRequest
(*AtomicGetHigherUserRequest)(nil), // 9: ranking_service.AtomicGetHigherUserRequest
}
var file_ranking_service_proto_depIdxs = []int32{
3, // 0: ranking_service.GetRankingListResponse.rankingData:type_name -> ranking_service.RankingList
0, // 1: ranking_service.ranking_service.Ping:input_type -> ranking_service.Request
2, // 2: ranking_service.ranking_service.SetUserGameScore:input_type -> ranking_service.SetUserGameScoreRequest
5, // 3: ranking_service.ranking_service.GetRankingList:input_type -> ranking_service.GetRankingListRequest
7, // 4: ranking_service.ranking_service.AddUserGameScore:input_type -> ranking_service.AddUserGameScoreRequest
8, // 5: ranking_service.ranking_service.RemoveRanking:input_type -> ranking_service.RemoveRankingRequest
9, // 6: ranking_service.ranking_service.AtomicGetHigherUser:input_type -> ranking_service.AtomicGetHigherUserRequest
1, // 7: ranking_service.ranking_service.Ping:output_type -> ranking_service.Response
6, // 8: ranking_service.ranking_service.SetUserGameScore:output_type -> ranking_service.BaseResult
4, // 9: ranking_service.ranking_service.GetRankingList:output_type -> ranking_service.GetRankingListResponse
6, // 10: ranking_service.ranking_service.AddUserGameScore:output_type -> ranking_service.BaseResult
6, // 11: ranking_service.ranking_service.RemoveRanking:output_type -> ranking_service.BaseResult
3, // 12: ranking_service.ranking_service.AtomicGetHigherUser:output_type -> ranking_service.RankingList
7, // [7:13] is the sub-list for method output_type
1, // [1:7] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_ranking_service_proto_init() }
func file_ranking_service_proto_init() {
if File_ranking_service_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_ranking_service_proto_rawDesc), len(file_ranking_service_proto_rawDesc)),
NumEnums: 0,
NumMessages: 10,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_ranking_service_proto_goTypes,
DependencyIndexes: file_ranking_service_proto_depIdxs,
MessageInfos: file_ranking_service_proto_msgTypes,
}.Build()
File_ranking_service_proto = out.File
file_ranking_service_proto_goTypes = nil
file_ranking_service_proto_depIdxs = nil
}

View File

@ -0,0 +1,311 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc v3.19.4
// source: ranking_service.proto
package ranking
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
RankingService_Ping_FullMethodName = "/ranking_service.ranking_service/Ping"
RankingService_SetUserGameScore_FullMethodName = "/ranking_service.ranking_service/SetUserGameScore"
RankingService_GetRankingList_FullMethodName = "/ranking_service.ranking_service/GetRankingList"
RankingService_AddUserGameScore_FullMethodName = "/ranking_service.ranking_service/AddUserGameScore"
RankingService_RemoveRanking_FullMethodName = "/ranking_service.ranking_service/RemoveRanking"
RankingService_AtomicGetHigherUser_FullMethodName = "/ranking_service.ranking_service/AtomicGetHigherUser"
)
// RankingServiceClient is the client API for RankingService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type RankingServiceClient interface {
Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
SetUserGameScore(ctx context.Context, in *SetUserGameScoreRequest, opts ...grpc.CallOption) (*BaseResult, error)
GetRankingList(ctx context.Context, in *GetRankingListRequest, opts ...grpc.CallOption) (*GetRankingListResponse, error)
AddUserGameScore(ctx context.Context, in *AddUserGameScoreRequest, opts ...grpc.CallOption) (*BaseResult, error)
RemoveRanking(ctx context.Context, in *RemoveRankingRequest, opts ...grpc.CallOption) (*BaseResult, error)
AtomicGetHigherUser(ctx context.Context, in *AtomicGetHigherUserRequest, opts ...grpc.CallOption) (*RankingList, error)
}
type rankingServiceClient struct {
cc grpc.ClientConnInterface
}
func NewRankingServiceClient(cc grpc.ClientConnInterface) RankingServiceClient {
return &rankingServiceClient{cc}
}
func (c *rankingServiceClient) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Response)
err := c.cc.Invoke(ctx, RankingService_Ping_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *rankingServiceClient) SetUserGameScore(ctx context.Context, in *SetUserGameScoreRequest, opts ...grpc.CallOption) (*BaseResult, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(BaseResult)
err := c.cc.Invoke(ctx, RankingService_SetUserGameScore_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *rankingServiceClient) GetRankingList(ctx context.Context, in *GetRankingListRequest, opts ...grpc.CallOption) (*GetRankingListResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetRankingListResponse)
err := c.cc.Invoke(ctx, RankingService_GetRankingList_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *rankingServiceClient) AddUserGameScore(ctx context.Context, in *AddUserGameScoreRequest, opts ...grpc.CallOption) (*BaseResult, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(BaseResult)
err := c.cc.Invoke(ctx, RankingService_AddUserGameScore_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *rankingServiceClient) RemoveRanking(ctx context.Context, in *RemoveRankingRequest, opts ...grpc.CallOption) (*BaseResult, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(BaseResult)
err := c.cc.Invoke(ctx, RankingService_RemoveRanking_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *rankingServiceClient) AtomicGetHigherUser(ctx context.Context, in *AtomicGetHigherUserRequest, opts ...grpc.CallOption) (*RankingList, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(RankingList)
err := c.cc.Invoke(ctx, RankingService_AtomicGetHigherUser_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// RankingServiceServer is the server API for RankingService service.
// All implementations must embed UnimplementedRankingServiceServer
// for forward compatibility.
type RankingServiceServer interface {
Ping(context.Context, *Request) (*Response, error)
SetUserGameScore(context.Context, *SetUserGameScoreRequest) (*BaseResult, error)
GetRankingList(context.Context, *GetRankingListRequest) (*GetRankingListResponse, error)
AddUserGameScore(context.Context, *AddUserGameScoreRequest) (*BaseResult, error)
RemoveRanking(context.Context, *RemoveRankingRequest) (*BaseResult, error)
AtomicGetHigherUser(context.Context, *AtomicGetHigherUserRequest) (*RankingList, error)
mustEmbedUnimplementedRankingServiceServer()
}
// UnimplementedRankingServiceServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedRankingServiceServer struct{}
func (UnimplementedRankingServiceServer) Ping(context.Context, *Request) (*Response, error) {
return nil, status.Errorf(codes.Unimplemented, "method Ping not implemented")
}
func (UnimplementedRankingServiceServer) SetUserGameScore(context.Context, *SetUserGameScoreRequest) (*BaseResult, error) {
return nil, status.Errorf(codes.Unimplemented, "method SetUserGameScore not implemented")
}
func (UnimplementedRankingServiceServer) GetRankingList(context.Context, *GetRankingListRequest) (*GetRankingListResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetRankingList not implemented")
}
func (UnimplementedRankingServiceServer) AddUserGameScore(context.Context, *AddUserGameScoreRequest) (*BaseResult, error) {
return nil, status.Errorf(codes.Unimplemented, "method AddUserGameScore not implemented")
}
func (UnimplementedRankingServiceServer) RemoveRanking(context.Context, *RemoveRankingRequest) (*BaseResult, error) {
return nil, status.Errorf(codes.Unimplemented, "method RemoveRanking not implemented")
}
func (UnimplementedRankingServiceServer) AtomicGetHigherUser(context.Context, *AtomicGetHigherUserRequest) (*RankingList, error) {
return nil, status.Errorf(codes.Unimplemented, "method AtomicGetHigherUser not implemented")
}
func (UnimplementedRankingServiceServer) mustEmbedUnimplementedRankingServiceServer() {}
func (UnimplementedRankingServiceServer) testEmbeddedByValue() {}
// UnsafeRankingServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to RankingServiceServer will
// result in compilation errors.
type UnsafeRankingServiceServer interface {
mustEmbedUnimplementedRankingServiceServer()
}
func RegisterRankingServiceServer(s grpc.ServiceRegistrar, srv RankingServiceServer) {
// If the following call pancis, it indicates UnimplementedRankingServiceServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&RankingService_ServiceDesc, srv)
}
func _RankingService_Ping_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Request)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RankingServiceServer).Ping(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: RankingService_Ping_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RankingServiceServer).Ping(ctx, req.(*Request))
}
return interceptor(ctx, in, info, handler)
}
func _RankingService_SetUserGameScore_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SetUserGameScoreRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RankingServiceServer).SetUserGameScore(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: RankingService_SetUserGameScore_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RankingServiceServer).SetUserGameScore(ctx, req.(*SetUserGameScoreRequest))
}
return interceptor(ctx, in, info, handler)
}
func _RankingService_GetRankingList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetRankingListRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RankingServiceServer).GetRankingList(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: RankingService_GetRankingList_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RankingServiceServer).GetRankingList(ctx, req.(*GetRankingListRequest))
}
return interceptor(ctx, in, info, handler)
}
func _RankingService_AddUserGameScore_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(AddUserGameScoreRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RankingServiceServer).AddUserGameScore(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: RankingService_AddUserGameScore_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RankingServiceServer).AddUserGameScore(ctx, req.(*AddUserGameScoreRequest))
}
return interceptor(ctx, in, info, handler)
}
func _RankingService_RemoveRanking_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(RemoveRankingRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RankingServiceServer).RemoveRanking(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: RankingService_RemoveRanking_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RankingServiceServer).RemoveRanking(ctx, req.(*RemoveRankingRequest))
}
return interceptor(ctx, in, info, handler)
}
func _RankingService_AtomicGetHigherUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(AtomicGetHigherUserRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RankingServiceServer).AtomicGetHigherUser(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: RankingService_AtomicGetHigherUser_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RankingServiceServer).AtomicGetHigherUser(ctx, req.(*AtomicGetHigherUserRequest))
}
return interceptor(ctx, in, info, handler)
}
// RankingService_ServiceDesc is the grpc.ServiceDesc for RankingService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var RankingService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "ranking_service.ranking_service",
HandlerType: (*RankingServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Ping",
Handler: _RankingService_Ping_Handler,
},
{
MethodName: "SetUserGameScore",
Handler: _RankingService_SetUserGameScore_Handler,
},
{
MethodName: "GetRankingList",
Handler: _RankingService_GetRankingList_Handler,
},
{
MethodName: "AddUserGameScore",
Handler: _RankingService_AddUserGameScore_Handler,
},
{
MethodName: "RemoveRanking",
Handler: _RankingService_RemoveRanking_Handler,
},
{
MethodName: "AtomicGetHigherUser",
Handler: _RankingService_AtomicGetHigherUser_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "ranking_service.proto",
}

View File

@ -0,0 +1,41 @@
package main
import (
"fmt"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/server"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/ranking"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/pkg/config"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
const ServiceName = "ranking_service"
func main() {
var c config.Config
err := config.GetConfig(&c, ServiceName)
if err != nil {
panic(err)
}
c.RpcServerConf.Name = ServiceName + ".rpc"
ctx := svc.NewServiceContext(c)
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
ranking.RegisterRankingServiceServer(grpcServer, server.NewRankingServiceServer(ctx))
if c.Mode == service.DevMode || c.Mode == service.TestMode {
reflection.Register(grpcServer)
}
})
defer s.Stop()
fmt.Printf("Starting rpc server at %s...\n", c.RpcServerConf.ListenOn)
s.Start()
}

View File

@ -1,7 +1,7 @@
syntax = "proto3";
package ranking_management;
option go_package = "./ranking_management";
package ranking_service;
option go_package = "./ranking";
message Request {
string ping = 1;
@ -45,10 +45,35 @@ message BaseResult {
string error_msg = 2; //
}
service Ranking_management {
message AddUserGameScoreRequest{
uint32 type = 1;
uint32 appId = 2;
uint64 userId = 3;
uint32 score = 4;
}
message RemoveRankingRequest{
uint32 appId = 1;
uint32 type = 2;
}
message AtomicGetHigherUserRequest{
uint32 appId = 1;
uint32 score = 2;
uint32 type = 3;
}
service ranking_service {
rpc Ping(Request) returns(Response);
rpc SetUserGameScore (SetUserGameScoreRequest) returns (BaseResult);
rpc GetRankingList (GetRankingListRequest) returns (GetRankingListResponse);
rpc AddUserGameScore(AddUserGameScoreRequest) returns(BaseResult);
rpc RemoveRanking(RemoveRankingRequest) returns(BaseResult);
rpc AtomicGetHigherUser(AtomicGetHigherUserRequest) returns(RankingList);
}

View File

@ -0,0 +1,76 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.7.6
// Source: ranking_service.proto
package rankingservice
import (
"context"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/ranking"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
)
type (
AddUserGameScoreRequest = ranking.AddUserGameScoreRequest
AtomicGetHigherUserRequest = ranking.AtomicGetHigherUserRequest
BaseResult = ranking.BaseResult
GetRankingListRequest = ranking.GetRankingListRequest
GetRankingListResponse = ranking.GetRankingListResponse
RankingList = ranking.RankingList
RemoveRankingRequest = ranking.RemoveRankingRequest
Request = ranking.Request
Response = ranking.Response
SetUserGameScoreRequest = ranking.SetUserGameScoreRequest
RankingService interface {
Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
SetUserGameScore(ctx context.Context, in *SetUserGameScoreRequest, opts ...grpc.CallOption) (*BaseResult, error)
GetRankingList(ctx context.Context, in *GetRankingListRequest, opts ...grpc.CallOption) (*GetRankingListResponse, error)
AddUserGameScore(ctx context.Context, in *AddUserGameScoreRequest, opts ...grpc.CallOption) (*BaseResult, error)
RemoveRanking(ctx context.Context, in *RemoveRankingRequest, opts ...grpc.CallOption) (*BaseResult, error)
AtomicGetHigherUser(ctx context.Context, in *AtomicGetHigherUserRequest, opts ...grpc.CallOption) (*RankingList, error)
}
defaultRankingService struct {
cli zrpc.Client
}
)
func NewRankingService(cli zrpc.Client) RankingService {
return &defaultRankingService{
cli: cli,
}
}
func (m *defaultRankingService) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
client := ranking.NewRankingServiceClient(m.cli.Conn())
return client.Ping(ctx, in, opts...)
}
func (m *defaultRankingService) SetUserGameScore(ctx context.Context, in *SetUserGameScoreRequest, opts ...grpc.CallOption) (*BaseResult, error) {
client := ranking.NewRankingServiceClient(m.cli.Conn())
return client.SetUserGameScore(ctx, in, opts...)
}
func (m *defaultRankingService) GetRankingList(ctx context.Context, in *GetRankingListRequest, opts ...grpc.CallOption) (*GetRankingListResponse, error) {
client := ranking.NewRankingServiceClient(m.cli.Conn())
return client.GetRankingList(ctx, in, opts...)
}
func (m *defaultRankingService) AddUserGameScore(ctx context.Context, in *AddUserGameScoreRequest, opts ...grpc.CallOption) (*BaseResult, error) {
client := ranking.NewRankingServiceClient(m.cli.Conn())
return client.AddUserGameScore(ctx, in, opts...)
}
func (m *defaultRankingService) RemoveRanking(ctx context.Context, in *RemoveRankingRequest, opts ...grpc.CallOption) (*BaseResult, error) {
client := ranking.NewRankingServiceClient(m.cli.Conn())
return client.RemoveRanking(ctx, in, opts...)
}
func (m *defaultRankingService) AtomicGetHigherUser(ctx context.Context, in *AtomicGetHigherUserRequest, opts ...grpc.CallOption) (*RankingList, error) {
client := ranking.NewRankingServiceClient(m.cli.Conn())
return client.AtomicGetHigherUser(ctx, in, opts...)
}

View File

@ -1,29 +0,0 @@
package logic
import (
"context"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/internal/svc"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/user_management"
"github.com/zeromicro/go-zero/core/logx"
)
type SetAppAccountLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewSetAppAccountLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SetAppAccountLogic {
return &SetAppAccountLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *SetAppAccountLogic) SetAppAccount(in *user_management.SetAppUserRequest) (*user_management.Response, error) {
// todo: add your logic here and delete this line
return &user_management.Response{}, nil
}

View File

@ -1,33 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.7.6
// Source: user_management.proto
package server
import (
"context"
logic2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/internal/logic"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/internal/svc"
user_management2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/user_management"
)
type UserManagementServer struct {
svcCtx *svc.ServiceContext
user_management2.UnimplementedUserManagementServer
}
func NewUserManagementServer(svcCtx *svc.ServiceContext) *UserManagementServer {
return &UserManagementServer{
svcCtx: svcCtx,
}
}
func (s *UserManagementServer) Ping(ctx context.Context, in *user_management2.Request) (*user_management2.Response, error) {
l := logic2.NewPingLogic(ctx, s.svcCtx)
return l.Ping(in)
}
func (s *UserManagementServer) SetAppAccount(ctx context.Context, in *user_management2.SetAppUserRequest) (*user_management2.Response, error) {
l := logic2.NewSetAppAccountLogic(ctx, s.svcCtx)
return l.SetAppAccount(in)
}

View File

@ -1,15 +0,0 @@
package svc
import (
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/internal/config"
)
type ServiceContext struct {
Config config.Config
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
}
}

View File

@ -1,38 +0,0 @@
package main
import (
"flag"
"fmt"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/internal/config"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/internal/server"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/internal/svc"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/user_management"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
var configFile = flag.String("f", "etc/user_management.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
ctx := svc.NewServiceContext(c)
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
user_management.RegisterUserManagementServer(grpcServer, server.NewUserManagementServer(ctx))
if c.Mode == service.DevMode || c.Mode == service.TestMode {
reflection.Register(grpcServer)
}
})
defer s.Stop()
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
s.Start()
}

View File

@ -1,23 +0,0 @@
syntax = "proto3";
package user_management;
option go_package="./user_management";
message Request {
string ping = 1;
}
message Response {
string pong = 1;
}
message SetAppUserRequest{
string Nickname=1;
string Avatar=2;
}
service User_management {
rpc Ping(Request) returns(Response);
rpc SetAppAccount (SetAppUserRequest) returns(Response);
}

View File

@ -1,244 +0,0 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.4
// protoc v3.19.4
// source: user_management.proto
package user_management
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type Request struct {
state protoimpl.MessageState `protogen:"open.v1"`
Ping string `protobuf:"bytes,1,opt,name=ping,proto3" json:"ping,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Request) Reset() {
*x = Request{}
mi := &file_user_management_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Request) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Request) ProtoMessage() {}
func (x *Request) ProtoReflect() protoreflect.Message {
mi := &file_user_management_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Request.ProtoReflect.Descriptor instead.
func (*Request) Descriptor() ([]byte, []int) {
return file_user_management_proto_rawDescGZIP(), []int{0}
}
func (x *Request) GetPing() string {
if x != nil {
return x.Ping
}
return ""
}
type Response struct {
state protoimpl.MessageState `protogen:"open.v1"`
Pong string `protobuf:"bytes,1,opt,name=pong,proto3" json:"pong,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Response) Reset() {
*x = Response{}
mi := &file_user_management_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Response) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Response) ProtoMessage() {}
func (x *Response) ProtoReflect() protoreflect.Message {
mi := &file_user_management_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Response.ProtoReflect.Descriptor instead.
func (*Response) Descriptor() ([]byte, []int) {
return file_user_management_proto_rawDescGZIP(), []int{1}
}
func (x *Response) GetPong() string {
if x != nil {
return x.Pong
}
return ""
}
type SetAppUserRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Nickname string `protobuf:"bytes,1,opt,name=Nickname,proto3" json:"Nickname,omitempty"`
Avatar string `protobuf:"bytes,2,opt,name=Avatar,proto3" json:"Avatar,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *SetAppUserRequest) Reset() {
*x = SetAppUserRequest{}
mi := &file_user_management_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *SetAppUserRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SetAppUserRequest) ProtoMessage() {}
func (x *SetAppUserRequest) ProtoReflect() protoreflect.Message {
mi := &file_user_management_proto_msgTypes[2]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SetAppUserRequest.ProtoReflect.Descriptor instead.
func (*SetAppUserRequest) Descriptor() ([]byte, []int) {
return file_user_management_proto_rawDescGZIP(), []int{2}
}
func (x *SetAppUserRequest) GetNickname() string {
if x != nil {
return x.Nickname
}
return ""
}
func (x *SetAppUserRequest) GetAvatar() string {
if x != nil {
return x.Avatar
}
return ""
}
var File_user_management_proto protoreflect.FileDescriptor
var file_user_management_proto_rawDesc = string([]byte{
0x0a, 0x15, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e,
0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61,
0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x1d, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x04, 0x70, 0x69, 0x6e, 0x67, 0x22, 0x1e, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x04, 0x70, 0x6f, 0x6e, 0x67, 0x22, 0x47, 0x0a, 0x11, 0x53, 0x65, 0x74, 0x41, 0x70,
0x70, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08,
0x4e, 0x69, 0x63, 0x6b, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08,
0x4e, 0x69, 0x63, 0x6b, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x41, 0x76, 0x61, 0x74,
0x61, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x41, 0x76, 0x61, 0x74, 0x61, 0x72,
0x32, 0x9e, 0x01, 0x0a, 0x0f, 0x55, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65,
0x6d, 0x65, 0x6e, 0x74, 0x12, 0x3b, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x18, 0x2e, 0x75,
0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61,
0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x12, 0x4e, 0x0a, 0x0d, 0x53, 0x65, 0x74, 0x41, 0x70, 0x70, 0x41, 0x63, 0x63, 0x6f, 0x75,
0x6e, 0x74, 0x12, 0x22, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65,
0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x53, 0x65, 0x74, 0x41, 0x70, 0x70, 0x55, 0x73, 0x65, 0x72, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61,
0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x42, 0x13, 0x5a, 0x11, 0x2e, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61,
0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
})
var (
file_user_management_proto_rawDescOnce sync.Once
file_user_management_proto_rawDescData []byte
)
func file_user_management_proto_rawDescGZIP() []byte {
file_user_management_proto_rawDescOnce.Do(func() {
file_user_management_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_user_management_proto_rawDesc), len(file_user_management_proto_rawDesc)))
})
return file_user_management_proto_rawDescData
}
var file_user_management_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_user_management_proto_goTypes = []any{
(*Request)(nil), // 0: user_management.Request
(*Response)(nil), // 1: user_management.Response
(*SetAppUserRequest)(nil), // 2: user_management.SetAppUserRequest
}
var file_user_management_proto_depIdxs = []int32{
0, // 0: user_management.User_management.Ping:input_type -> user_management.Request
2, // 1: user_management.User_management.SetAppAccount:input_type -> user_management.SetAppUserRequest
1, // 2: user_management.User_management.Ping:output_type -> user_management.Response
1, // 3: user_management.User_management.SetAppAccount:output_type -> user_management.Response
2, // [2:4] is the sub-list for method output_type
0, // [0:2] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_user_management_proto_init() }
func file_user_management_proto_init() {
if File_user_management_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_user_management_proto_rawDesc), len(file_user_management_proto_rawDesc)),
NumEnums: 0,
NumMessages: 3,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_user_management_proto_goTypes,
DependencyIndexes: file_user_management_proto_depIdxs,
MessageInfos: file_user_management_proto_msgTypes,
}.Build()
File_user_management_proto = out.File
file_user_management_proto_goTypes = nil
file_user_management_proto_depIdxs = nil
}

View File

@ -1,159 +0,0 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc v3.19.4
// source: user_management.proto
package user_management
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
UserManagement_Ping_FullMethodName = "/user_management.User_management/Ping"
UserManagement_SetAppAccount_FullMethodName = "/user_management.User_management/SetAppAccount"
)
// UserManagementClient is the client API for UserManagement service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type UserManagementClient interface {
Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
SetAppAccount(ctx context.Context, in *SetAppUserRequest, opts ...grpc.CallOption) (*Response, error)
}
type userManagementClient struct {
cc grpc.ClientConnInterface
}
func NewUserManagementClient(cc grpc.ClientConnInterface) UserManagementClient {
return &userManagementClient{cc}
}
func (c *userManagementClient) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Response)
err := c.cc.Invoke(ctx, UserManagement_Ping_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *userManagementClient) SetAppAccount(ctx context.Context, in *SetAppUserRequest, opts ...grpc.CallOption) (*Response, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Response)
err := c.cc.Invoke(ctx, UserManagement_SetAppAccount_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// UserManagementServer is the server API for UserManagement service.
// All implementations must embed UnimplementedUserManagementServer
// for forward compatibility.
type UserManagementServer interface {
Ping(context.Context, *Request) (*Response, error)
SetAppAccount(context.Context, *SetAppUserRequest) (*Response, error)
mustEmbedUnimplementedUserManagementServer()
}
// UnimplementedUserManagementServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedUserManagementServer struct{}
func (UnimplementedUserManagementServer) Ping(context.Context, *Request) (*Response, error) {
return nil, status.Errorf(codes.Unimplemented, "method Ping not implemented")
}
func (UnimplementedUserManagementServer) SetAppAccount(context.Context, *SetAppUserRequest) (*Response, error) {
return nil, status.Errorf(codes.Unimplemented, "method SetAppAccount not implemented")
}
func (UnimplementedUserManagementServer) mustEmbedUnimplementedUserManagementServer() {}
func (UnimplementedUserManagementServer) testEmbeddedByValue() {}
// UnsafeUserManagementServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to UserManagementServer will
// result in compilation errors.
type UnsafeUserManagementServer interface {
mustEmbedUnimplementedUserManagementServer()
}
func RegisterUserManagementServer(s grpc.ServiceRegistrar, srv UserManagementServer) {
// If the following call pancis, it indicates UnimplementedUserManagementServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&UserManagement_ServiceDesc, srv)
}
func _UserManagement_Ping_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Request)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UserManagementServer).Ping(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: UserManagement_Ping_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UserManagementServer).Ping(ctx, req.(*Request))
}
return interceptor(ctx, in, info, handler)
}
func _UserManagement_SetAppAccount_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SetAppUserRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UserManagementServer).SetAppAccount(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: UserManagement_SetAppAccount_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UserManagementServer).SetAppAccount(ctx, req.(*SetAppUserRequest))
}
return interceptor(ctx, in, info, handler)
}
// UserManagement_ServiceDesc is the grpc.ServiceDesc for UserManagement service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var UserManagement_ServiceDesc = grpc.ServiceDesc{
ServiceName: "user_management.User_management",
HandlerType: (*UserManagementServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Ping",
Handler: _UserManagement_Ping_Handler,
},
{
MethodName: "SetAppAccount",
Handler: _UserManagement_SetAppAccount_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "user_management.proto",
}

View File

@ -1,44 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.7.6
// Source: user_management.proto
package user_management_client
import (
"context"
user_management2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/user_management"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
)
type (
Request = user_management2.Request
Response = user_management2.Response
SetAppUserRequest = user_management2.SetAppUserRequest
UserManagement interface {
Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
SetAppAccount(ctx context.Context, in *SetAppUserRequest, opts ...grpc.CallOption) (*Response, error)
}
defaultUserManagement struct {
cli zrpc.Client
}
)
func NewUserManagement(cli zrpc.Client) UserManagement {
return &defaultUserManagement{
cli: cli,
}
}
func (m *defaultUserManagement) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
client := user_management2.NewUserManagementClient(m.cli.Conn())
return client.Ping(ctx, in, opts...)
}
func (m *defaultUserManagement) SetAppAccount(ctx context.Context, in *SetAppUserRequest, opts ...grpc.CallOption) (*Response, error) {
client := user_management2.NewUserManagementClient(m.cli.Conn())
return client.SetAppAccount(ctx, in, opts...)
}

View File

@ -0,0 +1,33 @@
FROM golang:alpine AS builder
LABEL stage=gobuilder
ENV CGO_ENABLED=0
ENV GOPROXY=https://goproxy.cn,direct
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk update --no-cache && apk add --no-cache tzdata
RUN apk add --no-cache git
WORKDIR /build
ADD go.mod .
ADD go.sum .
RUN go env -w GOPRIVATE=gitea.youtukeji.com.cn
RUN go mod download
COPY . .
RUN go build -ldflags="-s -w" -o /app/user ./app/user_service/user_service.go
FROM alpine
COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai
ENV TZ=Asia/Shanghai
WORKDIR /app
COPY --from=builder /app/user /app/user
EXPOSE 8888
CMD ["/app/user"]

View File

@ -0,0 +1,14 @@
{
"listenOn": "0.0.0.0:8080",
"etcd": {
"Hosts": [
"127.0.0.1:2379"
]
},
"redis": {
"Host": "127.0.0.1:6379"
},
"mysql": {
"Dsn": "root:youtu!0113@tcp(localhost:3306)/ecpm?charset=utf8mb4&parseTime=True&loc=Local"
}
}

View File

@ -1,6 +1,6 @@
Name: usermanagement.rpc
Name: user.rpc
ListenOn: 0.0.0.0:8080
Etcd:
Hosts:
- 127.0.0.1:2379
Key: usermanagement.rpc
Key: user.rpc

View File

@ -0,0 +1,26 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
import (
"time"
)
const TableNameUser = "user"
// User mapped from table <user>
type User struct {
ID uint64 `gorm:"column:id;type:bigint unsigned;primaryKey;autoIncrement:true;index:idx_app_user_id,priority:1" json:"id"`
IsNew uint32 `gorm:"column:is_new;type:tinyint unsigned;not null" json:"is_new"`
Nickname string `gorm:"column:nickname;type:varchar(255);not null;comment:昵称" json:"nickname"` // 昵称
Avatar string `gorm:"column:avatar;type:varchar(255);not null;comment:头像" json:"avatar"` // 头像
CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime;not null;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间
}
// TableName User's table name
func (*User) TableName() string {
return TableNameUser
}

View File

@ -0,0 +1,93 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"database/sql"
"gorm.io/gorm"
"gorm.io/gen"
"gorm.io/plugin/dbresolver"
)
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
User: newUser(db, opts...),
}
}
type Query struct {
db *gorm.DB
User user
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
User: q.User.clone(db),
}
}
func (q *Query) ReadDB() *Query {
return q.ReplaceDB(q.db.Clauses(dbresolver.Read))
}
func (q *Query) WriteDB() *Query {
return q.ReplaceDB(q.db.Clauses(dbresolver.Write))
}
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
return &Query{
db: db,
User: q.User.replaceDB(db),
}
}
type queryCtx struct {
User *userDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
User: q.User.WithContext(ctx),
}
}
func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error {
return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...)
}
func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx {
tx := q.db.Begin(opts...)
return &QueryTx{Query: q.clone(tx), Error: tx.Error}
}
type QueryTx struct {
*Query
Error error
}
func (q *QueryTx) Commit() error {
return q.db.Commit().Error
}
func (q *QueryTx) Rollback() error {
return q.db.Rollback().Error
}
func (q *QueryTx) SavePoint(name string) error {
return q.db.SavePoint(name).Error
}
func (q *QueryTx) RollbackTo(name string) error {
return q.db.RollbackTo(name).Error
}

View File

@ -0,0 +1,118 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"fmt"
"reflect"
"sync"
"testing"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
type Input struct {
Args []interface{}
}
type Expectation struct {
Ret []interface{}
}
type TestCase struct {
Input
Expectation
}
const _gen_test_db_name = "gen_test.db"
var _gen_test_db *gorm.DB
var _gen_test_once sync.Once
func init() {
InitializeDB()
_gen_test_db.AutoMigrate(&_another{})
}
func InitializeDB() {
_gen_test_once.Do(func() {
var err error
_gen_test_db, err = gorm.Open(sqlite.Open(_gen_test_db_name), &gorm.Config{})
if err != nil {
panic(fmt.Errorf("open sqlite %q fail: %w", _gen_test_db_name, err))
}
})
}
func assert(t *testing.T, methodName string, res, exp interface{}) {
if !reflect.DeepEqual(res, exp) {
t.Errorf("%v() gotResult = %v, want %v", methodName, res, exp)
}
}
type _another struct {
ID uint64 `gorm:"primaryKey"`
}
func (*_another) TableName() string { return "another_for_unit_test" }
func Test_Available(t *testing.T) {
if !Use(_gen_test_db).Available() {
t.Errorf("query.Available() == false")
}
}
func Test_WithContext(t *testing.T) {
query := Use(_gen_test_db)
if !query.Available() {
t.Errorf("query Use(_gen_test_db) fail: query.Available() == false")
}
type Content string
var key, value Content = "gen_tag", "unit_test"
qCtx := query.WithContext(context.WithValue(context.Background(), key, value))
for _, ctx := range []context.Context{
qCtx.User.UnderlyingDB().Statement.Context,
} {
if v := ctx.Value(key); v != value {
t.Errorf("get value from context fail, expect %q, got %q", value, v)
}
}
}
func Test_Transaction(t *testing.T) {
query := Use(_gen_test_db)
if !query.Available() {
t.Errorf("query Use(_gen_test_db) fail: query.Available() == false")
}
err := query.Transaction(func(tx *Query) error { return nil })
if err != nil {
t.Errorf("query.Transaction execute fail: %s", err)
}
tx := query.Begin()
err = tx.SavePoint("point")
if err != nil {
t.Errorf("query tx SavePoint fail: %s", err)
}
err = tx.RollbackTo("point")
if err != nil {
t.Errorf("query tx RollbackTo fail: %s", err)
}
err = tx.Commit()
if err != nil {
t.Errorf("query tx Commit fail: %s", err)
}
err = query.Begin().Rollback()
if err != nil {
t.Errorf("query tx Rollback fail: %s", err)
}
}

View File

@ -0,0 +1,347 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/internal/gen/dao/model"
)
func newUser(db *gorm.DB, opts ...gen.DOOption) user {
_user := user{}
_user.userDo.UseDB(db, opts...)
_user.userDo.UseModel(&model.User{})
tableName := _user.userDo.TableName()
_user.ALL = field.NewAsterisk(tableName)
_user.ID = field.NewUint64(tableName, "id")
_user.IsNew = field.NewUint32(tableName, "is_new")
_user.Nickname = field.NewString(tableName, "nickname")
_user.Avatar = field.NewString(tableName, "avatar")
_user.CreatedAt = field.NewTime(tableName, "created_at")
_user.UpdatedAt = field.NewTime(tableName, "updated_at")
_user.fillFieldMap()
return _user
}
type user struct {
userDo userDo
ALL field.Asterisk
ID field.Uint64
IsNew field.Uint32
Nickname field.String // 昵称
Avatar field.String // 头像
CreatedAt field.Time // 创建时间
UpdatedAt field.Time // 更新时间
fieldMap map[string]field.Expr
}
func (u user) Table(newTableName string) *user {
u.userDo.UseTable(newTableName)
return u.updateTableName(newTableName)
}
func (u user) As(alias string) *user {
u.userDo.DO = *(u.userDo.As(alias).(*gen.DO))
return u.updateTableName(alias)
}
func (u *user) updateTableName(table string) *user {
u.ALL = field.NewAsterisk(table)
u.ID = field.NewUint64(table, "id")
u.IsNew = field.NewUint32(table, "is_new")
u.Nickname = field.NewString(table, "nickname")
u.Avatar = field.NewString(table, "avatar")
u.CreatedAt = field.NewTime(table, "created_at")
u.UpdatedAt = field.NewTime(table, "updated_at")
u.fillFieldMap()
return u
}
func (u *user) WithContext(ctx context.Context) *userDo { return u.userDo.WithContext(ctx) }
func (u user) TableName() string { return u.userDo.TableName() }
func (u user) Alias() string { return u.userDo.Alias() }
func (u user) Columns(cols ...field.Expr) gen.Columns { return u.userDo.Columns(cols...) }
func (u *user) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := u.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (u *user) fillFieldMap() {
u.fieldMap = make(map[string]field.Expr, 6)
u.fieldMap["id"] = u.ID
u.fieldMap["is_new"] = u.IsNew
u.fieldMap["nickname"] = u.Nickname
u.fieldMap["avatar"] = u.Avatar
u.fieldMap["created_at"] = u.CreatedAt
u.fieldMap["updated_at"] = u.UpdatedAt
}
func (u user) clone(db *gorm.DB) user {
u.userDo.ReplaceConnPool(db.Statement.ConnPool)
return u
}
func (u user) replaceDB(db *gorm.DB) user {
u.userDo.ReplaceDB(db)
return u
}
type userDo struct{ gen.DO }
func (u userDo) Debug() *userDo {
return u.withDO(u.DO.Debug())
}
func (u userDo) WithContext(ctx context.Context) *userDo {
return u.withDO(u.DO.WithContext(ctx))
}
func (u userDo) ReadDB() *userDo {
return u.Clauses(dbresolver.Read)
}
func (u userDo) WriteDB() *userDo {
return u.Clauses(dbresolver.Write)
}
func (u userDo) Session(config *gorm.Session) *userDo {
return u.withDO(u.DO.Session(config))
}
func (u userDo) Clauses(conds ...clause.Expression) *userDo {
return u.withDO(u.DO.Clauses(conds...))
}
func (u userDo) Returning(value interface{}, columns ...string) *userDo {
return u.withDO(u.DO.Returning(value, columns...))
}
func (u userDo) Not(conds ...gen.Condition) *userDo {
return u.withDO(u.DO.Not(conds...))
}
func (u userDo) Or(conds ...gen.Condition) *userDo {
return u.withDO(u.DO.Or(conds...))
}
func (u userDo) Select(conds ...field.Expr) *userDo {
return u.withDO(u.DO.Select(conds...))
}
func (u userDo) Where(conds ...gen.Condition) *userDo {
return u.withDO(u.DO.Where(conds...))
}
func (u userDo) Order(conds ...field.Expr) *userDo {
return u.withDO(u.DO.Order(conds...))
}
func (u userDo) Distinct(cols ...field.Expr) *userDo {
return u.withDO(u.DO.Distinct(cols...))
}
func (u userDo) Omit(cols ...field.Expr) *userDo {
return u.withDO(u.DO.Omit(cols...))
}
func (u userDo) Join(table schema.Tabler, on ...field.Expr) *userDo {
return u.withDO(u.DO.Join(table, on...))
}
func (u userDo) LeftJoin(table schema.Tabler, on ...field.Expr) *userDo {
return u.withDO(u.DO.LeftJoin(table, on...))
}
func (u userDo) RightJoin(table schema.Tabler, on ...field.Expr) *userDo {
return u.withDO(u.DO.RightJoin(table, on...))
}
func (u userDo) Group(cols ...field.Expr) *userDo {
return u.withDO(u.DO.Group(cols...))
}
func (u userDo) Having(conds ...gen.Condition) *userDo {
return u.withDO(u.DO.Having(conds...))
}
func (u userDo) Limit(limit int) *userDo {
return u.withDO(u.DO.Limit(limit))
}
func (u userDo) Offset(offset int) *userDo {
return u.withDO(u.DO.Offset(offset))
}
func (u userDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *userDo {
return u.withDO(u.DO.Scopes(funcs...))
}
func (u userDo) Unscoped() *userDo {
return u.withDO(u.DO.Unscoped())
}
func (u userDo) Create(values ...*model.User) error {
if len(values) == 0 {
return nil
}
return u.DO.Create(values)
}
func (u userDo) CreateInBatches(values []*model.User, batchSize int) error {
return u.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (u userDo) Save(values ...*model.User) error {
if len(values) == 0 {
return nil
}
return u.DO.Save(values)
}
func (u userDo) First() (*model.User, error) {
if result, err := u.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.User), nil
}
}
func (u userDo) Take() (*model.User, error) {
if result, err := u.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.User), nil
}
}
func (u userDo) Last() (*model.User, error) {
if result, err := u.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.User), nil
}
}
func (u userDo) Find() ([]*model.User, error) {
result, err := u.DO.Find()
return result.([]*model.User), err
}
func (u userDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.User, err error) {
buf := make([]*model.User, 0, batchSize)
err = u.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
})
return results, err
}
func (u userDo) FindInBatches(result *[]*model.User, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return u.DO.FindInBatches(result, batchSize, fc)
}
func (u userDo) Attrs(attrs ...field.AssignExpr) *userDo {
return u.withDO(u.DO.Attrs(attrs...))
}
func (u userDo) Assign(attrs ...field.AssignExpr) *userDo {
return u.withDO(u.DO.Assign(attrs...))
}
func (u userDo) Joins(fields ...field.RelationField) *userDo {
for _, _f := range fields {
u = *u.withDO(u.DO.Joins(_f))
}
return &u
}
func (u userDo) Preload(fields ...field.RelationField) *userDo {
for _, _f := range fields {
u = *u.withDO(u.DO.Preload(_f))
}
return &u
}
func (u userDo) FirstOrInit() (*model.User, error) {
if result, err := u.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.User), nil
}
}
func (u userDo) FirstOrCreate() (*model.User, error) {
if result, err := u.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.User), nil
}
}
func (u userDo) FindByPage(offset int, limit int) (result []*model.User, count int64, err error) {
result, err = u.Offset(offset).Limit(limit).Find()
if err != nil {
return
}
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size + offset)
return
}
count, err = u.Offset(-1).Limit(-1).Count()
return
}
func (u userDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = u.Count()
if err != nil {
return
}
err = u.Offset(offset).Limit(limit).Scan(result)
return
}
func (u userDo) Scan(result interface{}) (err error) {
return u.DO.Scan(result)
}
func (u userDo) Delete(models ...*model.User) (result gen.ResultInfo, err error) {
return u.DO.Delete(models)
}
func (u *userDo) withDO(do gen.Dao) *userDo {
u.DO = *do.(*gen.DO)
return u
}

View File

@ -0,0 +1,145 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"fmt"
"testing"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/internal/gen/dao/model"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm/clause"
)
func init() {
InitializeDB()
err := _gen_test_db.AutoMigrate(&model.User{})
if err != nil {
fmt.Printf("Error: AutoMigrate(&model.User{}) fail: %s", err)
}
}
func Test_userQuery(t *testing.T) {
user := newUser(_gen_test_db)
user = *user.As(user.TableName())
_do := user.WithContext(context.Background()).Debug()
primaryKey := field.NewString(user.TableName(), clause.PrimaryKey)
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
if err != nil {
t.Error("clean table <user> fail:", err)
return
}
_, ok := user.GetFieldByName("")
if ok {
t.Error("GetFieldByName(\"\") from user success")
}
err = _do.Create(&model.User{})
if err != nil {
t.Error("create item in table <user> fail:", err)
}
err = _do.Save(&model.User{})
if err != nil {
t.Error("create item in table <user> fail:", err)
}
err = _do.CreateInBatches([]*model.User{{}, {}}, 10)
if err != nil {
t.Error("create item in table <user> fail:", err)
}
_, err = _do.Select(user.ALL).Take()
if err != nil {
t.Error("Take() on table <user> fail:", err)
}
_, err = _do.First()
if err != nil {
t.Error("First() on table <user> fail:", err)
}
_, err = _do.Last()
if err != nil {
t.Error("First() on table <user> fail:", err)
}
_, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil })
if err != nil {
t.Error("FindInBatch() on table <user> fail:", err)
}
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*model.User{}, 10, func(tx gen.Dao, batch int) error { return nil })
if err != nil {
t.Error("FindInBatches() on table <user> fail:", err)
}
_, err = _do.Select(user.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
if err != nil {
t.Error("Find() on table <user> fail:", err)
}
_, err = _do.Distinct(primaryKey).Take()
if err != nil {
t.Error("select Distinct() on table <user> fail:", err)
}
_, err = _do.Select(user.ALL).Omit(primaryKey).Take()
if err != nil {
t.Error("Omit() on table <user> fail:", err)
}
_, err = _do.Group(primaryKey).Find()
if err != nil {
t.Error("Group() on table <user> fail:", err)
}
_, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find()
if err != nil {
t.Error("Scopes() on table <user> fail:", err)
}
_, _, err = _do.FindByPage(0, 1)
if err != nil {
t.Error("FindByPage() on table <user> fail:", err)
}
_, err = _do.ScanByPage(&model.User{}, 0, 1)
if err != nil {
t.Error("ScanByPage() on table <user> fail:", err)
}
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
if err != nil {
t.Error("FirstOrInit() on table <user> fail:", err)
}
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
if err != nil {
t.Error("FirstOrCreate() on table <user> fail:", err)
}
var _a _another
var _aPK = field.NewString(_a.TableName(), "id")
err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
if err != nil {
t.Error("Join() on table <user> fail:", err)
}
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
if err != nil {
t.Error("LeftJoin() on table <user> fail:", err)
}
_, err = _do.Not().Or().Clauses().Take()
if err != nil {
t.Error("Not/Or/Clauses on table <user> fail:", err)
}
}

View File

@ -0,0 +1,14 @@
version: "0.1"
database:
dsn : "root:youtu!0113@tcp(192.168.0.47:3306)/ecpm?charset=utf8mb4&parseTime=True&loc=Local"
db : "mysql"
tables :
- "user"
outPath : "./dao/query"
outFile : ""
withUnitTest : true
modelPkgName : "model"
fieldNullable : true
fieldWithIndexTag : true
fieldWithTypeTag : true
fieldSignable : true

View File

@ -0,0 +1,39 @@
package logic
import (
"context"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/internal/gen/dao/model"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/user"
"github.com/zeromicro/go-zero/core/logx"
)
type CreateEmptyUserLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCreateEmptyUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateEmptyUserLogic {
return &CreateEmptyUserLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *CreateEmptyUserLogic) CreateEmptyUser(_ *user.Empty) (*user.UserId, error) {
userId, err := l.svcCtx.IDGen.NextID()
if err != nil {
return nil, err
}
err = l.svcCtx.Query.User.WithContext(l.ctx).Create(&model.User{
ID: userId,
})
if err != nil {
return nil, err
}
return &user.UserId{UserId: userId}, nil
}

View File

@ -0,0 +1,43 @@
package logic
import (
"context"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/internal/gen/dao/model"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/user"
"github.com/zeromicro/go-zero/core/logx"
)
type CreateUserLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCreateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateUserLogic {
return &CreateUserLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// CreateUser 创建用户
func (l *CreateUserLogic) CreateUser(in *user.CreateUserRequest) (res *user.UserId, err error) {
userQ := l.svcCtx.Query.User
userModel := model.User{
Nickname: in.Nickname,
Avatar: in.Avatar,
}
userModel.ID, err = l.svcCtx.IDGen.NextID()
if err != nil {
return nil, err
}
err = userQ.WithContext(l.ctx).Create(&userModel)
if err != nil {
return nil, err
}
return &user.UserId{UserId: userModel.ID}, nil
}

View File

@ -0,0 +1,38 @@
package logic
import (
"context"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/user"
"github.com/zeromicro/go-zero/core/logx"
)
type FindByIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewFindByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FindByIdLogic {
return &FindByIdLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// FindById 创建用户或者获取用户
func (l *FindByIdLogic) FindById(in *user.UserId) (*user.User, error) {
userModel, err := l.svcCtx.Query.User.WithContext(l.ctx).Where(l.svcCtx.Query.User.ID.Eq(in.GetUserId())).FirstOrCreate()
if err != nil {
return nil, err
}
return &user.User{
ID: userModel.ID,
Nickname: userModel.Nickname,
Avatar: userModel.Avatar,
IsNew: userModel.IsNew == 1,
}, nil
}

View File

@ -0,0 +1,44 @@
package logic
import (
"context"
"errors"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/user"
"github.com/zeromicro/go-zero/core/logx"
)
type GetUserByIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetUserByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserByIdLogic {
return &GetUserByIdLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// GetUserById 通过 ID 获取用户
func (l *GetUserByIdLogic) GetUserById(in *user.UserId) (*user.User, error) {
if in.GetUserId() == 0 {
return &user.User{}, errors.New("userId is empty")
}
userModel, err := l.svcCtx.Query.User.WithContext(l.ctx).Where(l.svcCtx.Query.User.ID.Eq(in.UserId)).First()
if err != nil {
return &user.User{}, err
}
return &user.User{
ID: userModel.ID,
Nickname: userModel.Nickname,
Avatar: userModel.Avatar,
}, nil
}

View File

@ -0,0 +1,63 @@
package logic
import (
"context"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/user"
"github.com/zeromicro/go-zero/core/logx"
)
type GetUserIdsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetUserIdsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserIdsLogic {
return &GetUserIdsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// GetUserIds 通过 ID 获取用户
func (l *GetUserIdsLogic) GetUserIds(in *user.UserIds) (res *user.UserList, err error) {
if len(in.UserId) == 0 {
return nil, nil
}
userQuery := l.svcCtx.Query.User
users, err := userQuery.WithContext(l.ctx).Where(userQuery.ID.In(in.UserId...)).Find()
if err != nil {
return nil, err
}
var uMap = make(map[uint64]int)
for i := range users {
uMap[users[i].ID] = i
}
list := make([]*user.User, 0, len(users))
for _, id := range in.UserId {
i, ok := uMap[id]
var userModel *user.User
if ok {
userModel = &user.User{
ID: users[i].ID,
Nickname: users[i].Nickname,
Avatar: users[i].Avatar,
IsNew: users[i].IsNew == 1,
}
} else {
userModel = &user.User{ID: id}
}
list = append(list, userModel)
}
res = &user.UserList{
UserList: list,
}
return
}

View File

@ -2,8 +2,8 @@ package logic
import (
"context"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/internal/svc"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/user_management"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/user"
"github.com/zeromicro/go-zero/core/logx"
)
@ -22,8 +22,6 @@ func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
}
}
func (l *PingLogic) Ping(in *user_management.Request) (*user_management.Response, error) {
// todo: add your logic here and delete this line
return &user_management.Response{}, nil
func (l *PingLogic) Ping(in *user.Request) (*user.Response, error) {
return &user.Response{Pong: in.Ping}, nil
}

Some files were not shown because too many files have changed in this diff Show More