This project demonstrates a full-stack inventory management system built using Go and gRPC. It includes a Go backend server and gRPC services for inventory operations.
- Inventory management with stock updates and consumption
- gRPC APIs for communication
- Multi-platform build support (Linux, Windows, macOS)
- Secure gRPC with TLS certificates
- Go >= 1.20
- Protobuf Compiler (
protoc) - OpenSSL (for certificates)
-
Install protobuf compiler on Ubuntu
sudo apt install -y protobuf-compiler protoc --version # Ensure compiler version is 3+ -
Install
grpc-protobuf-compilerin yourubuntumachineapt install -y protobuf-compiler protoc --version # Ensure compiler version is 3+ -
Install these go-packages locally to generate grpc go code
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
-
Use this command to generate the the go code for grpc services
protoc \ --go_out=internal/generated/stock --go_opt=paths=source_relative \ --go-grpc_out=internal/generated/stock --go-grpc_opt=paths=source_relative \ proto/stock.proto
-
Command for creating certs and keys
openssl req -new -x509 -days 365 -nodes -out certs/server.crt -keyout certs/server.key -subj "/CN=localhost" -
Use this command to create your custom
Authorization-Tokenfor you grpc servicesopenssl rand -hex 32
-
Clone the Repository:
git clone https://github.com/Sahil2k07/gRPC-GO.git cd gRPC-GO -
Restore all the packages:
go mod download
-
Optionally have a local copy of all the packages:
go mod vendor
-
**Make a
dev.tomlfile and give all the credentials. Adev.example.tomlhas been provided[server] server_port = ":5000" origins = ["http://localhost:3000", "https://example.com"] [grpc] grpc_port = ":6000" grpc_url = "localhost:6000" grpc_token = "5763121b0c2141eb73d3c1ddfe65a02f30e56adc2fd6f62d1a143f38dc1f3680" [database] db_host = "localhost" db_port = "5432" db_user = "postgres" db_password = "sahil" db_name = "grpc-go" [jwt] cookie_name = "gRPC-GO-cookie" secret = "K3#v@9$1!pZ^mL2&uQ7*rF4)gT8_W+oB"
-
Run the migrations and restore the tables in your database. Refer to
cmd/migration/main.gogo run cmd/migration/main.go
-
Start the REST API Server:
go run cmd/server/main.go
-
Start the gRPC Server:
go run cmd/grpc/main.go
This project uses a Makefile to build server and gRPC binaries.
-
Build Linux server:
make server
-
Build Linux gRPC service:
make grpc
-
Build for Windows/macOS (cross-platform):
make server-windows make grpc-windows
make server-macos make grpc-macos
-
Build everything at once:
make all
-
Clean build artifacts:
make clean
-
Running the Server Build:
./build/server
-
Running the gRPC Build:
./build/grpc
Note: This is a link to the separate .NET repository. The .NET service and the Go/gRPC services communicate with each other.
You can find the .NET service repository here: https://github.com/Sahil2k07/OMS-gRPC