Grpc's Simple Go example

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

GRPC is a high-performance, general-purpose, open-source RPC framework developed by Google primarily for mobile applications and based on the HTTP/2 protocol standards, developed based on the PROTOBUF (Protocol buffers) serialization protocol, and supports many development languages. GRPC provides an easy way to precisely define services and automatically generate a highly reliable client function library for iOS, Android, and background support services. Clients take advantage of advanced streaming and linking capabilities to help conserve bandwidth, reduce the number of TCP links, conserve CPU usage, and battery life.

The example you see here is from: Grpc in 3 minutes (Go)
Http://www.grpc.io/docs/installation/go.html

Get the code for the client and server side separately as follows:

$ go get -u github.com/grpc/grpc-common/go/greeter_client$ go get -u github.com/grpc/grpc-common/go/greeter_server

Powerful IDL features

GRPC uses PROTOBUF to define services, PROTOBUF is a data serialization protocol developed by Google (similar to XML, JSON, Hessian). Protobuf is capable of serializing data and is widely used in data storage, communication protocols, and so on.

In this example, the IDL file uses this: Https://github.com/grpc/grpc-common/blob/master/protos/helloworld.proto

We are here directly with go files that have been produced based on this proto file: Https://github.com/grpc/grpc-common/blob/master/go/helloworld/helloworld.pb.go We don't use PROTOC tools here.

Due to the wall, some of our dependent package files can be downloaded in the following ways:

On GitHub you can find the source code, download and copy to the corresponding directory:

GOOGLE.GOLANG.ORG/GRPC corresponding code address in: Https://github.com/grpc/grpc-go

Google.golang.org/cloud/compute/metadata corresponding code address in: Https://github.com/GoogleCloudPlatform/gcloud-golang

Golang.org/x/oauth2 corresponding code address in: Https://github.com/golang/oauth2

Golang.org/x/net/context corresponding code address in: Https://github.com/golang/net

The source code for these packages can also be downloaded via http://gopm.io/or http://golangtc.com/download/package.

Go get–a This command, the –a parameter is the go install parameter, not the go get parameter.

Reference: HTTPS://GITHUB.COM/ASTAXIE/BUILD-WEB-APPLICATION-WITH-GOLANG/BLOB/MASTER/ZH/01.3.MD

Server-side code

Note I'm here to make it easier to view, increase each request to print one message:

Client code:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.