Goravel 升级 v1.4,使微服务间请求更加简单一体化。No bb, show the code.
Goravel 是一个功能完备、具有良好扩展能力的 Golang Web 应用程序框架。风格与 Laravel 保持一致,让 PHPer 不用学习新的框架,也可以愉快的玩转 Golang!
func (r *UserController) GetUser(ctx context.Context, req *grpcuser.UserRequest) (*grpcuser.UserResponse, error) { return &grpcuser.UserResponse{Name: "Goravel"}, nil }
facades.Grpc.Run(facades.Config.GetString("grpc.host"))
facades.Config.Add("grpc", map[string]interface{}{ "clients": map[string]any{ "user": map[string]any{ "host": config.Env("GRPC_USER_HOST", ""), "interceptors": []string{"trace"}, }, }, })
func (r *ServiceImpl) GetUser(ctx context.Context, userID uint64) (*grpcuser.User, error) { // 创建客户端实例 client, _ := facades.Grpc.Client(ctx, "user") // 注册服务 userServiceClient := grpcuser.NewUserServiceClient(client) // 调用接口 resp, _ := userServiceClient.GetUser(ctx, &grpcuser.UserRequest{ UserID: userID, }) return resp.Data, nil }
Over, 欢迎 Star、PR、Issues!