Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: minor fixes and suggestions #47

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions docs/getting-started/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ which we will use to generate the server and client code.
## Prerequisites

- [Go](https://golang.org) - fRPC works with `Go` version 1.18 or later. For installation instructions see [Go's Getting Started Guide](https://golang.org/doc/install).
- [Protocol Buffer Compiler (protoc)](https://developers.google.com/protocol-buffers) - fRPC works with `protoc` version 3. For installation instructions see the [Protoc Getting Started Guide](https://developers.google.com/protoc/docs/getting_started).
- [Protocol Buffer Compiler (protoc)](https://grpc.io/docs/protoc-installation/) - fRPC works with `protoc` version 3. For installation instructions see the [Protoc Getting Started Guide](https://developers.google.com/protoc/docs/getting_started).

If you're using MacOS and have [Brew](https://brew.sh/) installed, you can use `brew install go`
to install Golang, and `brew install protoc` to install the protoc compiler.
to install Golang, and `brew install protobuf` to install the protoc compiler.

## Install the fRPC Plugin

Expand Down Expand Up @@ -64,6 +64,8 @@ $ cd ~/frpc
Now we'll create an `echo.proto` file and define our message types:

```protobuf echo.proto
syntax = "proto3";

option go_package = "/echo";

message Request {
Expand All @@ -80,6 +82,8 @@ You can see that we've defined two message types, one for the `Request` and one
Next, we will define a new `EchoService` in our `proto3` file. This tells the compiler that we want to generate a server and client for this service.

```protobuf echo.proto
syntax = "proto3";

option go_package = "/echo";

service EchoService {
Expand Down Expand Up @@ -142,7 +146,7 @@ package main

import (
"context"
"frpc/echo"
"frpc/echo"
)

type svc struct{}
Expand All @@ -166,16 +170,15 @@ package main

import (
"context"
"frpc/echo"
"log"
"os"
"runtime"
"time"

"frpc/echo"
)

type svc struct{}

func (s *svc) Echo(_ context.Context, req *echo.Request) (*echo.Response, error) {
log.Printf("Received request %s\n", req.Message)
res := new(echo.Response)
res.Message = req.Message
return res, nil
Expand Down Expand Up @@ -236,7 +239,7 @@ Here, we're creating a new echo client using our generated `echo.NewClient()` fu
Then, we're passing in the address of the server we want to connect to. But we're not actually sending any
requests to the server yet.

To do that, we can write a simple look to send a request to the server every second and then print out the response:
To do that, we can write a simple loop to send a request to the server every second and then print out the response:

```go echo/client/client.go
package main
Expand All @@ -262,30 +265,28 @@ func main() {
if err != nil {
panic(err)
}
defer c.Close()

stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)

req := echo.NewRequest()
i := 0
for {
for i := 0; ; i++ {
select {
case <-stop:
err = c.Close()
if err != nil {
panic(err)
}
return
default:
case <-time.After(time.Second):
req.Message = fmt.Sprintf("#%d", i)
log.Printf("Sending Request %s\n", req.Message)
res, err := c.EchoService.Echo(context.Background(), req)
if err != nil {
panic(err)
}
log.Printf("Received Response %s\n", res.Message)
time.Sleep(time.Second)
i++
}
}
}
Expand Down