generated from cuongnd9/go_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
65 additions
and
3,688 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,28 +1,30 @@ | ||
FROM golang:1.14.6-alpine AS builder | ||
# Set necessary environmet variables needed for our image | ||
# Building Stage | ||
FROM golang:alpine3.19 AS builder | ||
|
||
ENV GO111MODULE=on \ | ||
CGO_ENABLED=0 \ | ||
GOOS=linux \ | ||
GOARCH=amd64 | ||
# Move to working directory /build | ||
|
||
WORKDIR /build | ||
# Copy and download dependency using go mod | ||
COPY go.mod . | ||
COPY go.sum . | ||
RUN go mod download | ||
# Copy the code into the container | ||
|
||
COPY . . | ||
# Build the application | ||
RUN go build -o main . | ||
# Move to /dist directory as the place for resulting binary folder | ||
|
||
WORKDIR /dist | ||
# Copy binary from build to main folder | ||
RUN cp /build/main . | ||
|
||
# Build a small image | ||
# Final Stage | ||
FROM scratch | ||
|
||
LABEL maintainer="Your Name <your.email@example.com>" | ||
LABEL org.opencontainers.image.source="https://github.com/yourusername/yourrepository" | ||
|
||
COPY --from=builder /dist/main / | ||
# Export necessary port | ||
|
||
EXPOSE 3000 | ||
# Command to run | ||
|
||
ENTRYPOINT ["/main"] |
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,57 +1,59 @@ | ||
# go_grpc | ||
# go-grpc | ||
|
||
![golangci-lint status](https://github.com/103cuong/go_grpc/workflows/golangci-lint/badge.svg) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/103cuong/go_grpc)](https://goreportcard.com/report/github.com/103cuong/go_grpc) | ||
Go 🤝 gRPC | ||
|
||
go 🤝 gRPC | ||
## Preparation | ||
|
||
## preparation | ||
```shell script | ||
brew install protobuf | ||
protoc --version | ||
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28 | ||
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2 | ||
export PATH="$PATH:$(go env GOPATH)/bin" | ||
``` | ||
|
||
- [Go](https://golang.org/) | ||
- [Docker](https://www.docker.com/) | ||
- [protobuf](https://developers.google.com/protocol-buffers) | ||
## How to use? | ||
|
||
### Start MySQL | ||
|
||
```shell script | ||
brew install protobuf # MacOS | ||
apt install -y protobuf-compiler # Linux - Ubuntu | ||
protoc --version | ||
docker run -it --name database -p 3306:3306 -e MYSQL_ROOT_PASSWORD=cuongnguyenpo -e MYSQL_DATABASE=cuongnguyenpo mysql:latest | ||
``` | ||
|
||
## how to use? | ||
*Create table if not exist* | ||
|
||
```sql | ||
CREATE TABLE `todo` ( | ||
`id` bigint(20) NOT NULL AUTO_INCREMENT, | ||
`title` varchar(200) DEFAULT NULL, | ||
`description` varchar(1024) DEFAULT NULL, | ||
`reminder` timestamp NULL DEFAULT NULL, | ||
PRIMARY KEY (`id`), | ||
UNIQUE (`id`) | ||
); | ||
``` | ||
|
||
### starting MySQL | ||
### Generate Go's protobuf code | ||
|
||
```shell script | ||
./scripts/database/start.sh | ||
protoc --proto_path=proto \ | ||
--go_out=pkg/pb --go_opt=paths=source_relative \ | ||
--go-grpc_out=pkg/pb --go-grpc_opt=paths=source_relative \ | ||
proto/*.proto | ||
``` | ||
|
||
### starting gRPC server | ||
### gRPC server | ||
|
||
```shell script | ||
cd cmd/server && go run main.go | ||
``` | ||
|
||
### staring gRPC client | ||
### gRPC client | ||
|
||
```shell script | ||
cd cmd/client && go run main.go | ||
``` | ||
|
||
### using BloomRPC | ||
|
||
![create](.images/create.png) | ||
![read](.images/read.png) | ||
![update](.images/update.png) | ||
![delete](.images/delete.png) | ||
![readall](.images/readall.png) | ||
|
||
## documents | ||
|
||
- [[Tutorial, Part 1] How to develop Go gRPC microservice with HTTP/REST endpoint, middleware, Kubernetes deployment, etc.](https://medium.com/@amsokol.com/tutorial-how-to-develop-go-grpc-microservice-with-http-rest-endpoint-middleware-kubernetes-daebb36a97e9) | ||
- [[Tutorial, Part 2] How to develop Go gRPC microservice with HTTP/REST endpoint, middleware, Kubernetes deployment, etc.](https://medium.com/@amsokol.com/tutorial-how-to-develop-go-grpc-microservice-with-http-rest-endpoint-middleware-kubernetes-af1fff81aeb2) | ||
- [[Tutorial, Part 3] How to develop Go gRPC microservice with HTTP/REST endpoint, middleware, Kubernetes deployment, etc.](https://medium.com/@amsokol.com/tutorial-part-3-how-to-develop-go-grpc-microservice-with-http-rest-endpoint-middleware-739aac8f1d7e) | ||
- [Go Generated Code](https://developers.google.com/protocol-buffers/docs/reference/go-generated) | ||
|
||
## license | ||
|
||
MIT © [Cuong Tran](https://github.com/103cuong/) | ||
MIT © [Cuong Nguyen](https://github.com/cuongnd9/) 2024 |
Oops, something went wrong.