if you haven't installed google's protocol buffers, see the prerequisites part at the bottom.
-
make
go.modfile with:$ go mod init [link to repo without "https://"]your repo should be on the public github. i couldn't get it to work on the itu instance.
Tip!
You can use
example.com, if you don't have a repo. -
make a
.protofile in a sub-directory, for exampletime/time.protoand fill it with IDL.-
notice line 3 and 4.
package time; option go_package = "https://github.itu.dk/nako/DISYS-week5;time";
the
go_packageshould equal a link to your repo, a semicolon and then the package name.Tip!
Notice the semicolon and the package-name at the end of the link. If you used example.com, you should write
... = "https://example.com/;packagename";.
-
-
run command:
$ protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative time/time.protowhich should create the two
pb.gofiles. Remember to change "time" to your directory and file name. -
run command:
$ go mod tidyto install dependencies and create the
go.sumfile. -
create a
client\client.gofile with theclient_template.txtas template.Tip!
When implementing your grpc methods, you should write the link without "https://" and with the packagename at the end. If you used example.com, you should write
"example.com/package". If you used a long name for your package, you can write a shorter name before the quotation marks, for examplepckg "example.com/longpackagename". -
create a
server\server.gofile with theserver_template.txtas template. -
switch out the "myPackage" with your actual package.
-
switch our the method names with actual method names.
-
add more methods to the
client.gofile, so that there's a method for each request in the.protofile. -
when everything is compilable, open a terminal, change directory to the
serverfolder, and run the command:$ go run .this will start your server.
-
open a new terminal, change directory to the
clientfolder and run the command:$ go run .this will run the requests listed in the
mainmethod of theclientfile. -
create a
Dockerfilelike the one in this repository. -
change line 11, 12 and 16 to match your repository.
from now on
please remember to commit and push changes to the files in your repository before running the program.
the following docker commands will clone your repository (maybe to the virtual machine?), so changes to files will not be applied, if you don't git commit yeet before.
the only exception (i think) is changes to the
client.gofile, since it's run locally on your computer, but just connects to the server in docker. -
run command:
$ docker build -t test --no-cache .to build the code. what you write after
-twill be the name of your image, so the name of the image here istest. the name doesn't matter, but it helps you identify it in the docker desktop app. -
run command:
$ docker run -p 9080:9080 -tid testto run the code in a docker container. if you changed the name of the image from
test, make sure to change it in this command as well. -
change directory into your
clientfolder. -
run command:
$ go run .to run the code.
-
before starting, install google's protocol buffers:
- go to this link: https://developers.google.com/protocol-buffers/docs/downloads
- click on the "release page" link.
- find the version you need and download it.
- as per october 2021, if your on windows, it's the third from the bottom,
protoc-3.18.1-win64.zip.
-
unzip the downloaded file somewhere "safe".
- on my windows machine, i placed it in
C:\Program Files\Protoc
- on my windows machine, i placed it in
-
add the path to the
binfolder to your system variables.-
on windows, click the windows key and search for "system", then there should come something up like "edit the system environment variables".
-
click the button "environment variables..." at the bottom.
-
in the bottom list select the variable called "path" and click "edit ..."
-
in the pop-up window, click "new..."
-
paste the total path to the
binfolder into the text field.my path is
C:\Program Files\Protoc\bin. -
click "ok".
-
-
open a terminal and run these commands:
$ go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26$ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1