go-mongodb-crud-example
所属分类:MongoDB
开发工具:GO
文件大小:40KB
下载次数:0
上传日期:2022-12-13 10:20:21
上 传 者:
sh-1993
说明: REST API示例。包括MongoDB、Zap记录器、chi路由器等。。。
(Example of REST API. Includes such things as MongoDB, Zap logger, chi router etc...)
文件列表:
Dockerfile (374, 2022-12-13)
cmd (0, 2022-12-13)
cmd\go-mongodb-crud-api-example (0, 2022-12-13)
cmd\go-mongodb-crud-api-example\config.go (658, 2022-12-13)
cmd\go-mongodb-crud-api-example\config.yaml (271, 2022-12-13)
cmd\go-mongodb-crud-api-example\main.go (2492, 2022-12-13)
docker-compose.yaml (396, 2022-12-13)
go.mod (1113, 2022-12-13)
go.sum (19511, 2022-12-13)
internal (0, 2022-12-13)
internal\api (0, 2022-12-13)
internal\api\api.go (8723, 2022-12-13)
internal\api\controller.go (1938, 2022-12-13)
internal\api\users.go (4332, 2022-12-13)
internal\database (0, 2022-12-13)
internal\database\dbuser (0, 2022-12-13)
internal\database\dbuser\database.go (1107, 2022-12-13)
internal\database\dbuser\user.go (2730, 2022-12-13)
internal\logger (0, 2022-12-13)
internal\logger\logger.go (1118, 2022-12-13)
internal\service (0, 2022-12-13)
internal\service\service.go (1196, 2022-12-13)
internal\service\storage.go (485, 2022-12-13)
internal\service\tests (0, 2022-12-13)
internal\service\tests\mock (0, 2022-12-13)
internal\service\tests\mock\storage_mock.go (3943, 2022-12-13)
internal\service\tests\service_test.go (3935, 2022-12-13)
openapi (0, 2022-12-13)
openapi\openapi.yaml (4783, 2022-12-13)
package-diagram.md (548, 2022-12-13)
package-diagram.png (14546, 2022-12-13)
# go-mongodb-crud-example
Example of REST API.
Includes:
- oapi-codegen;
- go-chi;
- Zap logger;
- MongoDB;
- Docker;
- Docker Compose;
- gomock.
## Description
Sample project for educational purposes.
There are 2 ideas:
- checking and glueing together technologies mentioned above;
- sharing my own experience for the ones who want to glue the same technologies.
## Package Diagram
## Generate
API boilerplate code is generated using `oapi-codegen` tool from the `openapi.yaml` file.
It's great tool that makes your actual API reflect the documentation.
Get it there:
`https://github.com/deepmap/oapi-codegen`
And make sure that your `GOPATH/bin` path presents in `PATH` variable.
Use this command to generate the `api.go` file:
- `oapi-codegen --package=api --generate=types,chi-server openapi/openapi.yaml > internal/api/api.go`
## Running
### Running
Use `go run .` from the folder that contains `main.go`.
### Running via Docker (no compose)
Get the image here:
`https://hub.docker.com/_/mongo`
Create network and volume:
- `docker network create db_network`
- `docker volume create mongo-vol`
- `docker volume create mongo-config-vol`
Run db container:
- `docker run -it --rm -p 27017:27017 --name mongodb-0 --network db_network --mount source=mongo-vol,target=/data/db --mount source=mongo-config-vol,target=/data/configdb mongo:5.0.6`
After that you can run your using `go run` if you need.
Build the app image and run:
- `docker build -t go-mongodb-app:v0.1.0 .`
- `docker run -it -p 8080:80 --name go-mongodb-app-0 --network db_network go-mongodb-app:v0.1.0`
### Running via Docker Compose
As simple as:
- `docker-compose build`
- `docker-compose up`
近期下载者:
相关文件:
收藏者: