Skip to content

Commit

Permalink
2024 🔥 project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongnd9 committed Mar 16, 2024
1 parent 9bc5456 commit 14735f9
Show file tree
Hide file tree
Showing 18 changed files with 265 additions and 44 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ mysql:

gen-proto:
protoc --proto_path=proto \
--go_out=pkg/pb --go_opt=paths=source_relative \
--go-grpc_out=pkg/pb --go-grpc_opt=paths=source_relative \
--go_out=api --go_opt=paths=source_relative \
--go-grpc_out=api --go-grpc_opt=paths=source_relative \
proto/*.proto

run-server:
go run cmd/server.go
go run cmd/server/main.go

run-client:
go run cmd/client.go
go run cmd/client/main.go
55 changes: 39 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,42 @@

Go 🤝 gRPC

# 🧑‍💻 Project Structure

### api/

This directory contains gRPC definitions.

### cmd/

The cmd/ directory contains the main applications of the project. In this case, there are client and server directories.

### config/

The config/ directory holds configuration files such as environment or settings.

### model/

The model/ directory contains database entities.

### module/

The module/ directory is collections of domain logic or features.

### pkg/

The pkg/ directory typically houses reusable packages or libraries that can be used across the project or potentially shared with other projects.

### proto/

This directory contains Protobuf files, which are used for defining gRPC services and messages.

### sql/

The sql/ directory contains SQL scripts, particularly release notes related to database schema changes or updates.

# 🐧 Commands

### 1. Local Machine

```shell script
Expand Down Expand Up @@ -30,25 +66,12 @@ go mod vendor
docker run -it --name database -p 3306:3306 -e MYSQL_ROOT_PASSWORD=cuongnguyenpo -e MYSQL_DATABASE=cuongnguyenpo mysql:latest
```

*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`)
);
```

### 4. Generate Go's protobuf code

```shell script
protoc --proto_path=proto \
--go_out=pkg/pb --go_opt=paths=source_relative \
--go-grpc_out=pkg/pb --go-grpc_opt=paths=source_relative \
--go_out=api --go_opt=paths=source_relative \
--go-grpc_out=api --go-grpc_opt=paths=source_relative \
proto/*.proto
```

Expand All @@ -64,6 +87,6 @@ cd cmd/server && go run main.go
cd cmd/client && go run main.go
```

### license
## License

MIT © [Cuong Nguyen](https://github.com/cuongnd9/) 2024
6 changes: 3 additions & 3 deletions pkg/pb/todo-message.pb.go → api/todo-message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pkg/pb/todo-service.pb.go → api/todo-service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/client.go → cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"context"
pb "github.com/cuongnd9/go-grpc/pkg/pb"
pb "github.com/cuongnd9/go-grpc/internal/pb"
"google.golang.org/grpc"
"log"
"syreclabs.com/go/faker"
Expand Down
3 changes: 1 addition & 2 deletions cmd/server.go → cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package main

import (
"fmt"
"github.com/cuongnd9/go-grpc/pkg"
"os"
)

func main() {
if err := pkg.RunServer(); err != nil {
if err := internal.RunServer(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package config
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.14

require (
github.com/go-sql-driver/mysql v1.5.0
github.com/golang/protobuf v1.4.2 // indirect
google.golang.org/grpc v1.27.0
google.golang.org/protobuf v1.25.0
syreclabs.com/go/faker v1.2.2
Expand Down
4 changes: 1 addition & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:x
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
Expand Down Expand Up @@ -67,7 +66,6 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
Expand Down
1 change: 1 addition & 0 deletions model/todo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package model
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package service
package todo

import (
"context"
Expand Down
Loading

0 comments on commit 14735f9

Please sign in to comment.