Comments (4)
set export GODEBUG=http2debug=2 in shell, and got this in rpc_server main.go in cycle when run man.go:
....
2018/03/20 16:26:21 http2: Framer 0xc420c8c000: wrote SETTINGS len=0
2018/03/20 16:26:21 http2: Framer 0xc420ec8000: wrote SETTINGS len=0
2018/03/20 16:26:21 http2: Framer 0xc420ec82a0: wrote SETTINGS len=0
2018/03/20 16:26:21 http2: Framer 0xc420c8c460: wrote SETTINGS len=0
2018/03/20 16:26:21 http2: Framer 0xc420ec8620: wrote SETTINGS len=0
2018/03/20 16:26:21 http2: Framer 0xc420c8c000: wrote SETTINGS len=0
2018/03/20 16:26:21 http2: Framer 0xc420ec80e0: wrote SETTINGS len=0
2018/03/20 16:26:21 http2: Framer 0xc422758000: wrote SETTINGS len=0
...
...
from go-grpc-tutorial.
@JesseYan
It's normal when use http, I got this error too.
You can read my documentation about this project, I think this is because http2 requires https.
from go-grpc-tutorial.
@jergoo 我想应该不是http2的问题,我换了一种方式,同样用http,我用两个端口,分别分开用在server和gateway上,可以正常运行。server.go, gateway.go分别见如下:
//server/main.go
package main
import (
"net"
pb "proto/bi/service/httpsdemo"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
"log"
)
// 定义helloHTTPService并实现约定的接口
type helloHTTPService struct{}
// HelloHTTPService Hello HTTP服务
var HelloHTTPService = helloHTTPService{}
// SayHello 实现Hello服务接口
func (h helloHTTPService) SayHello(ctx context.Context, in *pb.HelloHTTPRequest) (*pb.HelloHTTPResponse, error) {
resp := new(pb.HelloHTTPResponse)
resp.Message = "Hello " + in.Name + "."
return resp, nil
}
func main() {
endpoint := "127.0.0.1:50051"
lis, err := net.Listen("tcp", endpoint)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
s := grpc.NewServer()
pb.RegisterHelloHTTPServer(s, &HelloHTTPService)
// Register reflection service on gRPC server.
reflection.Register(s)
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}
//gateway/main.go
package main
import (
"flag"
"net/http"
"github.com/golang/glog"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"golang.org/x/net/context"
"google.golang.org/grpc"
gw "proto/bi/service/httpsdemo"
)
var (
echoEndpoint = flag.String("echo_endpoint", "127.0.0.1:50051", "endpoint of YourService")
)
func run() error {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
mux := runtime.NewServeMux()
opts := []grpc.DialOption{grpc.WithInsecure()}
err := gw.RegisterHelloHTTPHandlerFromEndpoint(ctx, mux, *echoEndpoint, opts)
if err != nil {
return err
}
return http.ListenAndServe(":8888", mux)
}
func main() {
flag.Parse()
defer glog.Flush()
if err := run(); err != nil {
glog.Fatal(err)
}
}
curl -X POST -k http://127.0.0.1:8888/example/echo -d '{"name": "Jesse Yan"}'
from go-grpc-tutorial.
@JesseYan hello_http里面的示例就是分开做的,但是你注意下分开后的server.go,是不能直接用http请求的
from go-grpc-tutorial.
Related Issues (8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-grpc-tutorial.