# carpooling-server-go **Repository Path**: SweetSunnyFlower/carpooling-server-go ## Basic Information - **Project Name**: carpooling-server-go - **Description**: 拼车小程序服务端接口 - **Primary Language**: Go - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-07-12 - **Last Updated**: 2023-10-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # carpooling-server-go #### 介绍 拼车服务端,使用golang编写 #### 软件架构 软件架构说明 #### 代码结构 ``` .├── app // 程序具体逻辑代码 │ ├── cmd // 命令 │ │ ├── cache.go │ │ ├── cmd.go │ │ ├── key.go │ │ ├── make // make 命令及子命令 │ │ │ ├── make.go │ │ │ ├── make_controller.go │ │ │ ├── make_cmd.go │ │ │ ├── make_factory.go │ │ │ ├── make_migration.go │ │ │ ├── make_model.go │ │ │ ├── make_policy.go │ │ │ ├── make_request.go │ │ │ ├── make_seeder.go │ │ │ └── stubs // make 命令的模板 │ │ │ ├── apicontroller.stub │ │ │ ├── cmd.stub │ │ │ ├── factory.stub │ │ │ ├── migration.stub │ │ │ ├── model │ │ │ │ ├── model.stub │ │ │ │ ├── model_hooks.stub │ │ │ │ └── model_util.stub │ │ │ ├── policy.stub │ │ │ ├── request.stub │ │ │ └── seeder.stub │ │ ├── migrate.go │ │ ├── play.go │ │ ├── seed.go │ │ └── serve.go │ ├── http // http 请求处理逻辑 │ │ ├── controllers // 控制器,存放 API 和视图控制器 │ │ │ ├── api // API 控制器,支持多版本的 API 控制器 │ │ │ │ └── v1 // v1 版本的 API 控制器 │ │ │ │ ├── users_controller.go │ │ │ │ └── ... │ │ └── middlewares // 中间件 │ │ ├── auth_jwt.go │ │ ├── guest_jwt.go │ │ ├── limit.go │ │ ├── logger.go │ │ └── recovery.go │ ├── models // 数据模型 │ │ ├── user // 单独的模型目录 │ │ │ ├── user_hooks.go // 模型钩子文件 │ │ │ ├── user_model.go // 模型主文件 │ │ │ └── user_util.go // 模型辅助方法 │ │ └── ... │ ├── policies // 授权策略目录 │ │ ├── category_policy.go │ │ └── ... │ └── requests // 请求验证目录(支持表单、标头、Raw JSON、URL Query) │ ├── validators // 自定的验证规则 │ │ ├── custom_rules.go │ │ └── custom_validators.go │ ├── user_request.go │ └── ... ├── bootstrap // 程序模块初始化目录 │ ├── app.go │ ├── cache.go │ ├── database.go │ ├── logger.go │ ├── redis.go │ └── route.go ├── config // 配置信息目录 │ ├── app.go │ ├── captcha.go │ ├── config.go │ ├── database.go │ ├── jwt.go │ ├── log.go │ ├── mail.go │ ├── pagination.go │ ├── redis.go │ ├── sms.go │ └── verifycode.go ├── database // 数据库相关目录 │ ├── database.db // sqlite 数据文件(加入到 .gitignore 中) │ ├── factories // 模型工厂目录 │ │ ├── user_factory.go │ │ └── ... │ ├── migrations // 数据库迁移目录 │ │ ├── 2021_12_21_102259_create_users_table.go │ │ ├── 2021_12_21_102340_create_categories_table.go │ │ └── ... │ └── seeders // 数据库填充目录 │ ├── users_seeder.go │ ├── ... ├── pkg // 内置辅助包 │ ├── app │ ├── auth │ ├── cache │ ├── captcha │ ├── config │ └── ... ├── public // 静态文件存放目录 │ ├── css │ ├── js │ └── uploads // 用户上传文件目录 │ └── avatars // 用户上传头像目录 ├── routes // 路由 │ ├── api.go │ └── web.go ├── storage // 内部存储目录 │ ├── app │ └── logs // 日志存储目录 │ ├── 2021-12-28.log │ ├── 2021-12-29.log │ ├── 2021-12-30.log │ └── logs.log └── tmp // air 的工作目录 ├── .env // 环境变量文件 ├── .env.example // 环境变量示例文件 ├── .gitignore // git 配置文件 ├── .air.toml // air 配置文件 ├── .editorconfig // editorconfig 配置文件 ├── go.mod // Go Module 依赖配置文件 ├── go.sum // Go Module 模块版本锁定文件 ├── main.go // Gohub 程序主入口 ├── Makefile // 自动化命令文件 ├── readme.md // 项目 readme ``` #### 安装教程 1. xxxx 2. xxxx 3. xxxx #### 使用说明 1. 可使用命令 ``` go run main.go generate:key 生成APP KEY go run main.go make command testCommand 生成一个命令文件 go run main.go make model car 创建模型 go run main.go make policie car go run main.go make request car go run main.go migrate up go run main.go migrate down go run main.go make migration add_cars_table go run main.go make controller v1/car/carBrand go run main.go make factory car go run main.go make seeder car go run main.go seed SeedCarsTable go run main.go cache clear go run main.go cache forget --key=links:all go run main.go sync_vehicle_brand ``` 2. xxxx 3. xxxx #### 参与贡献 #### 特技 #### 部署 ``` CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o carpooling upx carpooling scp carpooling root@ip:/var/www/carpooling/ ``` ``` sudo apt install python3 sudo apt install supervisor sudo systemctl status supervisor sudo systemctl start supervisor supervisorctl reload ``` ``` [program:carpooling] directory=/var/www/carpooling command=/var/www/carpooling/carpooling stopsignal=TERM autostart=true autorestart=true user=root stdout_logfile=/data/log/supervisor/carpooling/stdout.log stderr_logfile=/data/log/supervisor/carpooling/stderr.log ``` #### 创建一组接口 ``` make migration add_car_brands_table make model car_brand make policie car_brand make request car_brand make controller v1/car/car_brand ``` #### 数据填充 seed SeedRegionsTable seed SeedTracksTable ### Websocket #### message格式 ```json { "action":"ping", "payload": { "ping": "ping" } } // 用户发布行程 { "action":"publishtrip", "payload": { "id": 1 } } ``` ### 管理后台 #### - http://127.0.0.1:3100/admin #### 笔记 - json:"omitempty" // 可以标记如果为空就不返回了 - 在声明模型关联的时候,使用指针可以实现如果不存在就返回null,而不是结构体的默认值