Browse Source

v0.0.1开发:auth服务开放

#Suyghur 2 years ago
parent
commit
4dd4f25959

+ 40 - 0
apis/auth/auth.go

@@ -0,0 +1,40 @@
+package main
+
+import (
+	"flag"
+	"fmt"
+
+	"ylink/apis/auth/internal/config"
+	"ylink/apis/auth/internal/server"
+	"ylink/apis/auth/internal/svc"
+	"ylink/apis/auth/pb"
+
+	"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.yaml", "the config file")
+
+func main() {
+	flag.Parse()
+
+	var c config.Config
+	conf.MustLoad(*configFile, &c)
+	ctx := svc.NewServiceContext(c)
+	svr := server.NewAuthServer(ctx)
+
+	s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
+		pb.RegisterAuthServer(grpcServer, svr)
+
+		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()
+}

+ 52 - 0
apis/auth/auth/auth.go

@@ -0,0 +1,52 @@
+// Code generated by goctl. DO NOT EDIT!
+// Source: auth.proto
+
+package auth
+
+import (
+	"context"
+
+	"ylink/apis/auth/pb"
+
+	"github.com/zeromicro/go-zero/zrpc"
+	"google.golang.org/grpc"
+)
+
+type (
+	AuthReq       = pb.AuthReq
+	AuthResp      = pb.AuthResp
+	CheckAuthReq  = pb.CheckAuthReq
+	CsAuthReq     = pb.CsAuthReq
+	PlayerAuthReq = pb.PlayerAuthReq
+
+	Auth interface {
+		PlayerAuth(ctx context.Context, in *PlayerAuthReq, opts ...grpc.CallOption) (*AuthResp, error)
+		CsAuth(ctx context.Context, in *CsAuthReq, opts ...grpc.CallOption) (*AuthResp, error)
+		CheckAuth(ctx context.Context, in *CheckAuthReq, opts ...grpc.CallOption) (*AuthResp, error)
+	}
+
+	defaultAuth struct {
+		cli zrpc.Client
+	}
+)
+
+func NewAuth(cli zrpc.Client) Auth {
+	return &defaultAuth{
+		cli: cli,
+	}
+}
+
+func (m *defaultAuth) PlayerAuth(ctx context.Context, in *PlayerAuthReq, opts ...grpc.CallOption) (*AuthResp, error) {
+	client := pb.NewAuthClient(m.cli.Conn())
+	return client.PlayerAuth(ctx, in, opts...)
+}
+
+func (m *defaultAuth) CsAuth(ctx context.Context, in *CsAuthReq, opts ...grpc.CallOption) (*AuthResp, error) {
+	client := pb.NewAuthClient(m.cli.Conn())
+	return client.CsAuth(ctx, in, opts...)
+}
+
+func (m *defaultAuth) CheckAuth(ctx context.Context, in *CheckAuthReq, opts ...grpc.CallOption) (*AuthResp, error) {
+	client := pb.NewAuthClient(m.cli.Conn())
+	return client.CheckAuth(ctx, in, opts...)
+}

+ 6 - 0
apis/auth/etc/auth.yaml

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

+ 7 - 0
apis/auth/internal/config/config.go

@@ -0,0 +1,7 @@
+package config
+
+import "github.com/zeromicro/go-zero/zrpc"
+
+type Config struct {
+	zrpc.RpcServerConf
+}

+ 30 - 0
apis/auth/internal/logic/checkauthlogic.go

@@ -0,0 +1,30 @@
+package logic
+
+import (
+	"context"
+
+	"ylink/apis/auth/internal/svc"
+	"ylink/apis/auth/pb"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type CheckAuthLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewCheckAuthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckAuthLogic {
+	return &CheckAuthLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *CheckAuthLogic) CheckAuth(in *pb.CheckAuthReq) (*pb.AuthResp, error) {
+	// todo: add your logic here and delete this line
+
+	return &pb.AuthResp{}, nil
+}

+ 50 - 0
apis/auth/internal/logic/csauthlogic.go

@@ -0,0 +1,50 @@
+package logic
+
+import (
+	"context"
+	"google.golang.org/protobuf/types/known/structpb"
+
+	"ylink/apis/auth/internal/svc"
+	"ylink/apis/auth/pb"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type CsAuthLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewCsAuthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CsAuthLogic {
+	return &CsAuthLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *CsAuthLogic) CsAuth(in *pb.CsAuthReq) (*pb.AuthResp, error) {
+	l.Logger.Info("invoke func CsAuth...")
+	l.Logger.Infof("uname: %s", in.Uname)
+	l.Logger.Infof("password: %s", in.Password)
+
+	// todo 查询用户信息
+	// todo 生成token
+	if data, err := structpb.NewStruct(map[string]interface{}{
+		"token":         "cs_auth",
+		"basic_rpc_url": "https://www.baidu.com",
+	}); err != nil {
+		return &pb.AuthResp{
+			Code: 1,
+			Msg:  err.Error(),
+			Data: nil,
+		}, err
+	} else {
+		return &pb.AuthResp{
+			Code: 0,
+			Msg:  "success",
+			Data: data,
+		}, nil
+	}
+}

+ 53 - 0
apis/auth/internal/logic/playerauthlogic.go

@@ -0,0 +1,53 @@
+package logic
+
+import (
+	"context"
+	"google.golang.org/protobuf/types/known/structpb"
+
+	"ylink/apis/auth/internal/svc"
+	"ylink/apis/auth/pb"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type PlayerAuthLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewPlayerAuthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PlayerAuthLogic {
+	return &PlayerAuthLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *PlayerAuthLogic) PlayerAuth(in *pb.PlayerAuthReq) (*pb.AuthResp, error) {
+
+	l.Logger.Info("invoke func PlayerAuth...")
+	l.Logger.Infof("player_id: %s", in.PlayerId)
+	l.Logger.Infof("game_id: %s", in.GameId)
+
+	// todo 查询用户信息
+	// todo 生成token
+	if data, err := structpb.NewStruct(map[string]interface{}{
+		"token":         "player_auth",
+		"has_own_cs":    1,
+		"cs_id":         "cs1231",
+		"basic_rpc_url": "https://www.baidu.com",
+	}); err != nil {
+		return &pb.AuthResp{
+			Code: 1,
+			Msg:  err.Error(),
+			Data: nil,
+		}, err
+	} else {
+		return &pb.AuthResp{
+			Code: 0,
+			Msg:  "success",
+			Data: data,
+		}, nil
+	}
+}

+ 38 - 0
apis/auth/internal/server/authserver.go

@@ -0,0 +1,38 @@
+// Code generated by goctl. DO NOT EDIT!
+// Source: auth.proto
+
+package server
+
+import (
+	"context"
+
+	"ylink/apis/auth/internal/logic"
+	"ylink/apis/auth/internal/svc"
+	"ylink/apis/auth/pb"
+)
+
+type AuthServer struct {
+	svcCtx *svc.ServiceContext
+	pb.UnimplementedAuthServer
+}
+
+func NewAuthServer(svcCtx *svc.ServiceContext) *AuthServer {
+	return &AuthServer{
+		svcCtx: svcCtx,
+	}
+}
+
+func (s *AuthServer) PlayerAuth(ctx context.Context, in *pb.PlayerAuthReq) (*pb.AuthResp, error) {
+	l := logic.NewPlayerAuthLogic(ctx, s.svcCtx)
+	return l.PlayerAuth(in)
+}
+
+func (s *AuthServer) CsAuth(ctx context.Context, in *pb.CsAuthReq) (*pb.AuthResp, error) {
+	l := logic.NewCsAuthLogic(ctx, s.svcCtx)
+	return l.CsAuth(in)
+}
+
+func (s *AuthServer) CheckAuth(ctx context.Context, in *pb.CheckAuthReq) (*pb.AuthResp, error) {
+	l := logic.NewCheckAuthLogic(ctx, s.svcCtx)
+	return l.CheckAuth(in)
+}

+ 13 - 0
apis/auth/internal/svc/servicecontext.go

@@ -0,0 +1,13 @@
+package svc
+
+import "ylink/apis/auth/internal/config"
+
+type ServiceContext struct {
+	Config config.Config
+}
+
+func NewServiceContext(c config.Config) *ServiceContext {
+	return &ServiceContext{
+		Config: c,
+	}
+}

+ 451 - 0
apis/auth/pb/auth.pb.go

@@ -0,0 +1,451 @@
+// Code generated by protoc-gen-go. DO NOT EDIT.
+// versions:
+// 	protoc-gen-go v1.28.0
+// 	protoc        v3.19.4
+// source: pb/auth.proto
+
+package pb
+
+import (
+	protoreflect "google.golang.org/protobuf/reflect/protoreflect"
+	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
+	structpb "google.golang.org/protobuf/types/known/structpb"
+	reflect "reflect"
+	sync "sync"
+)
+
+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 AuthReq struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	Data *structpb.Struct `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
+}
+
+func (x *AuthReq) Reset() {
+	*x = AuthReq{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_pb_auth_proto_msgTypes[0]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *AuthReq) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*AuthReq) ProtoMessage() {}
+
+func (x *AuthReq) ProtoReflect() protoreflect.Message {
+	mi := &file_pb_auth_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use AuthReq.ProtoReflect.Descriptor instead.
+func (*AuthReq) Descriptor() ([]byte, []int) {
+	return file_pb_auth_proto_rawDescGZIP(), []int{0}
+}
+
+func (x *AuthReq) GetData() *structpb.Struct {
+	if x != nil {
+		return x.Data
+	}
+	return nil
+}
+
+type PlayerAuthReq struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	PlayerId string `protobuf:"bytes,1,opt,name=player_id,json=playerId,proto3" json:"player_id,omitempty"`
+	GameId   string `protobuf:"bytes,2,opt,name=game_id,json=gameId,proto3" json:"game_id,omitempty"`
+}
+
+func (x *PlayerAuthReq) Reset() {
+	*x = PlayerAuthReq{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_pb_auth_proto_msgTypes[1]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *PlayerAuthReq) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*PlayerAuthReq) ProtoMessage() {}
+
+func (x *PlayerAuthReq) ProtoReflect() protoreflect.Message {
+	mi := &file_pb_auth_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use PlayerAuthReq.ProtoReflect.Descriptor instead.
+func (*PlayerAuthReq) Descriptor() ([]byte, []int) {
+	return file_pb_auth_proto_rawDescGZIP(), []int{1}
+}
+
+func (x *PlayerAuthReq) GetPlayerId() string {
+	if x != nil {
+		return x.PlayerId
+	}
+	return ""
+}
+
+func (x *PlayerAuthReq) GetGameId() string {
+	if x != nil {
+		return x.GameId
+	}
+	return ""
+}
+
+type CsAuthReq struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	Uname    string `protobuf:"bytes,1,opt,name=uname,proto3" json:"uname,omitempty"`
+	Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"`
+}
+
+func (x *CsAuthReq) Reset() {
+	*x = CsAuthReq{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_pb_auth_proto_msgTypes[2]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *CsAuthReq) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*CsAuthReq) ProtoMessage() {}
+
+func (x *CsAuthReq) ProtoReflect() protoreflect.Message {
+	mi := &file_pb_auth_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use CsAuthReq.ProtoReflect.Descriptor instead.
+func (*CsAuthReq) Descriptor() ([]byte, []int) {
+	return file_pb_auth_proto_rawDescGZIP(), []int{2}
+}
+
+func (x *CsAuthReq) GetUname() string {
+	if x != nil {
+		return x.Uname
+	}
+	return ""
+}
+
+func (x *CsAuthReq) GetPassword() string {
+	if x != nil {
+		return x.Password
+	}
+	return ""
+}
+
+type CheckAuthReq struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"`
+}
+
+func (x *CheckAuthReq) Reset() {
+	*x = CheckAuthReq{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_pb_auth_proto_msgTypes[3]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *CheckAuthReq) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*CheckAuthReq) ProtoMessage() {}
+
+func (x *CheckAuthReq) ProtoReflect() protoreflect.Message {
+	mi := &file_pb_auth_proto_msgTypes[3]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use CheckAuthReq.ProtoReflect.Descriptor instead.
+func (*CheckAuthReq) Descriptor() ([]byte, []int) {
+	return file_pb_auth_proto_rawDescGZIP(), []int{3}
+}
+
+func (x *CheckAuthReq) GetToken() string {
+	if x != nil {
+		return x.Token
+	}
+	return ""
+}
+
+type AuthResp struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	Code int64            `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
+	Msg  string           `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"`
+	Data *structpb.Struct `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"`
+}
+
+func (x *AuthResp) Reset() {
+	*x = AuthResp{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_pb_auth_proto_msgTypes[4]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *AuthResp) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*AuthResp) ProtoMessage() {}
+
+func (x *AuthResp) ProtoReflect() protoreflect.Message {
+	mi := &file_pb_auth_proto_msgTypes[4]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use AuthResp.ProtoReflect.Descriptor instead.
+func (*AuthResp) Descriptor() ([]byte, []int) {
+	return file_pb_auth_proto_rawDescGZIP(), []int{4}
+}
+
+func (x *AuthResp) GetCode() int64 {
+	if x != nil {
+		return x.Code
+	}
+	return 0
+}
+
+func (x *AuthResp) GetMsg() string {
+	if x != nil {
+		return x.Msg
+	}
+	return ""
+}
+
+func (x *AuthResp) GetData() *structpb.Struct {
+	if x != nil {
+		return x.Data
+	}
+	return nil
+}
+
+var File_pb_auth_proto protoreflect.FileDescriptor
+
+var file_pb_auth_proto_rawDesc = []byte{
+	0x0a, 0x0d, 0x70, 0x62, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12,
+	0x02, 0x70, 0x62, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74,
+	0x6f, 0x62, 0x75, 0x66, 0x2f, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74,
+	0x6f, 0x22, 0x36, 0x0a, 0x07, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x71, 0x12, 0x2b, 0x0a, 0x04,
+	0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x67, 0x6f, 0x6f,
+	0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72,
+	0x75, 0x63, 0x74, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x45, 0x0a, 0x0d, 0x50, 0x6c, 0x61,
+	0x79, 0x65, 0x72, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x71, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x6c,
+	0x61, 0x79, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70,
+	0x6c, 0x61, 0x79, 0x65, 0x72, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x67, 0x61, 0x6d, 0x65, 0x5f,
+	0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x67, 0x61, 0x6d, 0x65, 0x49, 0x64,
+	0x22, 0x3d, 0x0a, 0x09, 0x43, 0x73, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x71, 0x12, 0x14, 0x0a,
+	0x05, 0x75, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x75, 0x6e,
+	0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18,
+	0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22,
+	0x24, 0x0a, 0x0c, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x71, 0x12,
+	0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05,
+	0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x5d, 0x0a, 0x08, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x73,
+	0x70, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52,
+	0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01,
+	0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x12, 0x2b, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18,
+	0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70,
+	0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x52, 0x04,
+	0x64, 0x61, 0x74, 0x61, 0x32, 0x89, 0x01, 0x0a, 0x04, 0x41, 0x75, 0x74, 0x68, 0x12, 0x2d, 0x0a,
+	0x0a, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x41, 0x75, 0x74, 0x68, 0x12, 0x11, 0x2e, 0x70, 0x62,
+	0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x71, 0x1a, 0x0c,
+	0x2e, 0x70, 0x62, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x73, 0x70, 0x12, 0x25, 0x0a, 0x06,
+	0x63, 0x73, 0x41, 0x75, 0x74, 0x68, 0x12, 0x0d, 0x2e, 0x70, 0x62, 0x2e, 0x43, 0x73, 0x41, 0x75,
+	0x74, 0x68, 0x52, 0x65, 0x71, 0x1a, 0x0c, 0x2e, 0x70, 0x62, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x52,
+	0x65, 0x73, 0x70, 0x12, 0x2b, 0x0a, 0x09, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x41, 0x75, 0x74, 0x68,
+	0x12, 0x10, 0x2e, 0x70, 0x62, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x41, 0x75, 0x74, 0x68, 0x52,
+	0x65, 0x71, 0x1a, 0x0c, 0x2e, 0x70, 0x62, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x73, 0x70,
+	0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+}
+
+var (
+	file_pb_auth_proto_rawDescOnce sync.Once
+	file_pb_auth_proto_rawDescData = file_pb_auth_proto_rawDesc
+)
+
+func file_pb_auth_proto_rawDescGZIP() []byte {
+	file_pb_auth_proto_rawDescOnce.Do(func() {
+		file_pb_auth_proto_rawDescData = protoimpl.X.CompressGZIP(file_pb_auth_proto_rawDescData)
+	})
+	return file_pb_auth_proto_rawDescData
+}
+
+var file_pb_auth_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
+var file_pb_auth_proto_goTypes = []interface{}{
+	(*AuthReq)(nil),         // 0: pb.AuthReq
+	(*PlayerAuthReq)(nil),   // 1: pb.PlayerAuthReq
+	(*CsAuthReq)(nil),       // 2: pb.CsAuthReq
+	(*CheckAuthReq)(nil),    // 3: pb.CheckAuthReq
+	(*AuthResp)(nil),        // 4: pb.AuthResp
+	(*structpb.Struct)(nil), // 5: google.protobuf.Struct
+}
+var file_pb_auth_proto_depIdxs = []int32{
+	5, // 0: pb.AuthReq.data:type_name -> google.protobuf.Struct
+	5, // 1: pb.AuthResp.data:type_name -> google.protobuf.Struct
+	1, // 2: pb.Auth.playerAuth:input_type -> pb.PlayerAuthReq
+	2, // 3: pb.Auth.csAuth:input_type -> pb.CsAuthReq
+	3, // 4: pb.Auth.checkAuth:input_type -> pb.CheckAuthReq
+	4, // 5: pb.Auth.playerAuth:output_type -> pb.AuthResp
+	4, // 6: pb.Auth.csAuth:output_type -> pb.AuthResp
+	4, // 7: pb.Auth.checkAuth:output_type -> pb.AuthResp
+	5, // [5:8] is the sub-list for method output_type
+	2, // [2:5] is the sub-list for method input_type
+	2, // [2:2] is the sub-list for extension type_name
+	2, // [2:2] is the sub-list for extension extendee
+	0, // [0:2] is the sub-list for field type_name
+}
+
+func init() { file_pb_auth_proto_init() }
+func file_pb_auth_proto_init() {
+	if File_pb_auth_proto != nil {
+		return
+	}
+	if !protoimpl.UnsafeEnabled {
+		file_pb_auth_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*AuthReq); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
+		file_pb_auth_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*PlayerAuthReq); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
+		file_pb_auth_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*CsAuthReq); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
+		file_pb_auth_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*CheckAuthReq); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
+		file_pb_auth_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*AuthResp); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
+	}
+	type x struct{}
+	out := protoimpl.TypeBuilder{
+		File: protoimpl.DescBuilder{
+			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
+			RawDescriptor: file_pb_auth_proto_rawDesc,
+			NumEnums:      0,
+			NumMessages:   5,
+			NumExtensions: 0,
+			NumServices:   1,
+		},
+		GoTypes:           file_pb_auth_proto_goTypes,
+		DependencyIndexes: file_pb_auth_proto_depIdxs,
+		MessageInfos:      file_pb_auth_proto_msgTypes,
+	}.Build()
+	File_pb_auth_proto = out.File
+	file_pb_auth_proto_rawDesc = nil
+	file_pb_auth_proto_goTypes = nil
+	file_pb_auth_proto_depIdxs = nil
+}

+ 21 - 3
apis/auth/pb/auth.proto

@@ -6,6 +6,24 @@ package pb;
 
 import "google/protobuf/struct.proto";
 
+message AuthReq{
+  google.protobuf.Struct data = 1;
+}
+
+message PlayerAuthReq{
+  string player_id = 1;
+  string game_id = 2;
+}
+
+message CsAuthReq{
+  string uname = 1;
+  string password = 2;
+}
+
+message CheckAuthReq{
+  string  token = 1;
+}
+
 message AuthResp{
   int64 code = 1;
   string msg = 2;
@@ -13,7 +31,7 @@ message AuthResp{
 }
 
 service Auth{
-  rpc playerAuth (google.protobuf.Struct) returns (AuthResp);
-  rpc csAuth (google.protobuf.Struct) returns (AuthResp);
-  rpc checkAuth (google.protobuf.Struct) returns (AuthResp);
+  rpc playerAuth (PlayerAuthReq) returns (AuthResp);
+  rpc csAuth (CsAuthReq) returns (AuthResp);
+  rpc checkAuth (CheckAuthReq) returns (AuthResp);
 }

+ 177 - 0
apis/auth/pb/auth_grpc.pb.go

@@ -0,0 +1,177 @@
+// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
+// versions:
+// - protoc-gen-go-grpc v1.2.0
+// - protoc             v3.19.4
+// source: pb/auth.proto
+
+package pb
+
+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.32.0 or later.
+const _ = grpc.SupportPackageIsVersion7
+
+// AuthClient is the client API for Auth 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 AuthClient interface {
+	PlayerAuth(ctx context.Context, in *PlayerAuthReq, opts ...grpc.CallOption) (*AuthResp, error)
+	CsAuth(ctx context.Context, in *CsAuthReq, opts ...grpc.CallOption) (*AuthResp, error)
+	CheckAuth(ctx context.Context, in *CheckAuthReq, opts ...grpc.CallOption) (*AuthResp, error)
+}
+
+type authClient struct {
+	cc grpc.ClientConnInterface
+}
+
+func NewAuthClient(cc grpc.ClientConnInterface) AuthClient {
+	return &authClient{cc}
+}
+
+func (c *authClient) PlayerAuth(ctx context.Context, in *PlayerAuthReq, opts ...grpc.CallOption) (*AuthResp, error) {
+	out := new(AuthResp)
+	err := c.cc.Invoke(ctx, "/pb.Auth/playerAuth", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+func (c *authClient) CsAuth(ctx context.Context, in *CsAuthReq, opts ...grpc.CallOption) (*AuthResp, error) {
+	out := new(AuthResp)
+	err := c.cc.Invoke(ctx, "/pb.Auth/csAuth", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+func (c *authClient) CheckAuth(ctx context.Context, in *CheckAuthReq, opts ...grpc.CallOption) (*AuthResp, error) {
+	out := new(AuthResp)
+	err := c.cc.Invoke(ctx, "/pb.Auth/checkAuth", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+// AuthServer is the server API for Auth service.
+// All implementations must embed UnimplementedAuthServer
+// for forward compatibility
+type AuthServer interface {
+	PlayerAuth(context.Context, *PlayerAuthReq) (*AuthResp, error)
+	CsAuth(context.Context, *CsAuthReq) (*AuthResp, error)
+	CheckAuth(context.Context, *CheckAuthReq) (*AuthResp, error)
+	mustEmbedUnimplementedAuthServer()
+}
+
+// UnimplementedAuthServer must be embedded to have forward compatible implementations.
+type UnimplementedAuthServer struct {
+}
+
+func (UnimplementedAuthServer) PlayerAuth(context.Context, *PlayerAuthReq) (*AuthResp, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method PlayerAuth not implemented")
+}
+func (UnimplementedAuthServer) CsAuth(context.Context, *CsAuthReq) (*AuthResp, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method CsAuth not implemented")
+}
+func (UnimplementedAuthServer) CheckAuth(context.Context, *CheckAuthReq) (*AuthResp, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method CheckAuth not implemented")
+}
+func (UnimplementedAuthServer) mustEmbedUnimplementedAuthServer() {}
+
+// UnsafeAuthServer may be embedded to opt out of forward compatibility for this service.
+// Use of this interface is not recommended, as added methods to AuthServer will
+// result in compilation errors.
+type UnsafeAuthServer interface {
+	mustEmbedUnimplementedAuthServer()
+}
+
+func RegisterAuthServer(s grpc.ServiceRegistrar, srv AuthServer) {
+	s.RegisterService(&Auth_ServiceDesc, srv)
+}
+
+func _Auth_PlayerAuth_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(PlayerAuthReq)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(AuthServer).PlayerAuth(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/pb.Auth/playerAuth",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(AuthServer).PlayerAuth(ctx, req.(*PlayerAuthReq))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+func _Auth_CsAuth_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(CsAuthReq)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(AuthServer).CsAuth(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/pb.Auth/csAuth",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(AuthServer).CsAuth(ctx, req.(*CsAuthReq))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+func _Auth_CheckAuth_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(CheckAuthReq)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(AuthServer).CheckAuth(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/pb.Auth/checkAuth",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(AuthServer).CheckAuth(ctx, req.(*CheckAuthReq))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+// Auth_ServiceDesc is the grpc.ServiceDesc for Auth service.
+// It's only intended for direct use with grpc.RegisterService,
+// and not to be introspected or modified (even as a copy)
+var Auth_ServiceDesc = grpc.ServiceDesc{
+	ServiceName: "pb.Auth",
+	HandlerType: (*AuthServer)(nil),
+	Methods: []grpc.MethodDesc{
+		{
+			MethodName: "playerAuth",
+			Handler:    _Auth_PlayerAuth_Handler,
+		},
+		{
+			MethodName: "csAuth",
+			Handler:    _Auth_CsAuth_Handler,
+		},
+		{
+			MethodName: "checkAuth",
+			Handler:    _Auth_CheckAuth_Handler,
+		},
+	},
+	Streams:  []grpc.StreamDesc{},
+	Metadata: "pb/auth.proto",
+}

+ 15 - 12
apis/cmd/pb/cmd.proto

@@ -6,6 +6,9 @@ package pb;
 
 import "google/protobuf/struct.proto";
 
+message CmdReq{
+  google.protobuf.Struct data = 1;
+}
 
 message CmdResp{
   int64 code = 1;
@@ -14,17 +17,17 @@ message CmdResp{
 }
 
 service Cmd {
-  rpc playerFetchCsInfo (google.protobuf.Struct) returns (CmdResp);
-  rpc playerFetchHistoryMsg (google.protobuf.Struct) returns (CmdResp);
-  rpc playerFetchMsg (google.protobuf.Struct) returns (CmdResp);
-  rpc playerSendMsg (google.protobuf.Struct) returns (CmdResp);
-  rpc playerDisconnect (google.protobuf.Struct) returns (CmdResp);
+  rpc playerFetchCsInfo (CmdReq) returns (CmdResp);
+  rpc playerFetchHistoryMsg (CmdReq) returns (CmdResp);
+  rpc playerFetchMsg (CmdReq) returns (CmdResp);
+  rpc playerSendMsg (CmdReq) returns (CmdResp);
+  rpc playerDisconnect (CmdReq) returns (CmdResp);
 
-  rpc csFetchPlayerInfo (google.protobuf.Struct) returns (CmdResp);
-  rpc csFetchPlayerQueue (google.protobuf.Struct) returns (CmdResp);
-  rpc csConnectPlayer (google.protobuf.Struct) returns (CmdResp);
-  rpc csFetchHistoryChat (google.protobuf.Struct) returns (CmdResp);
-  rpc csFetchHistoryMsg (google.protobuf.Struct) returns (CmdResp);
-  rpc csFetchMsg (google.protobuf.Struct) returns (CmdResp);
-  rpc csSendMsg (google.protobuf.Struct) returns (CmdResp);
+  rpc csFetchPlayerInfo (CmdReq) returns (CmdResp);
+  rpc csFetchPlayerQueue (CmdReq) returns (CmdResp);
+  rpc csConnectPlayer (CmdReq) returns (CmdResp);
+  rpc csFetchHistoryChat (CmdReq) returns (CmdResp);
+  rpc csFetchHistoryMsg (CmdReq) returns (CmdResp);
+  rpc csFetchMsg (CmdReq) returns (CmdResp);
+  rpc csSendMsg (CmdReq) returns (CmdResp);
 }

+ 2 - 2
bff/apibff/desc/bean.api

@@ -8,7 +8,7 @@ info(
 
 
 type CommResp {
-    Code int `json:"code"`
+    Code int64 `json:"code"`
     Msg string `json:"msg"`
     Data interface{} `json:"data"`
 }
@@ -36,7 +36,7 @@ type (
 
 type (
     CsAuthReq {
-        UserName string `json:"uname"`
+        Uname string `json:"uname"`
         Password string `json:"password"`
     }
 

+ 12 - 0
bff/apibff/etc/apibff.yaml

@@ -2,6 +2,18 @@ Name: apibff
 Host: 0.0.0.0
 Port: 10000
 
+AuthRpc:
+  Etcd:
+    Hosts:
+      - 127.0.0.1:2379
+    Key: auth.rpc
+
+#CmdRpc:
+#  Etcd:
+#    Hosts:
+#      - 127.0.0.1:2379
+#    Key: cmd.rpc
+
 Auth:
   AccessSecret: ylink2022
   AccessExpire: 259200

+ 5 - 1
bff/apibff/internal/config/config.go

@@ -1,6 +1,9 @@
 package config
 
-import "github.com/zeromicro/go-zero/rest"
+import (
+	"github.com/zeromicro/go-zero/rest"
+	"github.com/zeromicro/go-zero/zrpc"
+)
 
 type Config struct {
 	rest.RestConf
@@ -8,4 +11,5 @@ type Config struct {
 		AccessSecret string
 		AccessExpire int64
 	}
+	AuthRpc zrpc.RpcClientConf
 }

+ 17 - 3
bff/apibff/internal/logic/cs/auth/csauthlogic.go

@@ -2,6 +2,7 @@ package auth
 
 import (
 	"context"
+	"ylink/apis/auth/pb"
 
 	"ylink/bff/apibff/internal/svc"
 	"ylink/bff/apibff/internal/types"
@@ -24,7 +25,20 @@ func NewCsAuthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CsAuthLogi
 }
 
 func (l *CsAuthLogic) CsAuth(req *types.CsAuthReq) (resp *types.CommResp, err error) {
-	// todo: add your logic here and delete this line
-
-	return
+	if authResp, err := l.svcCtx.AuthRpc.CsAuth(l.ctx, &pb.CsAuthReq{
+		Uname:    req.Uname,
+		Password: req.Password,
+	}); err != nil {
+		return &types.CommResp{
+			Code: authResp.Code,
+			Msg:  "success",
+			Data: map[string]interface{}{},
+		}, err
+	} else {
+		return &types.CommResp{
+			Code: 0,
+			Msg:  "success",
+			Data: authResp.Data,
+		}, nil
+	}
 }

+ 17 - 3
bff/apibff/internal/logic/player/auth/playerauthlogic.go

@@ -2,6 +2,7 @@ package auth
 
 import (
 	"context"
+	"ylink/apis/auth/pb"
 
 	"ylink/bff/apibff/internal/svc"
 	"ylink/bff/apibff/internal/types"
@@ -24,7 +25,20 @@ func NewPlayerAuthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Player
 }
 
 func (l *PlayerAuthLogic) PlayerAuth(req *types.PlayerAuthReq) (resp *types.CommResp, err error) {
-	// todo: add your logic here and delete this line
-
-	return
+	if authResp, err := l.svcCtx.AuthRpc.PlayerAuth(l.ctx, &pb.PlayerAuthReq{
+		PlayerId: req.PlayerId,
+		GameId:   req.GameId,
+	}); err != nil {
+		return &types.CommResp{
+			Code: authResp.Code,
+			Msg:  "success",
+			Data: map[string]interface{}{},
+		}, err
+	} else {
+		return &types.CommResp{
+			Code: 0,
+			Msg:  "success",
+			Data: authResp.Data,
+		}, nil
+	}
 }

+ 6 - 2
bff/apibff/internal/svc/servicecontext.go

@@ -1,15 +1,19 @@
 package svc
 
 import (
+	"github.com/zeromicro/go-zero/zrpc"
+	"ylink/apis/auth/auth"
 	"ylink/bff/apibff/internal/config"
 )
 
 type ServiceContext struct {
-	Config config.Config
+	Config  config.Config
+	AuthRpc auth.Auth
 }
 
 func NewServiceContext(c config.Config) *ServiceContext {
 	return &ServiceContext{
-		Config: c,
+		Config:  c,
+		AuthRpc: auth.NewAuth(zrpc.MustNewClient(c.AuthRpc)),
 	}
 }

+ 2 - 2
bff/apibff/internal/types/types.go

@@ -2,7 +2,7 @@
 package types
 
 type CommResp struct {
-	Code int         `json:"code"`
+	Code int64       `json:"code"`
 	Msg  string      `json:"msg"`
 	Data interface{} `json:"data"`
 }
@@ -27,7 +27,7 @@ type PlayerSendMsgReq struct {
 }
 
 type CsAuthReq struct {
-	UserName string `json:"uname"`
+	Uname    string `json:"uname"`
 	Password string `json:"password"`
 }