-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding protobuf generator for stormrpc servers and clients using protobuf definitions * adding installation instructions to readme * fix comment
- Loading branch information
Showing
15 changed files
with
864 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
cmd | ||
.idea | ||
.idea | ||
prototest/gen_out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,26 @@ It provides some convenient features including: | |
|
||
Responses have an `Error` attribute and these are propagated across the wire without needing to tweak your request/response schemas. | ||
|
||
## Installation | ||
|
||
### Runtime Library | ||
|
||
The runtime library package ```github.com/actatum/stormrpc``` contains common types like ```stormrpc.Error```, ```stormrpc.Client``` and ```stormrpc.Server```. If you aren't generating servers and clients from protobuf definitions you only need to import the stormrpc package. | ||
|
||
```bash | ||
$ go get github.com/actatum/stormrpc | ||
``` | ||
|
||
### Code Generator | ||
|
||
You need to install ```go``` and the ```protoc``` compiler on your system. Then, install the protoc plugins ```protoc-gen-stormrpc``` and ```protoc-gen-go``` to generate Go code. | ||
|
||
```bash | ||
$ go install github.com/actatum/stormrpc/protoc-gen-stormrpc | ||
$ go install google.golang.org/protobuf/cmd/[email protected] | ||
``` | ||
Code generation examples can be found [here](https://github.com/actatum/stormrpc/tree/main/examples/protogen) | ||
|
||
## Basic Usage | ||
|
||
### Server | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/actatum/stormrpc" | ||
"github.com/actatum/stormrpc/examples/protogen/pb" | ||
) | ||
|
||
func main() { | ||
client, err := stormrpc.NewClient("nats://0.0.0.0:40897") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer client.Close() | ||
|
||
c := pb.NewEchoerClient(client) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
defer cancel() | ||
|
||
out, err := c.Echo(ctx, &pb.EchoRequest{Message: "protogen"}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
fmt.Printf("Response: %s\n", out.GetMessage()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go install ../../protoc-gen-stormrpc | ||
protoc --go_out=./pb --stormrpc_out=./pb pb/echo.proto |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
syntax = "proto3"; | ||
|
||
package protogen; | ||
|
||
option go_package = ".;pb"; | ||
|
||
service Echoer { | ||
rpc Echo (EchoRequest) returns (EchoResponse); | ||
} | ||
|
||
message EchoRequest { | ||
string message = 1; | ||
} | ||
|
||
message EchoResponse { | ||
string message = 1; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.