小编Aec*_*ech的帖子

使用 golang 客户端的 GRPC Web 请求?

我正在尝试使用 grpc-web 包装器创建一个 grpc 服务器。这个想法是将此 grpc 服务器与基于浏览器的应用程序以及普通的 grpc 客户端一起使用。但我很困惑如何才能使其适用于这两个应用程序?

package main

import (
    "context"
    "fmt"
    "io"
    "log"
    "net/http"
    "strconv"
    "time"

    "github.com/repo/test-grpc-server/greet/greetpb"
    "github.com/improbable-eng/grpc-web/go/grpcweb"
    "google.golang.org/grpc"
)

type server struct{}

func (*server) Greet(ctx context.Context, req *greetpb.GreetRequest) (*greetpb.GreetResponse, error) {
    fmt.Printf("Greet function was invoked with %v", req)
    firstName := req.GetGreeting().GetFirstName()
    result := "Hello " + firstName
    res := greetpb.GreetResponse{
        Result: result,
    }
    return &res, nil
}

func (*server) GreetManyTimes(req *greetpb.GreetManyTimesRequest, stream greetpb.GreetService_GreetManyTimesServer) error {
    fmt.Printf("GreetMany function was invoked with %v", req)

    firstName := req.GetGreeting().GetFirstName() …
Run Code Online (Sandbox Code Playgroud)

go grpc grpc-web

4
推荐指数
1
解决办法
4295
查看次数

标签 统计

go ×1

grpc ×1

grpc-web ×1