# de-news-server **Repository Path**: byte-and-deepcode/de-news-server ## Basic Information - **Project Name**: de-news-server - **Description**: 后端仓库 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-12-29 - **Last Updated**: 2021-12-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # dc-news 字节跳动训练营项目后端服务 ## 技术栈 - Gin - Gorm - jwt-go - MySQL - Zap - Redis - MongoDB ## 环境 - Go v1.16+ - Mysql 8.0+ - Redis 6.2+ - MongoDB 5.0+ ## 其他 - 本项目使用了又拍云-云储存服务,用于保存上传的文件 - API文档:[https://docs.apipost.cn/preview/473e18a1df2f3349/7bdcdf73c6173536](https://docs.apipost.cn/preview/473e18a1df2f3349/7bdcdf73c6173536) ## 本地运行(Windows) ### 安装Golang环境 你已经是个成年人了,自行百度吧 ### 设置国内源 ``` go env -w GOPROXY=https://goproxy.cn,direct ``` ### clone仓库 ``` git clone https://gitee.com/byte-and-deepcode/de-news-server.git cd dc-news ``` ### 编译 ``` go mod tidy go build ``` ### 修改配置文件 在`./conf/`目录新建`config.ini`配置文件: ``` port = 8080 #后端服务端口 release = false #是否为release模式 register = true #后台是否开放注册 api_domain = http://localhost:8080 #后端api域名和端口 app_domain = http://localhost #前台域名 cdn_domain = https://example.com #cdn域名(又拍云) report_service = http://localhost:5000 #使用报告服务接口地址 [mysql] user = root #数据库用户 password = root #数据库密码 host = 127.0.0.1 #数据库地址 port = 3306 #数据库端口 db = dc_news #数据库名 [smtp] mail_host = smtp.exmail.qq.com #smtp服务器地址 mail_port = 465 #smtp服务器端口 mail_user = support@kakkk.net #smtp用户名 mail_pwd = xxxx #smtp密码 mail_nickname = kakkk Support #发件人名称 [redis] redis_host = 127.0.0.1 #redis地址 redis_port = 6379 #redis端口 [upyun] bucket = dc-news #又拍云服务名 operator = op #又拍云操作员 password = 123123 #又拍云操作员密码 [mongo] host = 127.0.0.1 #MongoDB地址 port = 27017 #MongoDB端口 database = dc_news #MongoDB数据库 ``` ### 运行 ``` ./dc-news.exe ``` ### 注意 别忘了导入数据库 ## 部署(Ubuntu 20.04) ### 安装Golang环境 ``` sudo add-apt-repository ppa:longsleep/golang-backports sudo apt update sudo apt install golang-go ``` ### 设置国内源 ``` go env -w GOPROXY=https://goproxy.cn,direct ``` ### clone仓库 ``` git clone https://gitee.com/byte-and-deepcode/de-news-server.git cd dc-news ``` ### 编译 ``` go mod tidy go build ``` ### 修改配置文件 在`./conf/`目录新建`config.ini`配置文件: ``` port = 8080 #后端服务端口 release = false #是否为release模式 register = true #后台是否开放注册 api_domain = http://localhost:8080 #后端api域名和端口 app_domain = http://localhost #前台域名 cdn_domain = https://example.com #cdn域名(又拍云) report_service = http://localhost:5000 #使用报告服务接口地址 [mysql] user = root #数据库用户 password = root #数据库密码 host = 127.0.0.1 #数据库地址 port = 3306 #数据库端口 db = dc_news #数据库名 [smtp] mail_host = smtp.exmail.qq.com #smtp服务器地址 mail_port = 465 #smtp服务器端口 mail_user = support@kakkk.net #smtp用户名 mail_pwd = xxxx #smtp密码 mail_nickname = kakkk Support #发件人名称 [redis] redis_host = 127.0.0.1 #redis地址 redis_port = 6379 #redis端口 [upyun] bucket = dc-news #又拍云服务名 operator = op #又拍云操作员 password = 123123 #又拍云操作员密码 [mongo] host = 127.0.0.1 #MongoDB地址 port = 27017 #MongoDB端口 database = dc_news #MongoDB数据库 ``` 修改配置文件并保存 ### 后台运行 ``` nohup ./dc-news & ``` ### 结束运行 查看进程ID ``` ps -aux | grep dc-news ``` 根据进程ID结束运行 ``` kill 进程ID ``` ### Nginx反向代理 ``` location / { proxy_pass http://localhost:8080; proxy_set_header Host localhost; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; add_header X-Cache $upstream_cache_status; #Set Nginx Cache add_header Cache-Control no-cache; } ``` ### 日志目录 ``` ./logs/dc-news.log ```