Skip to content

Commit

Permalink
2024 ver
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongnd9 committed Mar 13, 2024
1 parent 2d0f88e commit 58efe3f
Show file tree
Hide file tree
Showing 28 changed files with 65 additions and 3,688 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ linters:

linters-settings:
goimports:
local-prefixes: github.com/103cuong/go_template
local-prefixes: github.com/cuongnd9/go_template
govet:
check-shadowing: true
settings:
Expand Down
Binary file removed .images/create.png
Binary file not shown.
Binary file removed .images/delete.png
Binary file not shown.
Binary file removed .images/read.png
Binary file not shown.
Binary file removed .images/readall.png
Binary file not shown.
Binary file removed .images/update.png
Binary file not shown.
24 changes: 13 additions & 11 deletions Dockerfile
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"]
66 changes: 34 additions & 32 deletions README.md
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
Loading

0 comments on commit 58efe3f

Please sign in to comment.