# blog **Repository Path**: pigful/blog ## Basic Information - **Project Name**: blog - **Description**: blog系统,,,,,,,, - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-05-10 - **Last Updated**: 2024-06-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # blog 安装数据库: ```bash docker run -itd --name mysql-test --restart always -p 3306:3306 -v /data/mysql/data:/var/lib/mysql -v /data/mysql/conf.d:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 mysql:8.0.27 ``` 安装依赖: ```bash go get -u github.com/gin-gonic/gin go get -u gopkg.in/ini.v1 go get -u github.com/jinzhu/gorm go get -u gorm.io/driver/mysql go get -u github.com/go-sql-driver/mysql go get -u github.com/dgrijalva/jwt-go go get -u github.com/aliyun/aliyun-oss-go-sdk/oss go get -u github.com/sirupsen/logrus go get -u github.com/gin-contrib/cors ``` Linux 下的 post 请求 ```bash # 请求创建用户 curl -i -X POST -H "Context-Type: application/json" -d '{"username": "pigful", "password": "123456", "role": 0}' http://localhost:9000/api/v1/user/add curl -i -X POST -H "Context-Type: application/json" -d '{"username": "admin", "password": "123456", "role": 0}' http://localhost:9000/api/v1/user/add curl -i -X POST -H "Context-Type: application/json" -d '{"username": "test", "password": "123456", "role": 1}' http://localhost:9000/api/v1/user/add # 请求创建分类 curl -i -X POST -H "Context-Type: application/json" -d '{"name": "golang"}' http://localhost:9000/api/v1/category/add curl -i -X POST -H "Context-Type: application/json" -d '{"name": "golang"}' http://localhost:9000/api/v1/category/add # 请求创建文章 curl -i -X POST -H "Context-Type: application/json" -d '{"titel": "分类1下的第一篇文章","cid": 1,"desc": "分类1下的第一篇文章","content": "分类1下的第一篇文章","img": "upload/image/1.jpg"}' http://localhost:9000/api/v1/article/add curl -i -X POST -H "Context-Type: application/json" -d '{"titel": "分类1下的第二篇文章","cid": 1,"desc": "分类1下的第二篇文章","content": "分类1下的第二篇文章","img": "upload/image/1.jpg"}' http://localhost:9000/api/v1/article/add # 登录验证,可以获取到token curl -i -X POST -H "Context-Type: application/json" -d '{"username": "admin","password": "123456"}' http://localhost:9000/api/v1/login # 上传文件 curl -i -X POST -F "file=@1.png" -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiZXhwIjoxNjQyMDYxNTc0LCJpc3MiOiJibG9nIn0.5NnpUtzQGV_45d2x1AnDI1-QbyOfKE3CgM8BhOK9FUg" http://localhost:9000/api/v1/upload curl -i -X POST -F "file=@1.png" -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiZXhwIjoxNjQ1MTY2NDc1LCJpc3MiOiJibG9nIn0.RK8OodIkBuopvuZL3aFnAipK2VaIckYLNlWRepGqJTs" http://localhost:9000/api/v1/upload ``` get 请求: ```bash # 查询用户列表;查询分页 pageSize(每页个数) pageNum(当前页码) curl -i http://localhost:9000/api/v1/user/get?pagesize=&pagenum= # 查询分类列表 curl -i http://localhost:9000/api/v1/category/get?pagesize=&pagenum= curl -i http://localhost:9000/api/v1/category/get?pagesize=3&pagenum=1 # 查询文章列表 curl -i http://localhost:9000/api/v1/article/get?pagesize=&pagenum= # 查询分类下的文章 curl -i http://localhost:9000/api/v1/category/article/list/1?pagesize=3&pagenum=1 # 查询单个文章信息 curl -i http://localhost:9000/api/v1/category/article/info/1 ``` delete 请求: ```bash # 删除用户 http://localhost:9000/api/v1/user/del/:id curl -i -X DELETE http://localhost:9000/api/v1/user/del/2 # 使用 token 认证删除用户,需要登录验证获取到 token curl -i -X DELETE -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiZXhwIjoxNjQxOTc1NTUyLCJpc3MiOiJibG9nIn0.rdXWTPgW_bjAdhhmTNqPMaqfAHdclrLCKDvGRszJgPw" http://localhost:9000/api/v1/user/del/3 # 删除分类 http://localhost:9000/api/v1/category/del/:id curl -i -X DELETE http://localhost:9000/api/v1/category/del/2 # 删除文章 curl -i -X DELETE http://localhost:9000/api/v1/article/del/2 ``` put 请求: ```bash # 编辑用户 http://localhost:9000/api/v1/user/edit/:id curl -i -X PUT -H "Context-Type: application/json" -d '{"username": "test1put","role": 0}' http://localhost:9000/api/v1/user/edit/3 # 编辑分类 http://localhost:9000/api/v1/category/edit/:id curl -i -X PUT -H "Context-Type: application/json" -d '{"name": "javatest"}' http://localhost:9000/api/v1/category/edit/3 # 编辑文章 curl -i -X PUT -H "Context-Type: application/json" -d '{"titel": "分类1下的第二篇文章","cid": 2,"desc": "分类1下的第二篇文章","content": "分类1下的第二篇文章","img": "upload/image/1.jpg"}' http://localhost:9000/api/v1/article/edit/3 ``` 安装 nodejs,vue ```bash wget https://nodejs.org/dist/v16.13.2/node-v16.13.2-linux-x64.tar.xz -P /usr/local tar -xf /usr/local/node-v16.13.2-linux-x64.tar.xz -C /usr/local rm -f /usr/local/node-v16.13.2-linux-x64.tar.xz ln -s /usr/local/node-v16.13.2-linux-x64 /usr/local/node echo "export PATH=$PATH:/usr/local/node/bin" >> /etc/profile.d/env.sh source /etc/profile.d/env.sh npm install -g cnpm --registry=https://registry.npm.taobao.org cnpm install -g @vue/cli npm install --global yarn # 后端 admin 项目依赖 yarn add ant-design-vue --dev yarn add axios yarn add babel-plugin-import --dev ``` vue遇到问题: ```bash # Error: ENOSPC: System limit for number of file watchers reached, echo "fs.inotify.max_user_watches=524288" >> /etc/sysctl.conf && sysctl -p ```