______ ____ __ __ __________________
/ ____/___ / __ \_________ / /_____ / / / /_ __/_ __/ __ \
/ / __/ __ \/ /_/ / ___/ __ \/ __/ __ \/ /_/ / / / / / / /_/ /
/ /_/ / /_/ / ____/ / / /_/ / /_/ /_/ / __ / / / / / / ____/ Example
\____/\____/_/ /_/ \____/\__/\____/_/ /_/ /_/ /_/ /_/
Copyright (©️) 2024 @H0llyW00dzZ All rights reserved.
ProtoHTTP is a simple gRPC server implementation in Go that responds with a "Hello, World!" message. This project serves as an example of how to set up a gRPC service with Go, including server reflection for tooling support.
- Simple gRPC service that responds to
SayHellorequests. - Server reflection enabled for easy testing with tools like
grpcurl. - Clean and well-documented Go code.
These instructions will get your copy of the project up and running on your local machine for development and testing purposes.
- Go (1.22 or higher)
- Protocol Buffer Compiler (
protoc) - gRPC Go Plugin
- gRPCurl (for testing)
First, clone the repository to your local machine:
git clone https://github.com/H0llyW00dzZ/ProtoHTTP.git
cd ProtoHTTPNext, install the necessary dependencies:
go mod tidyTo run the server, execute:
go run main.goThe server will start listening on port 50051.
You can test the SayHello service using grpcurl:
List services:
grpcurl -plaintext localhost:50051 listCall the SayHello method:
grpcurl -plaintext -d '{}' localhost:50051 redirect.HelloService/SayHelloCall the SayHelloWithField method:
grpcurl -plaintext -d '{"name": "Gopher"}' localhost:50051 redirect.HelloService/SayHelloWithFieldCall the Ping method:
grpcurl -plaintext -d '{}' localhost:50051 redirect.PingService/PingYou should receive a response like:
For SayHello:
{
"message": "Hello, World!"
}For SayHelloWithField:
{
"message": "Hello, Gopher!"
}For Ping:
{
"latencyMicroseconds": "101579",
"formattedLatency": "101579 µs",
"formattedLatencyMilliseconds": "101.58 ms"
}main.go: Contains the server implementation and the entry point to start the server./handler: This directory contains the generated gRPC code from your.protofiles.
After I learning how Protocol Buffers work, it seems that Protocol Buffers have limitations. For example, you cannot use concurrency or manage flexibility with goroutines. It is recommended to use Protocol Buffers for projects such as real-time communication or end-to-end communication.