43 lines
868 B
Go
43 lines
868 B
Go
package __
|
|
|
|
import (
|
|
"context"
|
|
"google.golang.org/grpc"
|
|
"log"
|
|
"net"
|
|
"qteam/app/utils"
|
|
"qteam/config"
|
|
)
|
|
|
|
// 服务定义
|
|
type UserServer struct{}
|
|
|
|
func (s *UserServer) GetUserByStuNumber(ctx context.Context, request *UserRequest) (*UserResponse, error) {
|
|
return &UserResponse{}, nil
|
|
}
|
|
|
|
func (s *UserServer) mustEmbedUnimplementedUserServiceServer() {
|
|
//TODO implement me
|
|
//panic("implement me")
|
|
}
|
|
func (s *UserServer) StartServer() *grpc.Server {
|
|
|
|
server := grpc.NewServer()
|
|
|
|
//注册服务
|
|
RegisterUserServiceServer(server, &UserServer{})
|
|
//启动监听程序
|
|
listener, err := net.Listen("tcp", config.GetConf().Rpc.User)
|
|
if err != nil {
|
|
log.Fatal("启动监听失败", err)
|
|
}
|
|
|
|
err = server.Serve(listener)
|
|
|
|
if err != nil {
|
|
log.Fatal("启动服务失败", err)
|
|
}
|
|
utils.Log(nil, "服务启动成功", config.GetConf().Rpc.User)
|
|
return server
|
|
}
|