Hello World with gRPC / go in Docker environment

Introduction

I started studying go. I started studying gRPC. First, I tried this. I stumbled more than I expected, so I'll keep a record. Quick start – gRPC

I'm not sure about go or gRPC.

The environment used this docker image. By name, I did it because I wanted it. grpc/go - Docker Hub

Docker I launched it like this. Docker I'm not sure.

docker pull grpc/go
docker run --name grpc-go -it grpc/go /bin/bash 

Quick Start Execute in order according to Quick Start.

When you execute the following command,

$ go run greeter_server/main.go

I get an error like this.

cannot find package "golang.org/x/net/http2"

And

undefined: "github.com/golang/protobuf/proto".ProtoPackageIsVersion4

I put in something that seems necessary, and put it back in with the following command.

go get golang.org/x/sys/unix
go get golang.org/x/net/http2
go get google.golang.org/genproto/googleapis/rpc/status
go get -u github.com/golang/protobuf/proto

The last one imitated the copy and paste and added -u, but I'm not sure. It looks like an update.

go - The Go Programming Language

The -u flag instructs get to update modules providing dependencies of packages named on the command line to use newer minor or patch releases when available. Continuing the previous example, 'go get -u A' will use the latest A with B v1.3.1 (not B v1.2.3). If B requires module C, but C does not provide any packages needed to build packages in A (not including tests), then C will not be updated.

When the above error appeared, I used the following command to erase it and reinsert it, so I couldn't understand the version. I want to understand it soon. I did rm, but by the way, I didn't delete the binary file. What happened? Was it overwritten?

rm -rf /go/src/github.com/golang/protobuf/proto
rm -rf /go/src/google.golang.org/grpc/
git clone https://github.com/grpc/grpc-go

When an error occurred, I referred to here. Go Frequently Asked Questions  |  Protocol Buffers  |  Google Developers

With the above correspondence, the first server and client worked. After that, when I did SayHello Again, I was told that it was undefined.

$ go run greeter_client/main.go 
# command-line-arguments
greeter_client/main.go:59:12: c.SayHelloAgain undefined (type helloworld.GreeterClient has no field or method SayHelloAgain)

The pb" google.golang.org/grpc/examples/helloworld/helloworld " in main.go was suspicious, so if you follow the path, you'll see/ go / src / google.golang.org There was an oldhelloworld.proto in / grpc / examples / helloworld / helloworld.

I wasn't sure what to do, but I overwrote the modified ~ / grpc-go / examples / helloworld / helloworld to the above path. When I ran server and client again, it worked as expected. For the time being, it was good. hello world is done.

environment

The environment when it finally moved is like this. I'm not sure how to check the version entered with go get. GOPATH is an image of docker pull and is included by default. .bashrc works even if it's empty.

# go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build743505095=/tmp/go-build -gno-record-gcc-switches"
# go version
go version go1.10.4 linux/amd64
# protoc --version
libprotoc 3.6.0

Finally

I was able to do something like Hello World. There are so many things I don't understand, so let's study while studying little by little.

Recommended Posts

Hello World with gRPC / go in Docker environment
Hello, World with Docker
Hello World in GO language
Let's try gRPC with Go and Docker
Hello world with full features of Go language
Go (Echo) Go Modules × Build development environment with Docker
hello world with ctypes
First python ① Environment construction with pythonbrew & Hello World !!
Hello world with flask
Japanese can be used with Python in Docker environment
Draw hello world with mod_wsgi
Hello World with Flask + Hamlish
Until hello world with zappa
Programming language in "Hello World"
Prepare python3 environment with Docker
Python starting with Hello world!
Display "Hello World" created in the local environment on the web
Let's do "Hello World" in 40 languages! !!
Run eclipse in Docker environment (noVNC)
Hello, world! With virtual CAN communication
Build a go environment using Docker
Tips for running Go with docker
Build Mysql + Python environment with docker
Build PyPy execution environment with Docker
[Note] Hello world output with python
cout << "Hello, World! \ N" in python
Hello World in Flask [Appropriate memo]
Code: 2 "Hello World" in "Choregraphe-Python script"
Hello World! By QPython with Braincrash
Rebuild Django's development environment with Docker! !! !! !!
Data science environment construction with Docker
Create a development environment for Go + MySQL + nginx with Docker (docker-compose)
Automate CircleCI environment variable registration in Go
Hello World and face detection with opencv-python 4.2
Build Jupyter Lab (Python) environment with Docker
I wanted to use jupyter notebook with docker in pip environment (opticspy)
[AWS] Create a Python Lambda environment with CodeStar and do Hello World
Using venv in Windows + Docker environment [Python]
Hello World with Raspberry Pi + Minecraft Pi Edition
Redirect HTTP to HTTPS with Elastic Beanstalk in Go / Java SE environment
Get a local DynamoDB environment with Docker
Create Python + uWSGI + Nginx environment with Docker
I set the environment variable with Docker and displayed it in Python
Re: Heroku life begin with Flask from zero - Environment and Hello world -
Environment maintenance made with Docker (I want to post-process GrADS in Python
[Linux] Build a jenkins environment with Docker
Hello world
Hello world instead of localhost in Django
Launch environment with LineBot + Heroku + Docker + Python
Introduction to docker Create ubuntu environment in ubuntu
How to display Hello world in python
Use WebDAV in a Portable Docker environment
Build NGINX + NGINX Unit + MySQL environment with Docker
Hello World! By QPython with Brainfu * k
Introduced sip-4.14 in python3.2.2 environment with MacOS 10.7.4
[Linux] Build a Docker environment with Amazon Linux 2
I got an error when trying to run Hello World in Go language
[Linux] SMTP setting method in Linux environment (host) when sending notification mail with Docker
Hello World and face detection with OpenCV 4.3 + Python
Environment construction with VSCode + Remote Container (Go / Application)
Note: Prepare the environment of CmdStanPy with docker