├── .gitattributes ├── .github └── workflows │ └── docker-image.yml ├── .gitignore ├── LICENSE ├── Makefile ├── README.MD ├── api ├── account │ ├── account.go │ └── v1 │ │ └── account.go ├── article │ ├── app │ │ └── article.go │ ├── article.go │ └── v1 │ │ └── article.go ├── article_grp │ ├── app │ │ └── article_grp.go │ ├── article_grp.go │ └── v1 │ │ └── article_grp.go ├── file │ ├── file.go │ └── v1 │ │ └── file.go ├── link │ ├── link.go │ └── v1 │ │ └── link.go ├── login │ ├── login.go │ └── v1 │ │ └── login.go ├── other │ ├── app │ │ └── other.go │ └── other.go ├── reading │ ├── reading.go │ └── v1 │ │ └── reading.go ├── reply │ ├── app │ │ └── reply.go │ ├── reply.go │ └── v1 │ │ └── reply.go ├── sentence │ ├── sentence.go │ └── v1 │ │ ├── sentence.go │ │ └── sentence_struct.go ├── tag │ ├── tag.go │ └── v1 │ │ ├── tag.go │ │ └── tag_struct.go └── tag_grp │ ├── tag_grp.go │ └── v1 │ ├── tag_grp.go │ └── tag_grp_struct.go ├── go.mod ├── go.sum ├── hack └── config.yaml ├── internal ├── cmd │ └── cmd.go ├── consts │ └── consts.go ├── controller │ ├── account │ │ ├── account.go │ │ ├── account_new.go │ │ ├── account_v1_info.go │ │ └── account_v1_logout.go │ ├── article │ │ ├── article.go │ │ ├── article_app_about.go │ │ ├── article_app_hist.go │ │ ├── article_app_list.go │ │ ├── article_app_rank.go │ │ ├── article_app_reply.go │ │ ├── article_app_show.go │ │ ├── article_new.go │ │ ├── article_v1_cre.go │ │ ├── article_v1_del.go │ │ ├── article_v1_list.go │ │ ├── article_v1_re_cre.go │ │ ├── article_v1_show.go │ │ └── article_v1_upd.go │ ├── article_grp │ │ ├── article_grp.go │ │ ├── article_grp_app_list.go │ │ ├── article_grp_new.go │ │ ├── article_grp_v1_cre.go │ │ ├── article_grp_v1_del.go │ │ ├── article_grp_v1_list.go │ │ ├── article_grp_v1_show.go │ │ └── article_grp_v1_upd.go │ ├── file │ │ ├── file.go │ │ ├── file_new.go │ │ └── file_v1_upload.go │ ├── link │ │ ├── link.go │ │ ├── link_new.go │ │ ├── link_v1_link_cre.go │ │ ├── link_v1_link_del.go │ │ ├── link_v1_link_list.go │ │ └── link_v1_link_upd.go │ ├── login │ │ ├── login.go │ │ ├── login_new.go │ │ └── login_v1_login.go │ ├── other │ │ ├── other.go │ │ ├── other_app_link.go │ │ ├── other_app_reading.go │ │ ├── other_app_saying.go │ │ └── other_new.go │ ├── reading │ │ ├── reading.go │ │ ├── reading_new.go │ │ └── reading_v1_reading.go │ ├── reply │ │ ├── reply.go │ │ ├── reply_app_reply.go │ │ ├── reply_new.go │ │ ├── reply_v1_reply_check.go │ │ ├── reply_v1_reply_cre.go │ │ ├── reply_v1_reply_del.go │ │ ├── reply_v1_reply_list.go │ │ ├── reply_v1_reply_show.go │ │ └── reply_v1_reply_upd.go │ ├── sentence │ │ ├── sentence.go │ │ ├── sentence_new.go │ │ ├── sentence_v1_cre.go │ │ ├── sentence_v1_del.go │ │ ├── sentence_v1_list.go │ │ ├── sentence_v1_show.go │ │ └── sentence_v1_upd.go │ ├── tag │ │ ├── tag.go │ │ ├── tag_new.go │ │ ├── tag_v1_cre.go │ │ ├── tag_v1_del.go │ │ ├── tag_v1_list.go │ │ ├── tag_v1_show.go │ │ └── tag_v1_upd.go │ └── tag_grp │ │ ├── tag_grp.go │ │ ├── tag_grp_new.go │ │ ├── tag_grp_v1_cre.go │ │ ├── tag_grp_v1_del.go │ │ ├── tag_grp_v1_list.go │ │ ├── tag_grp_v1_show.go │ │ └── tag_grp_v1_upd.go ├── dao │ ├── .gitkeep │ ├── admin.go │ ├── article.go │ ├── article_grp.go │ ├── internal │ │ ├── admin.go │ │ ├── article.go │ │ ├── article_grp.go │ │ ├── link.go │ │ ├── reading.go │ │ ├── reply.go │ │ ├── sentence.go │ │ ├── sentence_tag.go │ │ ├── sentence_tags.go │ │ ├── tag.go │ │ └── tag_grp.go │ ├── link.go │ ├── reading.go │ ├── reply.go │ ├── sentence.go │ ├── sentence_tag.go │ ├── tag.go │ └── tag_grp.go ├── logic │ ├── account │ │ └── account.go │ ├── admin │ │ └── admin.go │ ├── article │ │ └── article.go │ ├── article_grp │ │ └── article_grp.go │ ├── file │ │ └── file.go │ ├── link │ │ └── link.go │ ├── logic.go │ ├── middleware │ │ ├── auth.go │ │ └── response.go │ ├── reading │ │ └── reading.go │ ├── reply │ │ └── reply.go │ ├── rich │ │ └── rich.go │ ├── sentence │ │ └── sentence.go │ ├── tag │ │ └── tag.go │ └── tag_grp │ │ └── tag_grp.go ├── model │ ├── admin.go │ ├── article.go │ ├── article_grp.go │ ├── dataType.go │ ├── do │ │ ├── .gitkeep │ │ ├── admin.go │ │ ├── article.go │ │ ├── article_grp.go │ │ ├── link.go │ │ ├── reading.go │ │ ├── reply.go │ │ ├── sentence.go │ │ ├── sentence_tag.go │ │ ├── tag.go │ │ └── tag_grp.go │ ├── entity │ │ ├── .gitkeep │ │ ├── admin.go │ │ ├── article.go │ │ ├── article_grp.go │ │ ├── link.go │ │ ├── reading.go │ │ ├── reply.go │ │ ├── sentence.go │ │ ├── sentence_tag.go │ │ ├── tag.go │ │ └── tag_grp.go │ ├── file.go │ ├── link.go │ ├── reply.go │ └── sentence.go ├── service │ ├── account.go │ ├── admin.go │ ├── article.go │ ├── article_grp.go │ ├── file.go │ ├── link.go │ ├── middleware.go │ ├── reading.go │ ├── reply.go │ ├── rich.go │ ├── saying.go │ ├── sentence.go │ ├── tag.go │ └── tag_grp.go └── utility │ ├── err.go │ └── ext.go ├── main.go ├── manifest ├── config │ └── config.yaml ├── deploy │ └── kustomize │ │ ├── base │ │ ├── deployment.yaml │ │ ├── kustomization.yaml │ │ └── service.yaml │ │ └── overlays │ │ └── develop │ │ ├── configmap.yaml │ │ ├── deployment.yaml │ │ └── kustomization.yaml ├── docker │ └── Dockerfile ├── i18n │ └── zh-CN │ │ └── validation.toml ├── sql │ └── oldme.sql └── webserver │ └── oldme.conf ├── resource ├── i18n │ └── .gitkeep ├── public │ ├── html │ │ └── .gitkeep │ ├── plugin │ │ └── .gitkeep │ └── resource │ │ ├── css │ │ └── .gitkeep │ │ ├── image │ │ └── .gitkeep │ │ └── js │ │ └── .gitkeep └── template │ └── .gitkeep ├── test ├── gen_admin_test.go └── rich_test.go └── utility ├── gother.go ├── other.go ├── ufile └── file.go ├── uinit └── uinit.go ├── ujwt └── jwt.go └── uregex └── uregex.go /.gitattributes: -------------------------------------------------------------------------------- 1 | * linguist-language=GO -------------------------------------------------------------------------------- /.github/workflows/docker-image.yml: -------------------------------------------------------------------------------- 1 | name: Docker Image CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | env: 9 | TZ: "Asia/Shanghai" 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - name: Checkout Repository 17 | uses: actions/checkout@v4 18 | 19 | - name: Setup Go 20 | uses: actions/setup-go@v5 21 | with: 22 | go-version: "1.22.2" 23 | 24 | - name: Check Go Version 25 | run: go version 26 | 27 | - name: Install Dependencies 28 | run: go mod download 29 | 30 | - name: Build the Docker image 31 | run: | 32 | GOOS=linux GOARCH=amd64 go build -o main main.go 33 | 34 | docker login --username=${{ secrets.DOCKER_USERNAME }} --password=${{ secrets.DOCKER_PASSWORD }} registry.cn-hangzhou.aliyuncs.com 35 | docker build . --file manifest/docker/Dockerfile --tag registry.cn-hangzhou.aliyuncs.com/oldme/oldme-api:latest 36 | docker push registry.cn-hangzhou.aliyuncs.com/oldme/oldme-api:latest 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .buildpath 2 | .hgignore.swp 3 | .project 4 | .orig 5 | .swp 6 | .idea/ 7 | .settings/ 8 | .vscode/ 9 | vendor/ 10 | composer.lock 11 | gitpush.sh 12 | pkg/ 13 | bin/ 14 | cbuild 15 | **/.DS_Store 16 | .test/ 17 | main 18 | output/ 19 | manifest/output/ 20 | temp/ 21 | /main.exe 22 | log 23 | /*.exe~ 24 | static 25 | /oldme-api 26 | linux_amd64 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 oldme 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ROOT_DIR = $(shell pwd) 2 | NAMESPACE = "default" 3 | DEPLOY_NAME = "template-single" 4 | DOCKER_NAME = "template-single" 5 | 6 | # Install/Update to the latest CLI tool. 7 | .PHONY: cli 8 | cli: 9 | @set -e; \ 10 | wget -O gf https://github.com/gogf/gf/releases/latest/download/gf_$(shell go env GOOS)_$(shell go env GOARCH) && \ 11 | chmod +x gf && \ 12 | ./gf install -y && \ 13 | rm ./gf 14 | 15 | 16 | # Check and install CLI tool. 17 | .PHONY: cli.install 18 | cli.install: 19 | @set -e; \ 20 | gf -v > /dev/null 2>&1 || if [[ "$?" -ne "0" ]]; then \ 21 | echo "GoFame CLI is not installed, start proceeding auto installation..."; \ 22 | make cli; \ 23 | fi; 24 | 25 | 26 | # Generate Go files for DAO/DO/Entity. 27 | .PHONY: dao 28 | dao: cli.install 29 | @gf gen dao 30 | 31 | # Generate Go files for Service. 32 | .PHONY: service 33 | service: cli.install 34 | @gf gen service 35 | 36 | # Build image, deploy image and yaml to current kubectl environment and make port forward to local machine. 37 | .PHONY: start 38 | start: 39 | @set -e; \ 40 | make image; \ 41 | make deploy; \ 42 | make port; 43 | 44 | # Build docker image. 45 | .PHONY: image 46 | image: cli.install 47 | $(eval _TAG = $(shell git log -1 --format="%cd.%h" --date=format:"%Y%m%d%H%M%S")) 48 | ifneq (, $(shell git status --porcelain 2>/dev/null)) 49 | $(eval _TAG = $(_TAG).dirty) 50 | endif 51 | $(eval _TAG = $(if ${TAG}, ${TAG}, $(_TAG))) 52 | $(eval _PUSH = $(if ${PUSH}, ${PUSH}, )) 53 | @gf docker -p -b "-a amd64 -s linux -p temp" -tn $(DOCKER_NAME):${_TAG}; 54 | 55 | 56 | # Build docker image and automatically push to docker repo. 57 | .PHONY: image.push 58 | image.push: 59 | @make image PUSH=-p; 60 | 61 | 62 | # Deploy image and yaml to current kubectl environment. 63 | .PHONY: deploy 64 | deploy: 65 | $(eval _TAG = $(if ${TAG}, ${TAG}, develop)) 66 | 67 | @set -e; \ 68 | mkdir -p $(ROOT_DIR)/temp/kustomize;\ 69 | cd $(ROOT_DIR)/manifest/deploy/kustomize/overlays/${_TAG};\ 70 | kustomize build > $(ROOT_DIR)/temp/kustomize.yaml;\ 71 | kubectl apply -f $(ROOT_DIR)/temp/kustomize.yaml; \ 72 | kubectl patch -n $(NAMESPACE) deployment/$(DEPLOY_NAME) -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"$(shell date +%s)\"}}}}}"; 73 | 74 | 75 | -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | # oldme 个人博客接口 2 | - https://oldme.net 个人博客网站,本项目可以做为 `GoFrame` 的初学参考,会一直更新使用 `Go` 和 `GF` 的最新版本 3 | - 使用 `Go` + `GoFrame` 开发,感谢 `GoFrame`:https://github.com/gogf/gf 4 | - 后台登录组件使用golang-jwt/jwt:https://github.com/golang-jwt/jwt 5 | - 前端基于 `Vue3` + `Nuxt3` 开发 6 | 7 | # 版本信息 8 | - Go v1.22+ 9 | - GoFrame v2.8.3+ 10 | 版本信息以`go.mod`为准 11 | 12 | # 功能模块 13 | - 文章分类管理 14 | - 文章发布 15 | - 句子收集 16 | - 友情链接 17 | - 文章回复功能 18 | - 图片文件上传 19 | - 富文本图片文件处理 20 | - 后台登录认证 21 | 22 | # 部署 23 | - git clone https://github.com/oldme-git/oldme-api 24 | - 安装 mysql 数据库,运行 manifest/sql/oldme.sql 文件 25 | - 安装 redis 26 | - 修改 manifest/config下config.yaml配置文件 27 | - 安装 go.mod 依赖 28 | - 运行 go run main.go 29 | -------------------------------------------------------------------------------- /api/account/account.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package account 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/oldme-git/oldme-api/api/account/v1" 11 | ) 12 | 13 | type IAccountV1 interface { 14 | Logout(ctx context.Context, req *v1.LogoutReq) (res *v1.LogoutRes, err error) 15 | Info(ctx context.Context, req *v1.InfoReq) (res *v1.InfoRes, err error) 16 | } 17 | -------------------------------------------------------------------------------- /api/account/v1/account.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/frame/g" 5 | "github.com/gogf/gf/v2/os/gtime" 6 | ) 7 | 8 | type LogoutReq struct { 9 | g.Meta `path:"logout" method:"post" sm:"登出" tags:"账户"` 10 | Token string 11 | } 12 | 13 | type LogoutRes struct { 14 | Result bool 15 | } 16 | 17 | type InfoReq struct { 18 | g.Meta `path:"info" method:"get" sm:"获取登录信息" tags:"账户"` 19 | } 20 | 21 | type InfoRes struct { 22 | Username string `json:"username" dc:"用户名"` 23 | Nickname string `json:"nickname" dc:"昵称"` 24 | Avatar string `json:"avatar" dc:"头像"` 25 | Register *gtime.Time `json:"register" dc:"注册时间"` 26 | LastLogin *gtime.Time `json:"lastLogin" dc:"最后登录时间"` 27 | } 28 | -------------------------------------------------------------------------------- /api/article/app/article.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/frame/g" 5 | "github.com/gogf/gf/v2/os/gtime" 6 | "github.com/oldme-git/oldme-api/internal/model" 7 | ) 8 | 9 | type ( 10 | ListReq struct { 11 | g.Meta `path:"article/list/*grpId" method:"get" sm:"查询列表" tags:"app"` 12 | model.Paging 13 | GrpId model.Id `v:"integer|between:1,4294967295" json:"grpId"` 14 | Search string `v:"length: 1,30" json:"search" dc:"查询文本,会检索标题、标签、简介"` 15 | } 16 | 17 | ListRes struct { 18 | List []List `json:"list"` 19 | Total uint `json:"total"` 20 | } 21 | ) 22 | 23 | type ( 24 | RankReq struct { 25 | g.Meta `path:"article/rank" method:"get" sm:"查询文章排行" tags:"app"` 26 | Basis int `v:"required|in:1,2" dc:"1-热门文章 2-最新文章"` 27 | } 28 | 29 | RankRes struct { 30 | List []List `json:"list"` 31 | } 32 | ) 33 | 34 | type ( 35 | ShowReq struct { 36 | g.Meta `path:"article/show/{id}" method:"get" sm:"查询详情" tags:"app"` 37 | *model.IdInput 38 | } 39 | 40 | ShowRes struct { 41 | *One 42 | } 43 | ) 44 | 45 | type ( 46 | AboutReq struct { 47 | g.Meta `path:"about" method:"get" sm:"查询关于我们" tags:"app"` 48 | } 49 | 50 | AboutRes struct { 51 | *One 52 | } 53 | ) 54 | 55 | type ( 56 | HistReq struct { 57 | g.Meta `path:"article/hist" method:"post" sm:"增加一个点击数" tags:"app"` 58 | *model.IdInput 59 | } 60 | 61 | HistRes struct { 62 | } 63 | ) 64 | 65 | type ( 66 | ReplyReq struct { 67 | g.Meta `path:"article/reply/{id}" method:"get" sm:"查看该文章的回复" tags:"app"` 68 | *model.IdInput 69 | } 70 | 71 | ReplyRes struct { 72 | List []model.ReplyFloorApp `json:"list"` 73 | Total uint `json:"total"` 74 | } 75 | ) 76 | 77 | type ( 78 | List struct { 79 | Id uint `json:"id" description:""` 80 | GrpId uint `json:"grpId" description:"分组id"` 81 | Title string `json:"title" description:"标题"` 82 | Author string `json:"author" description:"作者"` 83 | Thumb string `json:"thumb" description:"图片地址"` 84 | Tags string `json:"tags" description:"标签,依英文逗号隔开"` 85 | Description string `json:"description" description:"简介"` 86 | Hist uint `json:"hist" description:"点击数"` 87 | Post uint `json:"post" description:"评论数"` 88 | CreatedAt *gtime.Time `json:"createdAt" description:"创建时间"` 89 | UpdatedAt *gtime.Time `json:"updatedAt" description:"更新时间"` 90 | LastedAt *gtime.Time `json:"lastedAt" description:"最后浏览时间"` 91 | } 92 | 93 | One struct { 94 | Id uint `json:"id" description:""` 95 | GrpId uint `json:"grpId" description:"分组id"` 96 | Title string `json:"title" description:"标题"` 97 | Author string `json:"author" description:"作者"` 98 | Thumb string `json:"thumb" description:"图片地址"` 99 | Tags string `json:"tags" description:"标签,依英文逗号隔开"` 100 | Description string `json:"description" description:"简介"` 101 | Content string `json:"content" description:"内容"` 102 | Hist uint `json:"hist" description:"点击数"` 103 | Post uint `json:"post" description:"评论数"` 104 | CreatedAt *gtime.Time `json:"createdAt" description:"创建时间"` 105 | UpdatedAt *gtime.Time `json:"updatedAt" description:"更新时间"` 106 | LastedAt *gtime.Time `json:"lastedAt" description:"最后浏览时间"` 107 | } 108 | ) 109 | -------------------------------------------------------------------------------- /api/article/article.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package article 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/oldme-git/oldme-api/api/article/app" 11 | "github.com/oldme-git/oldme-api/api/article/v1" 12 | ) 13 | 14 | type IArticleApp interface { 15 | List(ctx context.Context, req *app.ListReq) (res *app.ListRes, err error) 16 | Rank(ctx context.Context, req *app.RankReq) (res *app.RankRes, err error) 17 | Show(ctx context.Context, req *app.ShowReq) (res *app.ShowRes, err error) 18 | About(ctx context.Context, req *app.AboutReq) (res *app.AboutRes, err error) 19 | Hist(ctx context.Context, req *app.HistReq) (res *app.HistRes, err error) 20 | Reply(ctx context.Context, req *app.ReplyReq) (res *app.ReplyRes, err error) 21 | } 22 | 23 | type IArticleV1 interface { 24 | Cre(ctx context.Context, req *v1.CreReq) (res *v1.CreRes, err error) 25 | Upd(ctx context.Context, req *v1.UpdReq) (res *v1.UpdRes, err error) 26 | Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) 27 | List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) 28 | Show(ctx context.Context, req *v1.ShowReq) (res *v1.ShowRes, err error) 29 | ReCre(ctx context.Context, req *v1.ReCreReq) (res *v1.ReCreRes, err error) 30 | } 31 | -------------------------------------------------------------------------------- /api/article/v1/article.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/frame/g" 5 | "github.com/gogf/gf/v2/os/gtime" 6 | "github.com/oldme-git/oldme-api/internal/model" 7 | ) 8 | 9 | type ( 10 | CreReq struct { 11 | g.Meta `path:"article/create" method:"post" sm:"新增" tags:"文章"` 12 | GrpId model.Id `json:"grpId" v:"required|integer|between:1,4294967295"` 13 | Title string `json:"title" v:"required|length:2, 100"` 14 | Author string `json:"author" v:"length:2, 30"` 15 | Thumb string `json:"thumb" v:"length:2, 200"` 16 | Tags string `json:"tags" v:"length:2, 200"` 17 | Description string `json:"description" v:"length:2, 200"` 18 | Content string `json:"content" v:"length:2, 100000"` 19 | Order int `json:"order" v:"integer|between:-9999,9999"` 20 | Ontop uint `json:"ontop" v:"boolean"` 21 | Onshow uint `json:"onshow" v:"boolean"` 22 | Hist uint `json:"hist" v:"integer|between:0,999999"` 23 | Post uint `json:"post" v:"integer|between:0,999999"` 24 | } 25 | 26 | CreRes struct { 27 | LastId model.Id `json:"lastId"` 28 | } 29 | ) 30 | 31 | type ( 32 | UpdReq struct { 33 | g.Meta `path:"article/update/{id}" method:"post" sm:"修改" tags:"文章"` 34 | *model.IdInput 35 | GrpId model.Id `json:"grpId" v:"required|integer|between:1,4294967295"` 36 | Title string `json:"title" v:"required|length:2, 100"` 37 | Author string `json:"author" v:"length:2, 30"` 38 | Thumb string `json:"thumb" v:"length:2, 200"` 39 | Tags string `json:"tags" v:"length:2, 200"` 40 | Description string `json:"description" v:"length:2, 200"` 41 | Content string `json:"content" v:"length:2, 100000"` 42 | Order int `json:"order" v:"integer|between:-9999,9999"` 43 | Ontop uint `json:"ontop" v:"boolean"` 44 | Onshow uint `json:"onshow" v:"boolean"` 45 | Hist uint `json:"hist" v:"integer|between:0,999999"` 46 | Post uint `json:"post" v:"integer|between:0,999999"` 47 | } 48 | 49 | UpdRes struct{} 50 | ) 51 | 52 | type ( 53 | DelReq struct { 54 | g.Meta `path:"article/delete/{id}" method:"post" sm:"删除" tags:"文章"` 55 | *model.IdInput 56 | IsReal bool `dc:"是否彻底删除"` 57 | } 58 | 59 | DelRes struct{} 60 | ) 61 | 62 | type ( 63 | ListReq struct { 64 | g.Meta `path:"article/list/*grpId" method:"get" sm:"查询列表" tags:"文章"` 65 | model.Paging 66 | GrpId model.Id `v:"integer|between:1,4294967295" json:"grpId"` 67 | Search string `v:"length: 1,30" json:"search" dc:"查询文本,会检索标题、标签、简介"` 68 | Onshow bool `json:"onshow" dc:"是否查询只发布的文章"` 69 | IsDel bool `json:"isDel" dc:"是否查询删除掉的文章"` 70 | } 71 | 72 | ListRes struct { 73 | List []List `json:"list"` 74 | Total uint `json:"total"` 75 | } 76 | ) 77 | 78 | type ( 79 | ShowReq struct { 80 | g.Meta `path:"article/show/{id}" method:"get" sm:"查询详情" tags:"文章"` 81 | *model.IdInput 82 | } 83 | 84 | ShowRes struct { 85 | *One 86 | } 87 | ) 88 | 89 | type ( 90 | ReCreReq struct { 91 | g.Meta `path:"article/recreate/{id}" method:"post" sm:"找回文章" tags:"文章"` 92 | *model.IdInput 93 | } 94 | 95 | ReCreRes struct { 96 | } 97 | ) 98 | 99 | type ( 100 | List struct { 101 | Id uint `json:"id" description:""` 102 | GrpId uint `json:"grpId" description:"分组id"` 103 | Title string `json:"title" description:"标题"` 104 | Author string `json:"author" description:"作者"` 105 | Thumb string `json:"thumb" description:"图片地址"` 106 | Tags string `json:"tags" description:"标签,依英文逗号隔开"` 107 | Description string `json:"description" description:"简介"` 108 | Order int `json:"order" description:"排序,越大越靠前"` 109 | Ontop uint `json:"ontop" description:"是否置顶"` 110 | Onshow uint `json:"onshow" description:"是否显示"` 111 | Hist uint `json:"hist" description:"点击数"` 112 | Post uint `json:"post" description:"评论数"` 113 | CreatedAt *gtime.Time `json:"createdAt" description:"创建时间"` 114 | UpdatedAt *gtime.Time `json:"updatedAt" description:"更新时间"` 115 | LastedAt *gtime.Time `json:"lastedAt" description:"最后浏览时间"` 116 | } 117 | 118 | One struct { 119 | Id uint `json:"id" description:""` 120 | GrpId uint `json:"grpId" description:"分组id"` 121 | Title string `json:"title" description:"标题"` 122 | Author string `json:"author" description:"作者"` 123 | Thumb string `json:"thumb" description:"图片地址"` 124 | Tags string `json:"tags" description:"标签,依英文逗号隔开"` 125 | Description string `json:"description" description:"简介"` 126 | Content string `json:"content" description:"内容"` 127 | Order int `json:"order" description:"排序,越大越靠前"` 128 | Ontop uint `json:"ontop" description:"是否置顶"` 129 | Onshow uint `json:"onshow" description:"是否显示"` 130 | Hist uint `json:"hist" description:"点击数"` 131 | Post uint `json:"post" description:"评论数"` 132 | CreatedAt *gtime.Time `json:"createdAt" description:"创建时间"` 133 | UpdatedAt *gtime.Time `json:"updatedAt" description:"更新时间"` 134 | DeletedAt *gtime.Time `json:"deletedAt" description:"删除时间"` 135 | LastedAt *gtime.Time `json:"lastedAt" description:"最后浏览时间"` 136 | } 137 | ) 138 | -------------------------------------------------------------------------------- /api/article_grp/app/article_grp.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/frame/g" 5 | ) 6 | 7 | type ListReq struct { 8 | g.Meta `path:"article/group/list" method:"get" sm:"查询列表" tags:"app"` 9 | } 10 | 11 | type ListRes struct { 12 | List []List `json:"list"` 13 | } 14 | 15 | type List struct { 16 | Id uint `json:"id" description:""` 17 | Name string `json:"name" description:"名称"` 18 | Tags string `json:"tags" description:"标签,依英文逗号隔开"` 19 | Description string `json:"description" description:"简介"` 20 | ArticleCount uint `json:"article_count"` 21 | } 22 | -------------------------------------------------------------------------------- /api/article_grp/article_grp.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package article_grp 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/oldme-git/oldme-api/api/article_grp/app" 11 | "github.com/oldme-git/oldme-api/api/article_grp/v1" 12 | ) 13 | 14 | type IArticleGrpApp interface { 15 | List(ctx context.Context, req *app.ListReq) (res *app.ListRes, err error) 16 | } 17 | 18 | type IArticleGrpV1 interface { 19 | Cre(ctx context.Context, req *v1.CreReq) (res *v1.CreRes, err error) 20 | Upd(ctx context.Context, req *v1.UpdReq) (res *v1.UpdRes, err error) 21 | Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) 22 | List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) 23 | Show(ctx context.Context, req *v1.ShowReq) (res *v1.ShowRes, err error) 24 | } 25 | -------------------------------------------------------------------------------- /api/article_grp/v1/article_grp.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/frame/g" 5 | "github.com/oldme-git/oldme-api/internal/model" 6 | "github.com/oldme-git/oldme-api/internal/model/entity" 7 | ) 8 | 9 | type CreReq struct { 10 | g.Meta `path:"article/group/create" method:"post" sm:"新增" tags:"文章分类"` 11 | Name string `v:"required|length:2, 30"` 12 | Tags string `v:"length:1, 200"` 13 | Description string `v:"length:2, 200"` 14 | Onshow bool `v:"required"` 15 | Order int `json:"order" v:"integer|between:-9999,9999"` 16 | } 17 | 18 | type CreRes struct { 19 | } 20 | 21 | type UpdReq struct { 22 | g.Meta `path:"article/group/update/{id}" method:"post" sm:"修改" tags:"文章分类"` 23 | *model.IdInput 24 | Name string `v:"required|length:2, 30"` 25 | Tags string `v:"length:1, 200"` 26 | Description string `v:"length:2, 200"` 27 | Onshow bool `v:"required"` 28 | Order int `json:"order" v:"integer|between:-9999,9999"` 29 | } 30 | 31 | type UpdRes struct { 32 | } 33 | 34 | type DelReq struct { 35 | g.Meta `path:"article/group/delete/{id}" method:"post" sm:"删除" tags:"文章分类"` 36 | *model.IdInput 37 | } 38 | 39 | type DelRes struct { 40 | } 41 | 42 | type ListReq struct { 43 | g.Meta `path:"article/group/list" method:"get" sm:"查询列表" tags:"文章分类"` 44 | } 45 | 46 | type ListRes struct { 47 | List []entity.ArticleGrp `json:"list"` 48 | Total uint `json:"total"` 49 | } 50 | 51 | type ShowReq struct { 52 | g.Meta `path:"article/group/show/{id}" method:"get" sm:"查询详情" tags:"文章分类"` 53 | *model.IdInput 54 | } 55 | 56 | type ShowRes struct { 57 | *entity.ArticleGrp 58 | } 59 | -------------------------------------------------------------------------------- /api/file/file.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package file 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/oldme-git/oldme-api/api/file/v1" 11 | ) 12 | 13 | type IFileV1 interface { 14 | Upload(ctx context.Context, req *v1.UploadReq) (res *v1.UploadRes, err error) 15 | } 16 | -------------------------------------------------------------------------------- /api/file/v1/file.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/frame/g" 5 | "github.com/gogf/gf/v2/net/ghttp" 6 | "github.com/oldme-git/oldme-api/internal/model" 7 | ) 8 | 9 | type UploadReq struct { 10 | g.Meta `path:"file/upload/img" mime:"multipart/form-data" method:"post" sm:"上传文件到临时库" tags:"文件"` 11 | File *ghttp.UploadFile `json:"file" v:"required" type:"file" dc:"选择文件上传上传,Max:5M"` 12 | } 13 | 14 | type UploadRes struct { 15 | model.FileInfo 16 | } 17 | -------------------------------------------------------------------------------- /api/link/link.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package link 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/oldme-git/oldme-api/api/link/v1" 11 | ) 12 | 13 | type ILinkV1 interface { 14 | LinkCre(ctx context.Context, req *v1.LinkCreReq) (res *v1.LinkCreRes, err error) 15 | LinkUpd(ctx context.Context, req *v1.LinkUpdReq) (res *v1.LinkUpdRes, err error) 16 | LinkDel(ctx context.Context, req *v1.LinkDelReq) (res *v1.LinkDelRes, err error) 17 | LinkList(ctx context.Context, req *v1.LinkListReq) (res *v1.LinkListRes, err error) 18 | } 19 | -------------------------------------------------------------------------------- /api/link/v1/link.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/frame/g" 5 | "github.com/oldme-git/oldme-api/internal/model" 6 | "github.com/oldme-git/oldme-api/internal/model/entity" 7 | ) 8 | 9 | type LinkCreReq struct { 10 | g.Meta `path:"link/create" method:"post" sm:"新增" tags:"友链"` 11 | *model.LinkInput 12 | } 13 | 14 | type LinkCreRes struct { 15 | } 16 | 17 | type LinkUpdReq struct { 18 | g.Meta `path:"link/update/{id}" method:"post" sm:"修改" tags:"友链"` 19 | *model.IdInput 20 | *model.LinkInput 21 | } 22 | 23 | type LinkUpdRes struct { 24 | } 25 | 26 | type LinkDelReq struct { 27 | g.Meta `path:"link/delete/{id}" method:"post" sm:"删除" tags:"友链"` 28 | *model.IdInput 29 | } 30 | 31 | type LinkDelRes struct { 32 | } 33 | 34 | type LinkListReq struct { 35 | g.Meta `path:"link/list" method:"get" sm:"查询列表" tags:"友链"` 36 | } 37 | 38 | type LinkListRes struct { 39 | List []entity.Link `json:"list"` 40 | Total uint `json:"total"` 41 | } 42 | -------------------------------------------------------------------------------- /api/login/login.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package login 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/oldme-git/oldme-api/api/login/v1" 11 | ) 12 | 13 | type ILoginV1 interface { 14 | Login(ctx context.Context, req *v1.LoginReq) (res *v1.LoginRes, err error) 15 | } 16 | -------------------------------------------------------------------------------- /api/login/v1/login.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import "github.com/gogf/gf/v2/frame/g" 4 | 5 | type LoginReq struct { 6 | g.Meta `path:"login" method:"post" sm:"登录" tags:"账户"` 7 | Username string `v:"required|length: 3,20"` 8 | Password string `v:"required|length: 8,30"` 9 | } 10 | 11 | type LoginRes struct { 12 | Token string `sm:"凭据" dc:"在需要鉴权的接口中header加入Authorization: token"` 13 | } 14 | -------------------------------------------------------------------------------- /api/other/app/other.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/frame/g" 5 | "github.com/oldme-git/oldme-api/internal/model/entity" 6 | ) 7 | 8 | type ( 9 | SayingReq struct { 10 | g.Meta `path:"saying" method:"get" sm:"随机查询一条句子" tags:"app"` 11 | } 12 | 13 | SayingRes struct { 14 | Saying string 15 | } 16 | ) 17 | 18 | type ( 19 | LinkReq struct { 20 | g.Meta `path:"link" method:"get" sm:"查询友链" tags:"app"` 21 | } 22 | 23 | LinkRes struct { 24 | List []entity.Link `json:"list"` 25 | Total uint `json:"total"` 26 | } 27 | ) 28 | 29 | type ( 30 | ReadingReq struct { 31 | g.Meta `path:"reading" method:"get" sm:"查询阅读列表" tags:"app"` 32 | } 33 | 34 | ReadingRes struct { 35 | List []ReadingList `json:"list"` 36 | } 37 | 38 | ReadingList struct { 39 | Id uint `json:"id"` 40 | Name string `json:"name" sm:"书名"` 41 | Author string `json:"author" sm:"作者"` 42 | Status uint `json:"status" sm:"状态 1弃读 2完结 9在读"` 43 | FinishedAt string `json:"finished_at" sm:"完结时间"` 44 | } 45 | ) 46 | -------------------------------------------------------------------------------- /api/other/other.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package other 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/oldme-git/oldme-api/api/other/app" 11 | ) 12 | 13 | type IOtherApp interface { 14 | Saying(ctx context.Context, req *app.SayingReq) (res *app.SayingRes, err error) 15 | Link(ctx context.Context, req *app.LinkReq) (res *app.LinkRes, err error) 16 | Reading(ctx context.Context, req *app.ReadingReq) (res *app.ReadingRes, err error) 17 | } 18 | -------------------------------------------------------------------------------- /api/reading/reading.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package reading 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/oldme-git/oldme-api/api/reading/v1" 11 | ) 12 | 13 | type IReadingV1 interface { 14 | Reading(ctx context.Context, req *v1.ReadingReq) (res *v1.ReadingRes, err error) 15 | } 16 | -------------------------------------------------------------------------------- /api/reading/v1/reading.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/frame/g" 5 | "github.com/oldme-git/oldme-api/internal/model/entity" 6 | ) 7 | 8 | type ( 9 | ReadingReq struct { 10 | g.Meta `path:"reading" method:"get" sm:"查询阅读列表" tags:"reading"` 11 | } 12 | 13 | ReadingRes struct { 14 | List []entity.Reading `json:"list"` 15 | } 16 | ) 17 | -------------------------------------------------------------------------------- /api/reply/app/reply.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/frame/g" 5 | "github.com/oldme-git/oldme-api/internal/model" 6 | ) 7 | 8 | type ReplyReq struct { 9 | g.Meta `path:"reply" method:"post" sm:"文章回复" tags:"app"` 10 | *model.ReplyInputApp 11 | } 12 | 13 | type ReplyRes struct { 14 | } 15 | -------------------------------------------------------------------------------- /api/reply/reply.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package reply 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/oldme-git/oldme-api/api/reply/app" 11 | "github.com/oldme-git/oldme-api/api/reply/v1" 12 | ) 13 | 14 | type IReplyApp interface { 15 | Reply(ctx context.Context, req *app.ReplyReq) (res *app.ReplyRes, err error) 16 | } 17 | 18 | type IReplyV1 interface { 19 | ReplyCre(ctx context.Context, req *v1.ReplyCreReq) (res *v1.ReplyCreRes, err error) 20 | ReplyUpd(ctx context.Context, req *v1.ReplyUpdReq) (res *v1.ReplyUpdRes, err error) 21 | ReplyDel(ctx context.Context, req *v1.ReplyDelReq) (res *v1.ReplyDelRes, err error) 22 | ReplyList(ctx context.Context, req *v1.ReplyListReq) (res *v1.ReplyListRes, err error) 23 | ReplyShow(ctx context.Context, req *v1.ReplyShowReq) (res *v1.ReplyShowRes, err error) 24 | ReplyCheck(ctx context.Context, req *v1.ReplyCheckReq) (res *v1.ReplyCheckRes, err error) 25 | } 26 | -------------------------------------------------------------------------------- /api/reply/v1/reply.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/frame/g" 5 | "github.com/oldme-git/oldme-api/internal/model" 6 | "github.com/oldme-git/oldme-api/internal/model/entity" 7 | ) 8 | 9 | type ReplyCreReq struct { 10 | g.Meta `path:"reply/create" method:"post" sm:"新增" tags:"文章回复"` 11 | *model.ReplyInput 12 | } 13 | 14 | type ReplyCreRes struct { 15 | } 16 | 17 | type ReplyUpdReq struct { 18 | g.Meta `path:"reply/update/{id}" method:"post" sm:"修改" tags:"文章回复"` 19 | *model.IdInput 20 | *model.ReplyBody 21 | } 22 | 23 | type ReplyUpdRes struct { 24 | } 25 | 26 | type ReplyDelReq struct { 27 | g.Meta `path:"reply/delete/{id}" method:"post" sm:"删除" tags:"文章回复"` 28 | *model.IdInput 29 | } 30 | 31 | type ReplyDelRes struct { 32 | } 33 | 34 | type ReplyListReq struct { 35 | g.Meta `path:"reply/list" method:"get" sm:"查询列表" tags:"文章回复"` 36 | *model.ReplyQuery 37 | } 38 | 39 | type ReplyListRes struct { 40 | List []entity.Reply `json:"list"` 41 | Total uint `json:"total"` 42 | } 43 | 44 | type ReplyShowReq struct { 45 | g.Meta `path:"reply/show/{id}" method:"get" sm:"查询详情" tags:"文章回复"` 46 | *model.IdInput 47 | } 48 | 49 | type ReplyShowRes struct { 50 | *model.ReplyShow 51 | } 52 | 53 | type ReplyCheckReq struct { 54 | g.Meta `path:"reply/check/{id}" method:"post" sm:"审核" tags:"文章回复"` 55 | *model.IdInput 56 | Result bool `json:"result" v:"required" dc:"审核结果:true成功,false失败"` 57 | Reason string `json:"reason" v:"length:1, 200" dc:"失败原因"` 58 | } 59 | 60 | type ReplyCheckRes struct { 61 | } 62 | -------------------------------------------------------------------------------- /api/sentence/sentence.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package sentence 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/oldme-git/oldme-api/api/sentence/v1" 11 | ) 12 | 13 | type ISentenceV1 interface { 14 | Cre(ctx context.Context, req *v1.CreReq) (res *v1.CreRes, err error) 15 | Upd(ctx context.Context, req *v1.UpdReq) (res *v1.UpdRes, err error) 16 | Show(ctx context.Context, req *v1.ShowReq) (res *v1.ShowRes, err error) 17 | Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) 18 | List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) 19 | } 20 | -------------------------------------------------------------------------------- /api/sentence/v1/sentence.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/frame/g" 5 | "github.com/oldme-git/oldme-api/internal/model" 6 | "github.com/oldme-git/oldme-api/internal/model/entity" 7 | ) 8 | 9 | type CreReq struct { 10 | g.Meta `path:"sentence/create" method:"post" sm:"新增" tags:"句子"` 11 | BookId model.Id `json:"book_id" v:"required"` 12 | TagIds []model.Id `json:"tag_ids"` 13 | Sentence string `json:"sentence" v:"required"` 14 | } 15 | 16 | type CreRes struct { 17 | } 18 | 19 | type UpdReq struct { 20 | g.Meta `path:"sentence/update/{id}" method:"post" sm:"修改" tags:"句子"` 21 | *model.IdInput 22 | BookId model.Id `json:"book_id" v:"required"` 23 | TagIds []model.Id `json:"tag_ids"` 24 | Sentence string `json:"sentence" v:"required"` 25 | } 26 | 27 | type UpdRes struct { 28 | } 29 | 30 | type ShowReq struct { 31 | g.Meta `path:"sentence/show/{id}" method:"get" sm:"查询详情" tags:"句子"` 32 | *model.IdInput 33 | } 34 | 35 | type ShowRes struct { 36 | *entity.Sentence 37 | TagList []entity.Tag `json:"tag_list"` 38 | } 39 | 40 | type DelReq struct { 41 | g.Meta `path:"sentence/delete/{id}" method:"post" sm:"删除" tags:"句子"` 42 | *model.IdInput 43 | } 44 | 45 | type DelRes struct { 46 | } 47 | 48 | type ListReq struct { 49 | g.Meta `path:"sentence/list" method:"get" sm:"查询列表" tags:"句子"` 50 | *model.Paging 51 | BookId model.Id `json:"book_id" dc:"书籍id"` 52 | TagIds []model.Id `json:"tag_ids" dc:"标签id"` 53 | Search string `json:"search" dc:"搜索文本"` 54 | } 55 | 56 | type ListRes struct { 57 | List []List `json:"list"` 58 | Total uint `json:"total"` 59 | } 60 | -------------------------------------------------------------------------------- /api/sentence/v1/sentence_struct.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import "github.com/oldme-git/oldme-api/internal/model" 4 | 5 | type List struct { 6 | Id model.Id `json:"id"` 7 | BookId model.Id `json:"book_id"` 8 | Sentence string `json:"sentence"` 9 | } 10 | -------------------------------------------------------------------------------- /api/tag/tag.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package tag 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/oldme-git/oldme-api/api/tag/v1" 11 | ) 12 | 13 | type ITagV1 interface { 14 | Cre(ctx context.Context, req *v1.CreReq) (res *v1.CreRes, err error) 15 | Upd(ctx context.Context, req *v1.UpdReq) (res *v1.UpdRes, err error) 16 | Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) 17 | List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) 18 | Show(ctx context.Context, req *v1.ShowReq) (res *v1.ShowRes, err error) 19 | } 20 | -------------------------------------------------------------------------------- /api/tag/v1/tag.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/frame/g" 5 | "github.com/oldme-git/oldme-api/internal/model" 6 | "github.com/oldme-git/oldme-api/internal/model/entity" 7 | ) 8 | 9 | type CreReq struct { 10 | g.Meta `path:"tag/create" method:"post" sm:"新增" tags:"标签"` 11 | GrpId model.Id `json:"grpId" v:"required|integer|between:1,4294967295"` 12 | Name string `json:"name" v:"required|length:1, 30"` 13 | } 14 | 15 | type CreRes struct { 16 | } 17 | 18 | type UpdReq struct { 19 | g.Meta `path:"tag/update/{id}" method:"post" sm:"修改" tags:"标签"` 20 | *model.IdInput 21 | GrpId model.Id `json:"grpId" v:"required|integer|between:1,4294967295"` 22 | Name string `json:"name" v:"required|length:1, 30"` 23 | } 24 | 25 | type UpdRes struct { 26 | } 27 | 28 | type DelReq struct { 29 | g.Meta `path:"tag/delete/{id}" method:"post" sm:"删除" tags:"标签"` 30 | *model.IdInput 31 | } 32 | 33 | type DelRes struct { 34 | } 35 | 36 | type ListReq struct { 37 | g.Meta `path:"tag/list" method:"get" sm:"查询列表" tags:"标签"` 38 | GrpId model.Id `json:"grpId" v:"required|integer|between:1,4294967295"` 39 | } 40 | 41 | type ListRes struct { 42 | List []List `json:"list"` 43 | } 44 | 45 | type ShowReq struct { 46 | g.Meta `path:"tag/show/{id}" method:"get" sm:"查询详情" tags:"标签"` 47 | *model.IdInput 48 | } 49 | 50 | type ShowRes struct { 51 | *entity.Tag 52 | } 53 | -------------------------------------------------------------------------------- /api/tag/v1/tag_struct.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import "github.com/oldme-git/oldme-api/internal/model" 4 | 5 | type List struct { 6 | Id model.Id `json:"id"` 7 | Name string `json:"name"` 8 | } 9 | -------------------------------------------------------------------------------- /api/tag_grp/tag_grp.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package tag_grp 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/oldme-git/oldme-api/api/tag_grp/v1" 11 | ) 12 | 13 | type ITagGrpV1 interface { 14 | Cre(ctx context.Context, req *v1.CreReq) (res *v1.CreRes, err error) 15 | Upd(ctx context.Context, req *v1.UpdReq) (res *v1.UpdRes, err error) 16 | Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) 17 | Show(ctx context.Context, req *v1.ShowReq) (res *v1.ShowRes, err error) 18 | List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) 19 | } 20 | -------------------------------------------------------------------------------- /api/tag_grp/v1/tag_grp.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/frame/g" 5 | "github.com/oldme-git/oldme-api/internal/model" 6 | "github.com/oldme-git/oldme-api/internal/model/entity" 7 | ) 8 | 9 | type CreReq struct { 10 | g.Meta `path:"tag/group/create" method:"post" sm:"新增" tags:"标签分类"` 11 | Name string `json:"name" v:"required|length:1, 30"` 12 | } 13 | 14 | type CreRes struct { 15 | } 16 | 17 | type UpdReq struct { 18 | g.Meta `path:"tag/group/update/{id}" method:"post" sm:"修改" tags:"标签分类"` 19 | *model.IdInput 20 | Name string `json:"name" v:"required|length:1, 30"` 21 | } 22 | 23 | type UpdRes struct { 24 | } 25 | 26 | type DelReq struct { 27 | g.Meta `path:"tag/group/delete/{id}" method:"post" sm:"删除" tags:"标签分类"` 28 | *model.IdInput 29 | } 30 | 31 | type DelRes struct { 32 | } 33 | 34 | type ShowReq struct { 35 | g.Meta `path:"tag/group/show/{id}" method:"get" sm:"查询详情" tags:"标签分类"` 36 | *model.IdInput 37 | } 38 | 39 | type ShowRes struct { 40 | *entity.TagGrp 41 | } 42 | 43 | type ListReq struct { 44 | g.Meta `path:"tag/group/list" method:"get" sm:"查询列表" tags:"标签分类"` 45 | } 46 | 47 | type ListRes struct { 48 | List []List `json:"list"` 49 | } 50 | -------------------------------------------------------------------------------- /api/tag_grp/v1/tag_grp_struct.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import "github.com/oldme-git/oldme-api/internal/model" 4 | 5 | type List struct { 6 | Id model.Id `json:"id"` 7 | Name string `json:"name"` 8 | } 9 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/oldme-git/oldme-api 2 | 3 | go 1.22.2 4 | 5 | require ( 6 | github.com/dlclark/regexp2 v1.10.0 7 | github.com/gogf/gf/contrib/drivers/mysql/v2 v2.8.3 8 | github.com/gogf/gf/contrib/nosql/redis/v2 v2.8.3 9 | github.com/gogf/gf/v2 v2.8.3 10 | github.com/golang-jwt/jwt/v5 v5.2.1 11 | ) 12 | 13 | require ( 14 | filippo.io/edwards25519 v1.1.0 // indirect 15 | github.com/BurntSushi/toml v1.4.0 // indirect 16 | github.com/cespare/xxhash/v2 v2.3.0 // indirect 17 | github.com/clbanning/mxj/v2 v2.7.0 // indirect 18 | github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect 19 | github.com/emirpasic/gods v1.18.1 // indirect 20 | github.com/fatih/color v1.18.0 // indirect 21 | github.com/fsnotify/fsnotify v1.7.0 // indirect 22 | github.com/go-logr/logr v1.4.2 // indirect 23 | github.com/go-logr/stdr v1.2.2 // indirect 24 | github.com/go-sql-driver/mysql v1.8.1 // indirect 25 | github.com/gorilla/websocket v1.5.3 // indirect 26 | github.com/grokify/html-strip-tags-go v0.1.0 // indirect 27 | github.com/magiconair/properties v1.8.9 // indirect 28 | github.com/mattn/go-colorable v0.1.13 // indirect 29 | github.com/mattn/go-isatty v0.0.20 // indirect 30 | github.com/mattn/go-runewidth v0.0.16 // indirect 31 | github.com/olekukonko/tablewriter v0.0.5 // indirect 32 | github.com/redis/go-redis/v9 v9.7.0 // indirect 33 | github.com/rivo/uniseg v0.4.7 // indirect 34 | go.opentelemetry.io/otel v1.27.0 // indirect 35 | go.opentelemetry.io/otel/metric v1.27.0 // indirect 36 | go.opentelemetry.io/otel/sdk v1.27.0 // indirect 37 | go.opentelemetry.io/otel/trace v1.27.0 // indirect 38 | golang.org/x/net v0.32.0 // indirect 39 | golang.org/x/sys v0.28.0 // indirect 40 | golang.org/x/text v0.21.0 // indirect 41 | gopkg.in/yaml.v3 v3.0.1 // indirect 42 | ) 43 | -------------------------------------------------------------------------------- /hack/config.yaml: -------------------------------------------------------------------------------- 1 | 2 | # CLI tool, only in development environment. 3 | # https://goframe.org/pages/viewpage.action?pageId=3673173 4 | gfcli: 5 | gen: 6 | dao: 7 | - link: "mysql:root:12345678@tcp(127.0.0.1:3306)/oldme" 8 | descriptionTag: true 9 | noModelComment: true 10 | 11 | build: 12 | name: "github.com/oldme-git/oldme-api" 13 | arch: "amd64" 14 | system: "linux" 15 | -------------------------------------------------------------------------------- /internal/cmd/cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/gogf/gf/v2/frame/g" 7 | "github.com/gogf/gf/v2/net/ghttp" 8 | "github.com/gogf/gf/v2/os/gcmd" 9 | "github.com/oldme-git/oldme-api/internal/controller/account" 10 | "github.com/oldme-git/oldme-api/internal/controller/article" 11 | "github.com/oldme-git/oldme-api/internal/controller/article_grp" 12 | "github.com/oldme-git/oldme-api/internal/controller/file" 13 | "github.com/oldme-git/oldme-api/internal/controller/link" 14 | "github.com/oldme-git/oldme-api/internal/controller/login" 15 | "github.com/oldme-git/oldme-api/internal/controller/other" 16 | "github.com/oldme-git/oldme-api/internal/controller/reading" 17 | "github.com/oldme-git/oldme-api/internal/controller/reply" 18 | "github.com/oldme-git/oldme-api/internal/controller/sentence" 19 | "github.com/oldme-git/oldme-api/internal/controller/tag" 20 | "github.com/oldme-git/oldme-api/internal/controller/tag_grp" 21 | "github.com/oldme-git/oldme-api/internal/logic/middleware" 22 | ) 23 | 24 | var ( 25 | Main = gcmd.Command{ 26 | Name: "main", 27 | Usage: "main", 28 | Brief: "start http server", 29 | Func: func(ctx context.Context, parser *gcmd.Parser) (err error) { 30 | s := g.Server() 31 | s.Group("/", func(group *ghttp.RouterGroup) { 32 | // 允许跨域 33 | // group.Middleware(ghttp.MiddlewareCORS) 34 | // admin路由 35 | // group.Middleware(ghttp.MiddlewareHandlerResponse) 36 | group.Middleware(middleware.Response) 37 | group.Group("/admin", func(group *ghttp.RouterGroup) { 38 | group.Group("/", func(group *ghttp.RouterGroup) { 39 | group.Bind(login.NewV1()) 40 | }) 41 | group.Group("/", func(group *ghttp.RouterGroup) { 42 | group.Middleware(middleware.Auth) 43 | group.Group("/v1", func(group *ghttp.RouterGroup) { 44 | group.Bind( 45 | account.NewV1(), 46 | article.NewV1(), 47 | article_grp.NewV1(), 48 | file.NewV1(), 49 | link.NewV1(), 50 | reply.NewV1(), 51 | reading.NewV1(), 52 | 53 | tag_grp.NewV1(), 54 | tag.NewV1(), 55 | sentence.NewV1(), 56 | ) 57 | }) 58 | }) 59 | }) 60 | 61 | // app路由 62 | group.Group("/app", func(group *ghttp.RouterGroup) { 63 | group.Bind( 64 | article.NewApp(), 65 | article_grp.NewApp(), 66 | reply.NewApp(), 67 | other.NewApp(), 68 | ) 69 | }) 70 | }) 71 | s.Run() 72 | return nil 73 | }, 74 | } 75 | ) 76 | -------------------------------------------------------------------------------- /internal/consts/consts.go: -------------------------------------------------------------------------------- 1 | package consts 2 | -------------------------------------------------------------------------------- /internal/controller/account/account.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package account 6 | 7 | -------------------------------------------------------------------------------- /internal/controller/account/account_new.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package account 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/api/account" 9 | ) 10 | 11 | type ControllerV1 struct{} 12 | 13 | func NewV1() account.IAccountV1 { 14 | return &ControllerV1{} 15 | } 16 | 17 | -------------------------------------------------------------------------------- /internal/controller/account/account_v1_info.go: -------------------------------------------------------------------------------- 1 | package account 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/account/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/account" 8 | ) 9 | 10 | func (c *ControllerV1) Info(ctx context.Context, req *v1.InfoReq) (*v1.InfoRes, error) { 11 | admin, err := account.Info(ctx) 12 | if err != nil { 13 | return nil, err 14 | } 15 | return &v1.InfoRes{ 16 | Username: admin.Username, 17 | Nickname: admin.Nickname, 18 | Avatar: admin.Avatar, 19 | Register: admin.Register, 20 | LastLogin: admin.LastLogin, 21 | }, nil 22 | } 23 | -------------------------------------------------------------------------------- /internal/controller/account/account_v1_logout.go: -------------------------------------------------------------------------------- 1 | package account 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/account/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/account" 8 | ) 9 | 10 | func (c *ControllerV1) Logout(ctx context.Context, req *v1.LogoutReq) (res *v1.LogoutRes, err error) { 11 | err = account.Logout(ctx) 12 | return 13 | } 14 | -------------------------------------------------------------------------------- /internal/controller/article/article.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package article 6 | -------------------------------------------------------------------------------- /internal/controller/article/article_app_about.go: -------------------------------------------------------------------------------- 1 | package article 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/article/app" 7 | "github.com/oldme-git/oldme-api/internal/logic/article" 8 | ) 9 | 10 | func (c *ControllerApp) About(ctx context.Context, req *app.AboutReq) (*app.AboutRes, error) { 11 | info, err := article.Show(ctx, 1) 12 | if err != nil { 13 | return nil, err 14 | } 15 | return &app.AboutRes{ 16 | One: &app.One{ 17 | Id: info.Id, 18 | GrpId: info.GrpId, 19 | Title: info.Title, 20 | Author: info.Author, 21 | Thumb: info.Thumb, 22 | Tags: info.Tags, 23 | Description: info.Description, 24 | Content: info.Content, 25 | Hist: info.Hist, 26 | Post: info.Post, 27 | CreatedAt: info.CreatedAt, 28 | UpdatedAt: info.UpdatedAt, 29 | LastedAt: info.LastedAt, 30 | }, 31 | }, nil 32 | } 33 | -------------------------------------------------------------------------------- /internal/controller/article/article_app_hist.go: -------------------------------------------------------------------------------- 1 | package article 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/article/app" 7 | "github.com/oldme-git/oldme-api/internal/logic/article" 8 | ) 9 | 10 | func (c *ControllerApp) Hist(ctx context.Context, req *app.HistReq) (res *app.HistRes, err error) { 11 | err = article.Hist(ctx, req.Id) 12 | if err != nil { 13 | return nil, err 14 | } 15 | return 16 | } 17 | -------------------------------------------------------------------------------- /internal/controller/article/article_app_list.go: -------------------------------------------------------------------------------- 1 | package article 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/article/app" 7 | "github.com/oldme-git/oldme-api/internal/logic/article" 8 | "github.com/oldme-git/oldme-api/internal/model" 9 | ) 10 | 11 | func (c *ControllerApp) List(ctx context.Context, req *app.ListReq) (res *app.ListRes, err error) { 12 | query := &model.ArticleQuery{ 13 | Paging: model.Paging{ 14 | Page: req.Page, 15 | Size: req.Size, 16 | }, 17 | GrpId: req.GrpId, 18 | Search: req.Search, 19 | Onshow: true, 20 | IsDel: false, 21 | } 22 | list, total, err := article.List(ctx, query) 23 | if err != nil { 24 | return nil, err 25 | } 26 | 27 | var listOut []app.List 28 | for _, v := range list { 29 | listOut = append(listOut, app.List{ 30 | Id: v.Id, 31 | GrpId: v.GrpId, 32 | Title: v.Title, 33 | Author: v.Author, 34 | Thumb: v.Thumb, 35 | Tags: v.Tags, 36 | Description: v.Description, 37 | Hist: v.Hist, 38 | Post: v.Post, 39 | CreatedAt: v.CreatedAt, 40 | UpdatedAt: v.UpdatedAt, 41 | LastedAt: v.LastedAt, 42 | }) 43 | } 44 | return &app.ListRes{ 45 | List: listOut, 46 | Total: total, 47 | }, nil 48 | } 49 | -------------------------------------------------------------------------------- /internal/controller/article/article_app_rank.go: -------------------------------------------------------------------------------- 1 | package article 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/internal/dao" 7 | "github.com/oldme-git/oldme-api/internal/model/entity" 8 | 9 | "github.com/oldme-git/oldme-api/api/article/app" 10 | ) 11 | 12 | func (c *ControllerApp) Rank(ctx context.Context, req *app.RankReq) (res *app.RankRes, err error) { 13 | db := dao.Article.Ctx(ctx) 14 | if req.Basis == 1 { 15 | db = db.Order("ontop desc,order desc,post desc,hist desc") 16 | } else { 17 | db = db.Order("created_at desc") 18 | } 19 | db = db.Where("onshow", true) 20 | data, err := db.Limit(0, 10).All() 21 | if err != nil { 22 | return 23 | } 24 | 25 | var ( 26 | list []entity.Article 27 | listOut []app.List 28 | ) 29 | _ = data.Structs(&list) 30 | for _, v := range list { 31 | listOut = append(listOut, app.List{ 32 | Id: v.Id, 33 | GrpId: v.GrpId, 34 | Title: v.Title, 35 | Author: v.Author, 36 | Thumb: v.Thumb, 37 | Tags: v.Tags, 38 | Description: v.Description, 39 | Hist: v.Hist, 40 | Post: v.Post, 41 | CreatedAt: v.CreatedAt, 42 | UpdatedAt: v.UpdatedAt, 43 | LastedAt: v.LastedAt, 44 | }) 45 | } 46 | return &app.RankRes{ 47 | List: listOut, 48 | }, nil 49 | } 50 | -------------------------------------------------------------------------------- /internal/controller/article/article_app_reply.go: -------------------------------------------------------------------------------- 1 | package article 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/article/app" 7 | "github.com/oldme-git/oldme-api/internal/logic/reply" 8 | ) 9 | 10 | func (c *ControllerApp) Reply(ctx context.Context, req *app.ReplyReq) (res *app.ReplyRes, err error) { 11 | total, list, err := reply.ListForAid(ctx, req.Id) 12 | if err != nil { 13 | return nil, err 14 | } 15 | return &app.ReplyRes{ 16 | List: list, 17 | Total: total, 18 | }, nil 19 | } 20 | -------------------------------------------------------------------------------- /internal/controller/article/article_app_show.go: -------------------------------------------------------------------------------- 1 | package article 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/article/app" 7 | "github.com/oldme-git/oldme-api/internal/logic/article" 8 | "github.com/oldme-git/oldme-api/internal/model" 9 | ) 10 | 11 | func (c *ControllerApp) Show(ctx context.Context, req *app.ShowReq) (res *app.ShowRes, err error) { 12 | info, err := article.Show(ctx, req.Id) 13 | if err != nil { 14 | return nil, err 15 | } 16 | 17 | if info == nil { 18 | return nil, err 19 | } 20 | 21 | if info.Onshow != 0 { 22 | _ = article.UpdLastedAt(ctx, model.Id(info.Id)) 23 | } 24 | 25 | return &app.ShowRes{ 26 | One: &app.One{ 27 | Id: info.Id, 28 | GrpId: info.GrpId, 29 | Title: info.Title, 30 | Author: info.Author, 31 | Thumb: info.Thumb, 32 | Tags: info.Tags, 33 | Description: info.Description, 34 | Content: info.Content, 35 | Hist: info.Hist, 36 | Post: info.Post, 37 | CreatedAt: info.CreatedAt, 38 | UpdatedAt: info.UpdatedAt, 39 | LastedAt: info.LastedAt, 40 | }, 41 | }, nil 42 | } 43 | -------------------------------------------------------------------------------- /internal/controller/article/article_new.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package article 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/api/article" 9 | ) 10 | 11 | type ControllerApp struct{} 12 | 13 | func NewApp() article.IArticleApp { 14 | return &ControllerApp{} 15 | } 16 | 17 | type ControllerV1 struct{} 18 | 19 | func NewV1() article.IArticleV1 { 20 | return &ControllerV1{} 21 | } 22 | -------------------------------------------------------------------------------- /internal/controller/article/article_v1_cre.go: -------------------------------------------------------------------------------- 1 | package article 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/article/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/article" 8 | "github.com/oldme-git/oldme-api/internal/logic/article_grp" 9 | "github.com/oldme-git/oldme-api/internal/model" 10 | "github.com/oldme-git/oldme-api/internal/utility" 11 | ) 12 | 13 | func (c *ControllerV1) Cre(ctx context.Context, req *v1.CreReq) (*v1.CreRes, error) { 14 | // 判断该分类是否存在 15 | if ok := article_grp.IsExist(ctx, req.GrpId); !ok { 16 | return nil, utility.Err.Skip(10101) 17 | } 18 | 19 | LastId, err := article.Cre(ctx, &model.ArticleInput{ 20 | GrpId: req.GrpId, 21 | Title: req.Title, 22 | Author: req.Author, 23 | Thumb: req.Thumb, 24 | Tags: req.Tags, 25 | Description: req.Description, 26 | Content: req.Content, 27 | Order: req.Order, 28 | Ontop: req.Ontop, 29 | Onshow: req.Onshow, 30 | Hist: req.Hist, 31 | Post: req.Post, 32 | }) 33 | if err != nil { 34 | return nil, err 35 | } 36 | 37 | return &v1.CreRes{LastId: LastId}, nil 38 | } 39 | -------------------------------------------------------------------------------- /internal/controller/article/article_v1_del.go: -------------------------------------------------------------------------------- 1 | package article 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/article/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/article" 8 | ) 9 | 10 | func (c *ControllerV1) Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) { 11 | err = article.Del(ctx, req.Id, req.IsReal) 12 | return 13 | } 14 | -------------------------------------------------------------------------------- /internal/controller/article/article_v1_list.go: -------------------------------------------------------------------------------- 1 | package article 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/article/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/article" 8 | "github.com/oldme-git/oldme-api/internal/model" 9 | ) 10 | 11 | func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) { 12 | list, total, err := article.List(ctx, &model.ArticleQuery{ 13 | Paging: model.Paging{ 14 | Page: req.Page, 15 | Size: req.Size, 16 | }, 17 | GrpId: req.GrpId, 18 | Search: req.Search, 19 | Onshow: req.Onshow, 20 | IsDel: req.IsDel, 21 | }) 22 | 23 | if err != nil { 24 | return nil, err 25 | } 26 | var listOut []v1.List 27 | for _, v := range list { 28 | listOut = append(listOut, v1.List{ 29 | Id: v.Id, 30 | GrpId: v.GrpId, 31 | Title: v.Title, 32 | Author: v.Author, 33 | Thumb: v.Thumb, 34 | Tags: v.Tags, 35 | Description: v.Description, 36 | Order: v.Order, 37 | Ontop: v.Ontop, 38 | Onshow: v.Onshow, 39 | Hist: v.Hist, 40 | Post: v.Post, 41 | CreatedAt: v.CreatedAt, 42 | UpdatedAt: v.UpdatedAt, 43 | LastedAt: v.LastedAt, 44 | }) 45 | } 46 | // 查询数据表里总共的数据条数 47 | return &v1.ListRes{ 48 | List: listOut, 49 | Total: total, 50 | }, nil 51 | } 52 | -------------------------------------------------------------------------------- /internal/controller/article/article_v1_re_cre.go: -------------------------------------------------------------------------------- 1 | package article 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/article/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/article" 8 | ) 9 | 10 | func (c *ControllerV1) ReCre(ctx context.Context, req *v1.ReCreReq) (res *v1.ReCreRes, err error) { 11 | err = article.ReCre(ctx, req.Id) 12 | return 13 | } 14 | -------------------------------------------------------------------------------- /internal/controller/article/article_v1_show.go: -------------------------------------------------------------------------------- 1 | package article 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/article/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/article" 8 | ) 9 | 10 | func (c *ControllerV1) Show(ctx context.Context, req *v1.ShowReq) (res *v1.ShowRes, err error) { 11 | info, err := article.Show(ctx, req.Id) 12 | if err != nil { 13 | return nil, err 14 | } 15 | 16 | return &v1.ShowRes{ 17 | One: &v1.One{ 18 | Id: info.Id, 19 | GrpId: info.GrpId, 20 | Title: info.Title, 21 | Author: info.Author, 22 | Thumb: info.Thumb, 23 | Tags: info.Tags, 24 | Description: info.Description, 25 | Content: info.Content, 26 | Order: info.Order, 27 | Ontop: info.Ontop, 28 | Onshow: info.Onshow, 29 | Hist: info.Hist, 30 | Post: info.Post, 31 | CreatedAt: info.CreatedAt, 32 | UpdatedAt: info.UpdatedAt, 33 | DeletedAt: info.DeletedAt, 34 | LastedAt: info.LastedAt, 35 | }, 36 | }, nil 37 | } 38 | -------------------------------------------------------------------------------- /internal/controller/article/article_v1_upd.go: -------------------------------------------------------------------------------- 1 | package article 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/article/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/article" 8 | "github.com/oldme-git/oldme-api/internal/logic/article_grp" 9 | "github.com/oldme-git/oldme-api/internal/model" 10 | "github.com/oldme-git/oldme-api/internal/utility" 11 | ) 12 | 13 | func (c *ControllerV1) Upd(ctx context.Context, req *v1.UpdReq) (res *v1.UpdRes, err error) { 14 | // 判断该分类是否存在 15 | if ok := article_grp.IsExist(ctx, req.GrpId); !ok { 16 | err = utility.Err.Skip(10101) 17 | return 18 | } 19 | err = article.Upd(ctx, req.Id, &model.ArticleInput{ 20 | GrpId: req.GrpId, 21 | Title: req.Title, 22 | Author: req.Author, 23 | Thumb: req.Thumb, 24 | Tags: req.Tags, 25 | Description: req.Description, 26 | Content: req.Content, 27 | Order: req.Order, 28 | Ontop: req.Ontop, 29 | Onshow: req.Onshow, 30 | Hist: req.Hist, 31 | Post: req.Post, 32 | }) 33 | return 34 | } 35 | -------------------------------------------------------------------------------- /internal/controller/article_grp/article_grp.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package article_grp 6 | 7 | -------------------------------------------------------------------------------- /internal/controller/article_grp/article_grp_app_list.go: -------------------------------------------------------------------------------- 1 | package article_grp 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/article_grp/app" 7 | "github.com/oldme-git/oldme-api/internal/logic/article_grp" 8 | ) 9 | 10 | func (c *ControllerApp) List(ctx context.Context, req *app.ListReq) (res *app.ListRes, err error) { 11 | list, err := article_grp.List(ctx) 12 | if err != nil { 13 | return nil, err 14 | } 15 | 16 | var listOut []app.List 17 | countList, _ := article_grp.ListArticleCount(ctx) 18 | 19 | for _, v := range list { 20 | listOut = append(listOut, app.List{ 21 | Id: v.Id, 22 | Name: v.Name, 23 | Tags: v.Tags, 24 | Description: v.Description, 25 | ArticleCount: countList[v.Id], 26 | }) 27 | } 28 | res = &app.ListRes{ 29 | List: listOut, 30 | } 31 | return 32 | } 33 | -------------------------------------------------------------------------------- /internal/controller/article_grp/article_grp_new.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package article_grp 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/api/article_grp" 9 | ) 10 | 11 | type ControllerApp struct{} 12 | 13 | func NewApp() article_grp.IArticleGrpApp { 14 | return &ControllerApp{} 15 | } 16 | 17 | type ControllerV1 struct{} 18 | 19 | func NewV1() article_grp.IArticleGrpV1 { 20 | return &ControllerV1{} 21 | } 22 | 23 | -------------------------------------------------------------------------------- /internal/controller/article_grp/article_grp_v1_cre.go: -------------------------------------------------------------------------------- 1 | package article_grp 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/article_grp/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/article_grp" 8 | "github.com/oldme-git/oldme-api/internal/model" 9 | ) 10 | 11 | func (c *ControllerV1) Cre(ctx context.Context, req *v1.CreReq) (res *v1.CreRes, err error) { 12 | err = article_grp.Cre(ctx, &model.ArticleGrpInput{ 13 | Name: req.Name, 14 | Tags: req.Tags, 15 | Description: req.Description, 16 | Onshow: req.Onshow, 17 | Order: req.Order, 18 | }) 19 | return 20 | } 21 | -------------------------------------------------------------------------------- /internal/controller/article_grp/article_grp_v1_del.go: -------------------------------------------------------------------------------- 1 | package article_grp 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/article_grp/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/article_grp" 8 | ) 9 | 10 | func (c *ControllerV1) Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) { 11 | err = article_grp.Del(ctx, req.Id) 12 | return 13 | } 14 | -------------------------------------------------------------------------------- /internal/controller/article_grp/article_grp_v1_list.go: -------------------------------------------------------------------------------- 1 | package article_grp 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/article_grp/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/article_grp" 8 | ) 9 | 10 | func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (*v1.ListRes, error) { 11 | list, err := article_grp.List(ctx) 12 | if err != nil { 13 | return nil, err 14 | } 15 | return &v1.ListRes{ 16 | List: list, 17 | Total: uint(len(list)), 18 | }, nil 19 | } 20 | -------------------------------------------------------------------------------- /internal/controller/article_grp/article_grp_v1_show.go: -------------------------------------------------------------------------------- 1 | package article_grp 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/article_grp/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/article_grp" 8 | ) 9 | 10 | func (c *ControllerV1) Show(ctx context.Context, req *v1.ShowReq) (*v1.ShowRes, error) { 11 | info, err := article_grp.Show(ctx, req.Id) 12 | if err != nil { 13 | return nil, err 14 | } 15 | return &v1.ShowRes{ 16 | ArticleGrp: info, 17 | }, nil 18 | } 19 | -------------------------------------------------------------------------------- /internal/controller/article_grp/article_grp_v1_upd.go: -------------------------------------------------------------------------------- 1 | package article_grp 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/article_grp/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/article_grp" 8 | "github.com/oldme-git/oldme-api/internal/model" 9 | ) 10 | 11 | func (c *ControllerV1) Upd(ctx context.Context, req *v1.UpdReq) (res *v1.UpdRes, err error) { 12 | err = article_grp.Upd(ctx, req.Id, &model.ArticleGrpInput{ 13 | Name: req.Name, 14 | Tags: req.Tags, 15 | Description: req.Description, 16 | Onshow: req.Onshow, 17 | Order: req.Order, 18 | }) 19 | return 20 | } 21 | -------------------------------------------------------------------------------- /internal/controller/file/file.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package file 6 | -------------------------------------------------------------------------------- /internal/controller/file/file_new.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package file 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/api/file" 9 | ) 10 | 11 | type ControllerV1 struct{} 12 | 13 | func NewV1() file.IFileV1 { 14 | return &ControllerV1{} 15 | } 16 | -------------------------------------------------------------------------------- /internal/controller/file/file_v1_upload.go: -------------------------------------------------------------------------------- 1 | package file 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/file/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/file" 8 | ) 9 | 10 | func (c *ControllerV1) Upload(ctx context.Context, req *v1.UploadReq) (*v1.UploadRes, error) { 11 | info, err := file.Upload(ctx, req.File) 12 | if err != nil { 13 | return nil, err 14 | } 15 | return &v1.UploadRes{ 16 | FileInfo: *info, 17 | }, nil 18 | } 19 | -------------------------------------------------------------------------------- /internal/controller/link/link.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package link 6 | -------------------------------------------------------------------------------- /internal/controller/link/link_new.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package link 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/api/link" 9 | ) 10 | 11 | type ControllerV1 struct{} 12 | 13 | func NewV1() link.ILinkV1 { 14 | return &ControllerV1{} 15 | } 16 | -------------------------------------------------------------------------------- /internal/controller/link/link_v1_link_cre.go: -------------------------------------------------------------------------------- 1 | package link 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/link/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/link" 8 | ) 9 | 10 | func (c *ControllerV1) LinkCre(ctx context.Context, req *v1.LinkCreReq) (res *v1.LinkCreRes, err error) { 11 | err = link.Cre(ctx, req.LinkInput) 12 | return 13 | } 14 | -------------------------------------------------------------------------------- /internal/controller/link/link_v1_link_del.go: -------------------------------------------------------------------------------- 1 | package link 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/link/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/link" 8 | ) 9 | 10 | func (c *ControllerV1) LinkDel(ctx context.Context, req *v1.LinkDelReq) (res *v1.LinkDelRes, err error) { 11 | err = link.Del(ctx, req.Id) 12 | return 13 | } 14 | -------------------------------------------------------------------------------- /internal/controller/link/link_v1_link_list.go: -------------------------------------------------------------------------------- 1 | package link 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/link/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/link" 8 | ) 9 | 10 | func (c *ControllerV1) LinkList(ctx context.Context, req *v1.LinkListReq) (res *v1.LinkListRes, err error) { 11 | list, err := link.List(ctx) 12 | if err != nil { 13 | return nil, err 14 | } 15 | return &v1.LinkListRes{ 16 | List: list, 17 | Total: uint(len(list)), 18 | }, nil 19 | } 20 | -------------------------------------------------------------------------------- /internal/controller/link/link_v1_link_upd.go: -------------------------------------------------------------------------------- 1 | package link 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/link/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/link" 8 | ) 9 | 10 | func (c *ControllerV1) LinkUpd(ctx context.Context, req *v1.LinkUpdReq) (res *v1.LinkUpdRes, err error) { 11 | err = link.Upd(ctx, req.Id, req.LinkInput) 12 | return 13 | } 14 | -------------------------------------------------------------------------------- /internal/controller/login/login.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package login 6 | 7 | -------------------------------------------------------------------------------- /internal/controller/login/login_new.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package login 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/api/login" 9 | ) 10 | 11 | type ControllerV1 struct{} 12 | 13 | func NewV1() login.ILoginV1 { 14 | return &ControllerV1{} 15 | } 16 | 17 | -------------------------------------------------------------------------------- /internal/controller/login/login_v1_login.go: -------------------------------------------------------------------------------- 1 | package login 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/login/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/account" 8 | "github.com/oldme-git/oldme-api/internal/model" 9 | ) 10 | 11 | func (c *ControllerV1) Login(ctx context.Context, req *v1.LoginReq) (*v1.LoginRes, error) { 12 | token, err := account.Login(ctx, &model.LoginInput{ 13 | Username: req.Username, 14 | Password: req.Password, 15 | }) 16 | if err != nil { 17 | return nil, err 18 | } 19 | return &v1.LoginRes{ 20 | Token: token, 21 | }, nil 22 | } 23 | -------------------------------------------------------------------------------- /internal/controller/other/other.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package other 6 | -------------------------------------------------------------------------------- /internal/controller/other/other_app_link.go: -------------------------------------------------------------------------------- 1 | package other 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/other/app" 7 | "github.com/oldme-git/oldme-api/internal/logic/link" 8 | ) 9 | 10 | func (c *ControllerApp) Link(ctx context.Context, req *app.LinkReq) (*app.LinkRes, error) { 11 | list, err := link.List(ctx) 12 | if err != nil { 13 | return nil, err 14 | } 15 | return &app.LinkRes{ 16 | List: list, 17 | Total: uint(len(list)), 18 | }, nil 19 | } 20 | -------------------------------------------------------------------------------- /internal/controller/other/other_app_reading.go: -------------------------------------------------------------------------------- 1 | package other 2 | 3 | import ( 4 | "context" 5 | "time" 6 | 7 | "github.com/oldme-git/oldme-api/internal/logic/reading" 8 | 9 | "github.com/oldme-git/oldme-api/api/other/app" 10 | ) 11 | 12 | func (c *ControllerApp) Reading(ctx context.Context, req *app.ReadingReq) (res *app.ReadingRes, err error) { 13 | list, err := reading.List(ctx) 14 | if err != nil { 15 | return nil, err 16 | } 17 | res = new(app.ReadingRes) 18 | for _, v := range list { 19 | res.List = append(res.List, app.ReadingList{ 20 | Id: v.Id, 21 | Name: v.Name, 22 | Author: v.Author, 23 | Status: v.Status, 24 | FinishedAt: v.FinishedAt.Layout(time.DateOnly), 25 | }) 26 | } 27 | return 28 | } 29 | -------------------------------------------------------------------------------- /internal/controller/other/other_app_saying.go: -------------------------------------------------------------------------------- 1 | package other 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/other/app" 7 | "github.com/oldme-git/oldme-api/internal/logic/sentence" 8 | ) 9 | 10 | func (c *ControllerApp) Saying(ctx context.Context, req *app.SayingReq) (res *app.SayingRes, err error) { 11 | saying, err := sentence.Saying(ctx) 12 | if err != nil { 13 | return nil, err 14 | } 15 | return &app.SayingRes{ 16 | Saying: saying.Sentence, 17 | }, nil 18 | } 19 | -------------------------------------------------------------------------------- /internal/controller/other/other_new.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package other 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/api/other" 9 | ) 10 | 11 | type ControllerApp struct{} 12 | 13 | func NewApp() other.IOtherApp { 14 | return &ControllerApp{} 15 | } 16 | -------------------------------------------------------------------------------- /internal/controller/reading/reading.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package reading 6 | -------------------------------------------------------------------------------- /internal/controller/reading/reading_new.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package reading 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/api/reading" 9 | ) 10 | 11 | type ControllerV1 struct{} 12 | 13 | func NewV1() reading.IReadingV1 { 14 | return &ControllerV1{} 15 | } 16 | -------------------------------------------------------------------------------- /internal/controller/reading/reading_v1_reading.go: -------------------------------------------------------------------------------- 1 | package reading 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/internal/logic/reading" 7 | 8 | "github.com/oldme-git/oldme-api/api/reading/v1" 9 | ) 10 | 11 | func (c *ControllerV1) Reading(ctx context.Context, req *v1.ReadingReq) (res *v1.ReadingRes, err error) { 12 | list, err := reading.List(ctx) 13 | if err != nil { 14 | return nil, err 15 | } 16 | return &v1.ReadingRes{ 17 | List: list, 18 | }, nil 19 | } 20 | -------------------------------------------------------------------------------- /internal/controller/reply/reply.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package reply 6 | -------------------------------------------------------------------------------- /internal/controller/reply/reply_app_reply.go: -------------------------------------------------------------------------------- 1 | package reply 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/reply/app" 7 | "github.com/oldme-git/oldme-api/internal/logic/reply" 8 | "github.com/oldme-git/oldme-api/internal/model" 9 | "github.com/oldme-git/oldme-api/internal/model/entity" 10 | ) 11 | 12 | func (c *ControllerApp) Reply(ctx context.Context, req *app.ReplyReq) (res *app.ReplyRes, err error) { 13 | _, err = reply.Cre(ctx, &entity.Reply{ 14 | Aid: int(req.Aid), 15 | Pid: int(req.Pid), 16 | Email: req.Email, 17 | Site: req.Site, 18 | Name: req.Name, 19 | Content: req.Content, 20 | // 直接审核通过 21 | Status: model.SuccessStatus, 22 | }) 23 | return 24 | } 25 | -------------------------------------------------------------------------------- /internal/controller/reply/reply_new.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package reply 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/api/reply" 9 | ) 10 | 11 | type ControllerApp struct{} 12 | 13 | func NewApp() reply.IReplyApp { 14 | return &ControllerApp{} 15 | } 16 | 17 | type ControllerV1 struct{} 18 | 19 | func NewV1() reply.IReplyV1 { 20 | return &ControllerV1{} 21 | } 22 | -------------------------------------------------------------------------------- /internal/controller/reply/reply_v1_reply_check.go: -------------------------------------------------------------------------------- 1 | package reply 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/reply/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/reply" 8 | ) 9 | 10 | func (c *ControllerV1) ReplyCheck(ctx context.Context, req *v1.ReplyCheckReq) (res *v1.ReplyCheckRes, err error) { 11 | err = reply.Check(ctx, req.Id, req.Result, req.Reason) 12 | return 13 | } 14 | -------------------------------------------------------------------------------- /internal/controller/reply/reply_v1_reply_cre.go: -------------------------------------------------------------------------------- 1 | package reply 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/reply/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/reply" 8 | "github.com/oldme-git/oldme-api/internal/model" 9 | "github.com/oldme-git/oldme-api/internal/model/entity" 10 | ) 11 | 12 | func (c *ControllerV1) ReplyCre(ctx context.Context, req *v1.ReplyCreReq) (res *v1.ReplyCreRes, err error) { 13 | if req.Status == 0 { 14 | req.Status = model.SuccessStatus 15 | } 16 | _, err = reply.Cre(ctx, &entity.Reply{ 17 | Aid: int(req.Aid), 18 | Pid: int(req.Pid), 19 | Email: req.Email, 20 | Site: req.Site, 21 | Name: req.Name, 22 | Content: req.Content, 23 | Status: int(req.Status), 24 | }) 25 | return 26 | } 27 | -------------------------------------------------------------------------------- /internal/controller/reply/reply_v1_reply_del.go: -------------------------------------------------------------------------------- 1 | package reply 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/reply/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/reply" 8 | ) 9 | 10 | func (c *ControllerV1) ReplyDel(ctx context.Context, req *v1.ReplyDelReq) (res *v1.ReplyDelRes, err error) { 11 | err = reply.Del(ctx, req.Id) 12 | return 13 | } 14 | -------------------------------------------------------------------------------- /internal/controller/reply/reply_v1_reply_list.go: -------------------------------------------------------------------------------- 1 | package reply 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/reply/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/reply" 8 | ) 9 | 10 | func (c *ControllerV1) ReplyList(ctx context.Context, req *v1.ReplyListReq) (*v1.ReplyListRes, error) { 11 | list, total, err := reply.List(ctx, req.ReplyQuery) 12 | if err != nil { 13 | return nil, err 14 | } 15 | // 查询数据表里总共的数据条数 16 | return &v1.ReplyListRes{ 17 | List: list, 18 | Total: total, 19 | }, nil 20 | } 21 | -------------------------------------------------------------------------------- /internal/controller/reply/reply_v1_reply_show.go: -------------------------------------------------------------------------------- 1 | package reply 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/reply/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/reply" 8 | ) 9 | 10 | func (c *ControllerV1) ReplyShow(ctx context.Context, req *v1.ReplyShowReq) (*v1.ReplyShowRes, error) { 11 | info, err := reply.Show(ctx, req.Id) 12 | if err != nil { 13 | return nil, err 14 | } 15 | return &v1.ReplyShowRes{ 16 | ReplyShow: info, 17 | }, nil 18 | } 19 | -------------------------------------------------------------------------------- /internal/controller/reply/reply_v1_reply_upd.go: -------------------------------------------------------------------------------- 1 | package reply 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/reply/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/reply" 8 | ) 9 | 10 | func (c *ControllerV1) ReplyUpd(ctx context.Context, req *v1.ReplyUpdReq) (res *v1.ReplyUpdRes, err error) { 11 | err = reply.Upd(ctx, req.Id, req.ReplyBody) 12 | return 13 | } 14 | -------------------------------------------------------------------------------- /internal/controller/sentence/sentence.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package sentence 6 | -------------------------------------------------------------------------------- /internal/controller/sentence/sentence_new.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package sentence 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/api/sentence" 9 | ) 10 | 11 | type ControllerV1 struct{} 12 | 13 | func NewV1() sentence.ISentenceV1 { 14 | return &ControllerV1{} 15 | } 16 | -------------------------------------------------------------------------------- /internal/controller/sentence/sentence_v1_cre.go: -------------------------------------------------------------------------------- 1 | package sentence 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/internal/logic/sentence" 7 | "github.com/oldme-git/oldme-api/internal/model" 8 | 9 | "github.com/oldme-git/oldme-api/api/sentence/v1" 10 | ) 11 | 12 | func (c *ControllerV1) Cre(ctx context.Context, req *v1.CreReq) (res *v1.CreRes, err error) { 13 | err = sentence.Cre(ctx, &model.SentenceInput{ 14 | BookId: req.BookId, 15 | TagIds: req.TagIds, 16 | Sentence: req.Sentence, 17 | }) 18 | return 19 | } 20 | -------------------------------------------------------------------------------- /internal/controller/sentence/sentence_v1_del.go: -------------------------------------------------------------------------------- 1 | package sentence 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/internal/logic/sentence" 7 | 8 | "github.com/oldme-git/oldme-api/api/sentence/v1" 9 | ) 10 | 11 | func (c *ControllerV1) Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) { 12 | err = sentence.Del(ctx, req.Id) 13 | return 14 | } 15 | -------------------------------------------------------------------------------- /internal/controller/sentence/sentence_v1_list.go: -------------------------------------------------------------------------------- 1 | package sentence 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/sentence/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/sentence" 8 | "github.com/oldme-git/oldme-api/internal/model" 9 | "github.com/oldme-git/oldme-api/internal/model/entity" 10 | ) 11 | 12 | func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) { 13 | if req.Paging == nil { 14 | req.Paging = &model.Paging{ 15 | Page: 1, 16 | Size: 15, 17 | } 18 | } 19 | 20 | // bookId 和 tagId 不能同时存在,tagId 优先级更高 21 | var ( 22 | data []entity.Sentence 23 | total uint 24 | ) 25 | if len(req.TagIds) > 0 { 26 | data, total, err = c.listByTagIds(ctx, req) 27 | } else if req.BookId > 0 { 28 | data, total, err = c.listByBookId(ctx, req) 29 | } else { 30 | data, total, err = c.listBySearch(ctx, req) 31 | } 32 | 33 | if err != nil { 34 | return nil, err 35 | } 36 | 37 | var list []v1.List 38 | for _, v := range data { 39 | list = append(list, v1.List{ 40 | Id: model.Id(v.Id), 41 | BookId: model.Id(v.BookId), 42 | Sentence: v.Sentence, 43 | }) 44 | } 45 | return &v1.ListRes{ 46 | List: list, 47 | Total: total, 48 | }, nil 49 | } 50 | 51 | func (c *ControllerV1) listByTagIds(ctx context.Context, req *v1.ListReq) (data []entity.Sentence, total uint, err error) { 52 | var ids []model.Id 53 | ids, total, err = sentence.GetIdsByTagIds(ctx, req.TagIds, *req.Paging) 54 | if err != nil { 55 | return 56 | } 57 | 58 | // 重置页码到1,使用新的ids控制分页 59 | req.Paging.Page = 1 60 | 61 | query := &model.SentenceQuery{ 62 | Paging: *req.Paging, 63 | Ids: ids, 64 | } 65 | 66 | data, _, err = sentence.List(ctx, query) 67 | return 68 | } 69 | 70 | func (c *ControllerV1) listByBookId(ctx context.Context, req *v1.ListReq) (data []entity.Sentence, total uint, err error) { 71 | query := &model.SentenceQuery{ 72 | Paging: *req.Paging, 73 | BookId: req.BookId, 74 | } 75 | 76 | data, total, err = sentence.List(ctx, query) 77 | return 78 | } 79 | 80 | func (c *ControllerV1) listBySearch(ctx context.Context, req *v1.ListReq) (data []entity.Sentence, total uint, err error) { 81 | query := &model.SentenceQuery{ 82 | Paging: *req.Paging, 83 | Search: req.Search, 84 | } 85 | 86 | data, total, err = sentence.List(ctx, query) 87 | return 88 | } 89 | -------------------------------------------------------------------------------- /internal/controller/sentence/sentence_v1_show.go: -------------------------------------------------------------------------------- 1 | package sentence 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/internal/logic/sentence" 7 | 8 | "github.com/oldme-git/oldme-api/api/sentence/v1" 9 | ) 10 | 11 | func (c *ControllerV1) Show(ctx context.Context, req *v1.ShowReq) (res *v1.ShowRes, err error) { 12 | data, err := sentence.Show(ctx, req.Id) 13 | if err != nil { 14 | return nil, err 15 | } 16 | tagList, err := sentence.ShowTag(ctx, req.Id) 17 | if err != nil { 18 | return nil, err 19 | } 20 | 21 | return &v1.ShowRes{ 22 | Sentence: data, 23 | TagList: tagList, 24 | }, nil 25 | } 26 | -------------------------------------------------------------------------------- /internal/controller/sentence/sentence_v1_upd.go: -------------------------------------------------------------------------------- 1 | package sentence 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/internal/logic/sentence" 7 | "github.com/oldme-git/oldme-api/internal/model" 8 | 9 | "github.com/oldme-git/oldme-api/api/sentence/v1" 10 | ) 11 | 12 | func (c *ControllerV1) Upd(ctx context.Context, req *v1.UpdReq) (res *v1.UpdRes, err error) { 13 | err = sentence.Upd(ctx, &model.SentenceInput{ 14 | Id: req.Id, 15 | BookId: req.BookId, 16 | Sentence: req.Sentence, 17 | TagIds: req.TagIds, 18 | }) 19 | return 20 | } 21 | -------------------------------------------------------------------------------- /internal/controller/tag/tag.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package tag 6 | -------------------------------------------------------------------------------- /internal/controller/tag/tag_new.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package tag 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/api/tag" 9 | ) 10 | 11 | type ControllerV1 struct{} 12 | 13 | func NewV1() tag.ITagV1 { 14 | return &ControllerV1{} 15 | } 16 | -------------------------------------------------------------------------------- /internal/controller/tag/tag_v1_cre.go: -------------------------------------------------------------------------------- 1 | package tag 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/tag/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/tag" 8 | ) 9 | 10 | func (c *ControllerV1) Cre(ctx context.Context, req *v1.CreReq) (res *v1.CreRes, err error) { 11 | err = tag.Cre(ctx, req.GrpId, req.Name) 12 | return nil, err 13 | } 14 | -------------------------------------------------------------------------------- /internal/controller/tag/tag_v1_del.go: -------------------------------------------------------------------------------- 1 | package tag 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/internal/logic/tag" 7 | 8 | "github.com/oldme-git/oldme-api/api/tag/v1" 9 | ) 10 | 11 | func (c *ControllerV1) Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) { 12 | err = tag.Del(ctx, req.Id) 13 | return nil, err 14 | } 15 | -------------------------------------------------------------------------------- /internal/controller/tag/tag_v1_list.go: -------------------------------------------------------------------------------- 1 | package tag 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/internal/logic/tag" 7 | "github.com/oldme-git/oldme-api/internal/model" 8 | 9 | "github.com/oldme-git/oldme-api/api/tag/v1" 10 | ) 11 | 12 | func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) { 13 | data, err := tag.List(ctx, req.GrpId) 14 | if err != nil { 15 | return nil, err 16 | } 17 | 18 | var list []v1.List 19 | for _, v := range data { 20 | list = append(list, v1.List{ 21 | Id: model.Id(v.Id), 22 | Name: v.Name, 23 | }) 24 | } 25 | 26 | return &v1.ListRes{ 27 | List: list, 28 | }, err 29 | } 30 | -------------------------------------------------------------------------------- /internal/controller/tag/tag_v1_show.go: -------------------------------------------------------------------------------- 1 | package tag 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/internal/logic/tag" 7 | 8 | "github.com/oldme-git/oldme-api/api/tag/v1" 9 | ) 10 | 11 | func (c *ControllerV1) Show(ctx context.Context, req *v1.ShowReq) (res *v1.ShowRes, err error) { 12 | info, err := tag.Show(ctx, req.Id) 13 | if err != nil { 14 | return nil, err 15 | } 16 | return &v1.ShowRes{ 17 | Tag: info, 18 | }, nil 19 | } 20 | -------------------------------------------------------------------------------- /internal/controller/tag/tag_v1_upd.go: -------------------------------------------------------------------------------- 1 | package tag 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/tag/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/tag" 8 | ) 9 | 10 | func (c *ControllerV1) Upd(ctx context.Context, req *v1.UpdReq) (res *v1.UpdRes, err error) { 11 | err = tag.Upd(ctx, req.Id, req.GrpId, req.Name) 12 | return nil, err 13 | } 14 | -------------------------------------------------------------------------------- /internal/controller/tag_grp/tag_grp.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package tag_grp 6 | -------------------------------------------------------------------------------- /internal/controller/tag_grp/tag_grp_new.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package tag_grp 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/api/tag_grp" 9 | ) 10 | 11 | type ControllerV1 struct{} 12 | 13 | func NewV1() tag_grp.ITagGrpV1 { 14 | return &ControllerV1{} 15 | } 16 | -------------------------------------------------------------------------------- /internal/controller/tag_grp/tag_grp_v1_cre.go: -------------------------------------------------------------------------------- 1 | package tag_grp 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/internal/logic/tag_grp" 7 | 8 | "github.com/oldme-git/oldme-api/api/tag_grp/v1" 9 | ) 10 | 11 | func (c *ControllerV1) Cre(ctx context.Context, req *v1.CreReq) (res *v1.CreRes, err error) { 12 | err = tag_grp.Cre(ctx, req.Name) 13 | return nil, err 14 | } 15 | -------------------------------------------------------------------------------- /internal/controller/tag_grp/tag_grp_v1_del.go: -------------------------------------------------------------------------------- 1 | package tag_grp 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/internal/logic/tag_grp" 7 | 8 | "github.com/oldme-git/oldme-api/api/tag_grp/v1" 9 | ) 10 | 11 | func (c *ControllerV1) Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) { 12 | err = tag_grp.Del(ctx, req.Id) 13 | return nil, err 14 | } 15 | -------------------------------------------------------------------------------- /internal/controller/tag_grp/tag_grp_v1_list.go: -------------------------------------------------------------------------------- 1 | package tag_grp 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/api/tag_grp/v1" 7 | "github.com/oldme-git/oldme-api/internal/logic/tag_grp" 8 | "github.com/oldme-git/oldme-api/internal/model" 9 | ) 10 | 11 | func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) { 12 | data, err := tag_grp.List(ctx) 13 | if err != nil { 14 | return nil, err 15 | } 16 | 17 | var list []v1.List 18 | for _, v := range data { 19 | list = append(list, v1.List{ 20 | Id: model.Id(v.Id), 21 | Name: v.Name, 22 | }) 23 | } 24 | 25 | return &v1.ListRes{ 26 | List: list, 27 | }, err 28 | } 29 | -------------------------------------------------------------------------------- /internal/controller/tag_grp/tag_grp_v1_show.go: -------------------------------------------------------------------------------- 1 | package tag_grp 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/internal/logic/tag_grp" 7 | 8 | "github.com/oldme-git/oldme-api/api/tag_grp/v1" 9 | ) 10 | 11 | func (c *ControllerV1) Show(ctx context.Context, req *v1.ShowReq) (res *v1.ShowRes, err error) { 12 | info, err := tag_grp.Show(ctx, req.Id) 13 | if err != nil { 14 | return nil, err 15 | } 16 | return &v1.ShowRes{ 17 | TagGrp: info, 18 | }, nil 19 | } 20 | -------------------------------------------------------------------------------- /internal/controller/tag_grp/tag_grp_v1_upd.go: -------------------------------------------------------------------------------- 1 | package tag_grp 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/internal/logic/tag_grp" 7 | 8 | "github.com/oldme-git/oldme-api/api/tag_grp/v1" 9 | ) 10 | 11 | func (c *ControllerV1) Upd(ctx context.Context, req *v1.UpdReq) (res *v1.UpdRes, err error) { 12 | err = tag_grp.Upd(ctx, req.Id, req.Name) 13 | return nil, err 14 | } 15 | -------------------------------------------------------------------------------- /internal/dao/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldme-git/oldme-api/70948f91c0f6f3d090b431541bca7350f82e1e22/internal/dao/.gitkeep -------------------------------------------------------------------------------- /internal/dao/admin.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package dao 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/frame/g" 9 | "github.com/gogf/gf/v2/util/gconv" 10 | "github.com/oldme-git/oldme-api/internal/dao/internal" 11 | "github.com/oldme-git/oldme-api/internal/model/entity" 12 | ) 13 | 14 | // internalAdminDao is internal type for wrapping internal DAO implements. 15 | type internalAdminDao = *internal.AdminDao 16 | 17 | // adminDao is the data access object for table admin. 18 | // You can define custom methods on it to extend its functionality as you wish. 19 | type adminDao struct { 20 | internalAdminDao 21 | } 22 | 23 | var ( 24 | // Admin is globally public accessible object for table admin operations. 25 | Admin = adminDao{ 26 | internal.NewAdminDao(), 27 | } 28 | ) 29 | 30 | // GetAdmin 根据username获取管理员 31 | func (a adminDao) GetAdmin(username string) (admin *entity.Admin) { 32 | data, err := g.Model(Admin.Table()).Where("username", username).One() 33 | if err != nil { 34 | return nil 35 | } 36 | _ = gconv.Struct(data, &admin) 37 | return 38 | } 39 | -------------------------------------------------------------------------------- /internal/dao/article.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package dao 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/internal/dao/internal" 9 | ) 10 | 11 | // internalArticleDao is internal type for wrapping internal DAO implements. 12 | type internalArticleDao = *internal.ArticleDao 13 | 14 | // articleDao is the data access object for table article. 15 | // You can define custom methods on it to extend its functionality as you wish. 16 | type articleDao struct { 17 | internalArticleDao 18 | } 19 | 20 | var ( 21 | // Article is globally public accessible object for table article operations. 22 | Article = articleDao{ 23 | internal.NewArticleDao(), 24 | } 25 | ) 26 | 27 | // Fill with you ideas below. 28 | -------------------------------------------------------------------------------- /internal/dao/article_grp.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package dao 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/internal/dao/internal" 9 | ) 10 | 11 | // internalArticleGrpDao is internal type for wrapping internal DAO implements. 12 | type internalArticleGrpDao = *internal.ArticleGrpDao 13 | 14 | // articleGrpDao is the data access object for table article_grp. 15 | // You can define custom methods on it to extend its functionality as you wish. 16 | type articleGrpDao struct { 17 | internalArticleGrpDao 18 | } 19 | 20 | var ( 21 | // ArticleGrp is globally public accessible object for table article_grp operations. 22 | ArticleGrp = articleGrpDao{ 23 | internal.NewArticleGrpDao(), 24 | } 25 | ) 26 | 27 | // Fill with you ideas below. 28 | -------------------------------------------------------------------------------- /internal/dao/internal/admin.go: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ========================================================================== 4 | 5 | package internal 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/gogf/gf/v2/database/gdb" 11 | "github.com/gogf/gf/v2/frame/g" 12 | ) 13 | 14 | // AdminDao is the data access object for table admin. 15 | type AdminDao struct { 16 | table string // table is the underlying table name of the DAO. 17 | group string // group is the database configuration group name of current DAO. 18 | columns AdminColumns // columns contains all the column names of Table for convenient usage. 19 | } 20 | 21 | // AdminColumns defines and stores column names for table admin. 22 | type AdminColumns struct { 23 | Id string // 24 | Username string // 用户名 25 | Password string // 密码 26 | Nickname string // 昵称 27 | Avatar string // 头像,base64 28 | Register string // 注册时间 29 | Salt string // 随机盐值 30 | LastLogin string // 最后登录时间 31 | } 32 | 33 | // adminColumns holds the columns for table admin. 34 | var adminColumns = AdminColumns{ 35 | Id: "id", 36 | Username: "username", 37 | Password: "password", 38 | Nickname: "nickname", 39 | Avatar: "avatar", 40 | Register: "register", 41 | Salt: "salt", 42 | LastLogin: "last_login", 43 | } 44 | 45 | // NewAdminDao creates and returns a new DAO object for table data access. 46 | func NewAdminDao() *AdminDao { 47 | return &AdminDao{ 48 | group: "default", 49 | table: "admin", 50 | columns: adminColumns, 51 | } 52 | } 53 | 54 | // DB retrieves and returns the underlying raw database management object of current DAO. 55 | func (dao *AdminDao) DB() gdb.DB { 56 | return g.DB(dao.group) 57 | } 58 | 59 | // Table returns the table name of current dao. 60 | func (dao *AdminDao) Table() string { 61 | return dao.table 62 | } 63 | 64 | // Columns returns all column names of current dao. 65 | func (dao *AdminDao) Columns() AdminColumns { 66 | return dao.columns 67 | } 68 | 69 | // Group returns the configuration group name of database of current dao. 70 | func (dao *AdminDao) Group() string { 71 | return dao.group 72 | } 73 | 74 | // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. 75 | func (dao *AdminDao) Ctx(ctx context.Context) *gdb.Model { 76 | return dao.DB().Model(dao.table).Safe().Ctx(ctx) 77 | } 78 | 79 | // Transaction wraps the transaction logic using function f. 80 | // It rollbacks the transaction and returns the error from function f if it returns non-nil error. 81 | // It commits the transaction and returns nil if function f returns nil. 82 | // 83 | // Note that, you should not Commit or Rollback the transaction in function f 84 | // as it is automatically handled by this function. 85 | func (dao *AdminDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { 86 | return dao.Ctx(ctx).Transaction(ctx, f) 87 | } 88 | -------------------------------------------------------------------------------- /internal/dao/internal/article.go: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ========================================================================== 4 | 5 | package internal 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/gogf/gf/v2/database/gdb" 11 | "github.com/gogf/gf/v2/frame/g" 12 | ) 13 | 14 | // ArticleDao is the data access object for table article. 15 | type ArticleDao struct { 16 | table string // table is the underlying table name of the DAO. 17 | group string // group is the database configuration group name of current DAO. 18 | columns ArticleColumns // columns contains all the column names of Table for convenient usage. 19 | } 20 | 21 | // ArticleColumns defines and stores column names for table article. 22 | type ArticleColumns struct { 23 | Id string // 24 | GrpId string // 分组id 25 | Title string // 标题 26 | Author string // 作者 27 | Thumb string // 图片地址 28 | Tags string // 标签,依英文逗号隔开 29 | Description string // 简介 30 | Content string // 内容 31 | Order string // 排序,越大越靠前 32 | Ontop string // 是否置顶 33 | Onshow string // 是否显示 34 | Hist string // 点击数 35 | Post string // 评论数 36 | CreatedAt string // 创建时间 37 | UpdatedAt string // 更新时间 38 | DeletedAt string // 删除时间 39 | LastedAt string // 最后浏览时间 40 | } 41 | 42 | // articleColumns holds the columns for table article. 43 | var articleColumns = ArticleColumns{ 44 | Id: "id", 45 | GrpId: "grp_id", 46 | Title: "title", 47 | Author: "author", 48 | Thumb: "thumb", 49 | Tags: "tags", 50 | Description: "description", 51 | Content: "content", 52 | Order: "order", 53 | Ontop: "ontop", 54 | Onshow: "onshow", 55 | Hist: "hist", 56 | Post: "post", 57 | CreatedAt: "created_at", 58 | UpdatedAt: "updated_at", 59 | DeletedAt: "deleted_at", 60 | LastedAt: "lasted_at", 61 | } 62 | 63 | // NewArticleDao creates and returns a new DAO object for table data access. 64 | func NewArticleDao() *ArticleDao { 65 | return &ArticleDao{ 66 | group: "default", 67 | table: "article", 68 | columns: articleColumns, 69 | } 70 | } 71 | 72 | // DB retrieves and returns the underlying raw database management object of current DAO. 73 | func (dao *ArticleDao) DB() gdb.DB { 74 | return g.DB(dao.group) 75 | } 76 | 77 | // Table returns the table name of current dao. 78 | func (dao *ArticleDao) Table() string { 79 | return dao.table 80 | } 81 | 82 | // Columns returns all column names of current dao. 83 | func (dao *ArticleDao) Columns() ArticleColumns { 84 | return dao.columns 85 | } 86 | 87 | // Group returns the configuration group name of database of current dao. 88 | func (dao *ArticleDao) Group() string { 89 | return dao.group 90 | } 91 | 92 | // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. 93 | func (dao *ArticleDao) Ctx(ctx context.Context) *gdb.Model { 94 | return dao.DB().Model(dao.table).Safe().Ctx(ctx) 95 | } 96 | 97 | // Transaction wraps the transaction logic using function f. 98 | // It rollbacks the transaction and returns the error from function f if it returns non-nil error. 99 | // It commits the transaction and returns nil if function f returns nil. 100 | // 101 | // Note that, you should not Commit or Rollback the transaction in function f 102 | // as it is automatically handled by this function. 103 | func (dao *ArticleDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { 104 | return dao.Ctx(ctx).Transaction(ctx, f) 105 | } 106 | -------------------------------------------------------------------------------- /internal/dao/internal/article_grp.go: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ========================================================================== 4 | 5 | package internal 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/gogf/gf/v2/database/gdb" 11 | "github.com/gogf/gf/v2/frame/g" 12 | ) 13 | 14 | // ArticleGrpDao is the data access object for table article_grp. 15 | type ArticleGrpDao struct { 16 | table string // table is the underlying table name of the DAO. 17 | group string // group is the database configuration group name of current DAO. 18 | columns ArticleGrpColumns // columns contains all the column names of Table for convenient usage. 19 | } 20 | 21 | // ArticleGrpColumns defines and stores column names for table article_grp. 22 | type ArticleGrpColumns struct { 23 | Id string // 24 | Name string // 名称 25 | Tags string // 标签,依英文逗号隔开 26 | Description string // 简介 27 | Onshow string // 是否显示 28 | Order string // 排序,越大越靠前 29 | } 30 | 31 | // articleGrpColumns holds the columns for table article_grp. 32 | var articleGrpColumns = ArticleGrpColumns{ 33 | Id: "id", 34 | Name: "name", 35 | Tags: "tags", 36 | Description: "description", 37 | Onshow: "onshow", 38 | Order: "order", 39 | } 40 | 41 | // NewArticleGrpDao creates and returns a new DAO object for table data access. 42 | func NewArticleGrpDao() *ArticleGrpDao { 43 | return &ArticleGrpDao{ 44 | group: "default", 45 | table: "article_grp", 46 | columns: articleGrpColumns, 47 | } 48 | } 49 | 50 | // DB retrieves and returns the underlying raw database management object of current DAO. 51 | func (dao *ArticleGrpDao) DB() gdb.DB { 52 | return g.DB(dao.group) 53 | } 54 | 55 | // Table returns the table name of current dao. 56 | func (dao *ArticleGrpDao) Table() string { 57 | return dao.table 58 | } 59 | 60 | // Columns returns all column names of current dao. 61 | func (dao *ArticleGrpDao) Columns() ArticleGrpColumns { 62 | return dao.columns 63 | } 64 | 65 | // Group returns the configuration group name of database of current dao. 66 | func (dao *ArticleGrpDao) Group() string { 67 | return dao.group 68 | } 69 | 70 | // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. 71 | func (dao *ArticleGrpDao) Ctx(ctx context.Context) *gdb.Model { 72 | return dao.DB().Model(dao.table).Safe().Ctx(ctx) 73 | } 74 | 75 | // Transaction wraps the transaction logic using function f. 76 | // It rollbacks the transaction and returns the error from function f if it returns non-nil error. 77 | // It commits the transaction and returns nil if function f returns nil. 78 | // 79 | // Note that, you should not Commit or Rollback the transaction in function f 80 | // as it is automatically handled by this function. 81 | func (dao *ArticleGrpDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { 82 | return dao.Ctx(ctx).Transaction(ctx, f) 83 | } 84 | -------------------------------------------------------------------------------- /internal/dao/internal/link.go: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ========================================================================== 4 | 5 | package internal 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/gogf/gf/v2/database/gdb" 11 | "github.com/gogf/gf/v2/frame/g" 12 | ) 13 | 14 | // LinkDao is the data access object for table link. 15 | type LinkDao struct { 16 | table string // table is the underlying table name of the DAO. 17 | group string // group is the database configuration group name of current DAO. 18 | columns LinkColumns // columns contains all the column names of Table for convenient usage. 19 | } 20 | 21 | // LinkColumns defines and stores column names for table link. 22 | type LinkColumns struct { 23 | Id string // 24 | Name string // 名称 25 | Description string // 描述 26 | Link string // 链接 27 | } 28 | 29 | // linkColumns holds the columns for table link. 30 | var linkColumns = LinkColumns{ 31 | Id: "id", 32 | Name: "name", 33 | Description: "description", 34 | Link: "link", 35 | } 36 | 37 | // NewLinkDao creates and returns a new DAO object for table data access. 38 | func NewLinkDao() *LinkDao { 39 | return &LinkDao{ 40 | group: "default", 41 | table: "link", 42 | columns: linkColumns, 43 | } 44 | } 45 | 46 | // DB retrieves and returns the underlying raw database management object of current DAO. 47 | func (dao *LinkDao) DB() gdb.DB { 48 | return g.DB(dao.group) 49 | } 50 | 51 | // Table returns the table name of current dao. 52 | func (dao *LinkDao) Table() string { 53 | return dao.table 54 | } 55 | 56 | // Columns returns all column names of current dao. 57 | func (dao *LinkDao) Columns() LinkColumns { 58 | return dao.columns 59 | } 60 | 61 | // Group returns the configuration group name of database of current dao. 62 | func (dao *LinkDao) Group() string { 63 | return dao.group 64 | } 65 | 66 | // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. 67 | func (dao *LinkDao) Ctx(ctx context.Context) *gdb.Model { 68 | return dao.DB().Model(dao.table).Safe().Ctx(ctx) 69 | } 70 | 71 | // Transaction wraps the transaction logic using function f. 72 | // It rollbacks the transaction and returns the error from function f if it returns non-nil error. 73 | // It commits the transaction and returns nil if function f returns nil. 74 | // 75 | // Note that, you should not Commit or Rollback the transaction in function f 76 | // as it is automatically handled by this function. 77 | func (dao *LinkDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { 78 | return dao.Ctx(ctx).Transaction(ctx, f) 79 | } 80 | -------------------------------------------------------------------------------- /internal/dao/internal/reading.go: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ========================================================================== 4 | 5 | package internal 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/gogf/gf/v2/database/gdb" 11 | "github.com/gogf/gf/v2/frame/g" 12 | ) 13 | 14 | // ReadingDao is the data access object for table reading. 15 | type ReadingDao struct { 16 | table string // table is the underlying table name of the DAO. 17 | group string // group is the database configuration group name of current DAO. 18 | columns ReadingColumns // columns contains all the column names of Table for convenient usage. 19 | } 20 | 21 | // ReadingColumns defines and stores column names for table reading. 22 | type ReadingColumns struct { 23 | Id string // 24 | Name string // 书名 25 | Author string // 作者 26 | Status string // 状态: 1完结 2在读 3弃读 27 | FinishedAt string // 读完时间 28 | } 29 | 30 | // readingColumns holds the columns for table reading. 31 | var readingColumns = ReadingColumns{ 32 | Id: "id", 33 | Name: "name", 34 | Author: "author", 35 | Status: "status", 36 | FinishedAt: "finished_at", 37 | } 38 | 39 | // NewReadingDao creates and returns a new DAO object for table data access. 40 | func NewReadingDao() *ReadingDao { 41 | return &ReadingDao{ 42 | group: "default", 43 | table: "reading", 44 | columns: readingColumns, 45 | } 46 | } 47 | 48 | // DB retrieves and returns the underlying raw database management object of current DAO. 49 | func (dao *ReadingDao) DB() gdb.DB { 50 | return g.DB(dao.group) 51 | } 52 | 53 | // Table returns the table name of current dao. 54 | func (dao *ReadingDao) Table() string { 55 | return dao.table 56 | } 57 | 58 | // Columns returns all column names of current dao. 59 | func (dao *ReadingDao) Columns() ReadingColumns { 60 | return dao.columns 61 | } 62 | 63 | // Group returns the configuration group name of database of current dao. 64 | func (dao *ReadingDao) Group() string { 65 | return dao.group 66 | } 67 | 68 | // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. 69 | func (dao *ReadingDao) Ctx(ctx context.Context) *gdb.Model { 70 | return dao.DB().Model(dao.table).Safe().Ctx(ctx) 71 | } 72 | 73 | // Transaction wraps the transaction logic using function f. 74 | // It rollbacks the transaction and returns the error from function f if it returns non-nil error. 75 | // It commits the transaction and returns nil if function f returns nil. 76 | // 77 | // Note that, you should not Commit or Rollback the transaction in function f 78 | // as it is automatically handled by this function. 79 | func (dao *ReadingDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { 80 | return dao.Ctx(ctx).Transaction(ctx, f) 81 | } 82 | -------------------------------------------------------------------------------- /internal/dao/internal/reply.go: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ========================================================================== 4 | 5 | package internal 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/gogf/gf/v2/database/gdb" 11 | "github.com/gogf/gf/v2/frame/g" 12 | ) 13 | 14 | // ReplyDao is the data access object for table reply. 15 | type ReplyDao struct { 16 | table string // table is the underlying table name of the DAO. 17 | group string // group is the database configuration group name of current DAO. 18 | columns ReplyColumns // columns contains all the column names of Table for convenient usage. 19 | } 20 | 21 | // ReplyColumns defines and stores column names for table reply. 22 | type ReplyColumns struct { 23 | Id string // 24 | Aid string // 文章id 25 | Rid string // 根回复id,一个根可视为一个楼层 26 | Pid string // 回复的id 27 | PName string // 回复的名称 28 | Email string // 回复人邮箱 29 | Name string // 回复人名称 30 | Site string // 回复人网站 31 | Content string // 回复内容 32 | Status string // 状态: 1待审核 2审核通过 3审核失败 33 | Reason string // 审核失败原因 34 | CreatedAt string // 创建时间 35 | UpdatedAt string // 更新时间 36 | DeletedAt string // 删除时间 37 | } 38 | 39 | // replyColumns holds the columns for table reply. 40 | var replyColumns = ReplyColumns{ 41 | Id: "id", 42 | Aid: "aid", 43 | Rid: "rid", 44 | Pid: "pid", 45 | PName: "p_name", 46 | Email: "email", 47 | Name: "name", 48 | Site: "site", 49 | Content: "content", 50 | Status: "status", 51 | Reason: "reason", 52 | CreatedAt: "created_at", 53 | UpdatedAt: "updated_at", 54 | DeletedAt: "deleted_at", 55 | } 56 | 57 | // NewReplyDao creates and returns a new DAO object for table data access. 58 | func NewReplyDao() *ReplyDao { 59 | return &ReplyDao{ 60 | group: "default", 61 | table: "reply", 62 | columns: replyColumns, 63 | } 64 | } 65 | 66 | // DB retrieves and returns the underlying raw database management object of current DAO. 67 | func (dao *ReplyDao) DB() gdb.DB { 68 | return g.DB(dao.group) 69 | } 70 | 71 | // Table returns the table name of current dao. 72 | func (dao *ReplyDao) Table() string { 73 | return dao.table 74 | } 75 | 76 | // Columns returns all column names of current dao. 77 | func (dao *ReplyDao) Columns() ReplyColumns { 78 | return dao.columns 79 | } 80 | 81 | // Group returns the configuration group name of database of current dao. 82 | func (dao *ReplyDao) Group() string { 83 | return dao.group 84 | } 85 | 86 | // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. 87 | func (dao *ReplyDao) Ctx(ctx context.Context) *gdb.Model { 88 | return dao.DB().Model(dao.table).Safe().Ctx(ctx) 89 | } 90 | 91 | // Transaction wraps the transaction logic using function f. 92 | // It rollbacks the transaction and returns the error from function f if it returns non-nil error. 93 | // It commits the transaction and returns nil if function f returns nil. 94 | // 95 | // Note that, you should not Commit or Rollback the transaction in function f 96 | // as it is automatically handled by this function. 97 | func (dao *ReplyDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { 98 | return dao.Ctx(ctx).Transaction(ctx, f) 99 | } 100 | -------------------------------------------------------------------------------- /internal/dao/internal/sentence.go: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ========================================================================== 4 | 5 | package internal 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/gogf/gf/v2/database/gdb" 11 | "github.com/gogf/gf/v2/frame/g" 12 | ) 13 | 14 | // SentenceDao is the data access object for table sentence. 15 | type SentenceDao struct { 16 | table string // table is the underlying table name of the DAO. 17 | group string // group is the database configuration group name of current DAO. 18 | columns SentenceColumns // columns contains all the column names of Table for convenient usage. 19 | } 20 | 21 | // SentenceColumns defines and stores column names for table sentence. 22 | type SentenceColumns struct { 23 | Id string // 24 | BookId string // 25 | Sentence string // 26 | } 27 | 28 | // sentenceColumns holds the columns for table sentence. 29 | var sentenceColumns = SentenceColumns{ 30 | Id: "id", 31 | BookId: "book_id", 32 | Sentence: "sentence", 33 | } 34 | 35 | // NewSentenceDao creates and returns a new DAO object for table data access. 36 | func NewSentenceDao() *SentenceDao { 37 | return &SentenceDao{ 38 | group: "default", 39 | table: "sentence", 40 | columns: sentenceColumns, 41 | } 42 | } 43 | 44 | // DB retrieves and returns the underlying raw database management object of current DAO. 45 | func (dao *SentenceDao) DB() gdb.DB { 46 | return g.DB(dao.group) 47 | } 48 | 49 | // Table returns the table name of current dao. 50 | func (dao *SentenceDao) Table() string { 51 | return dao.table 52 | } 53 | 54 | // Columns returns all column names of current dao. 55 | func (dao *SentenceDao) Columns() SentenceColumns { 56 | return dao.columns 57 | } 58 | 59 | // Group returns the configuration group name of database of current dao. 60 | func (dao *SentenceDao) Group() string { 61 | return dao.group 62 | } 63 | 64 | // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. 65 | func (dao *SentenceDao) Ctx(ctx context.Context) *gdb.Model { 66 | return dao.DB().Model(dao.table).Safe().Ctx(ctx) 67 | } 68 | 69 | // Transaction wraps the transaction logic using function f. 70 | // It rollbacks the transaction and returns the error from function f if it returns non-nil error. 71 | // It commits the transaction and returns nil if function f returns nil. 72 | // 73 | // Note that, you should not Commit or Rollback the transaction in function f 74 | // as it is automatically handled by this function. 75 | func (dao *SentenceDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { 76 | return dao.Ctx(ctx).Transaction(ctx, f) 77 | } 78 | -------------------------------------------------------------------------------- /internal/dao/internal/sentence_tag.go: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ========================================================================== 4 | 5 | package internal 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/gogf/gf/v2/database/gdb" 11 | "github.com/gogf/gf/v2/frame/g" 12 | ) 13 | 14 | // SentenceTagDao is the data access object for table sentence_tag. 15 | type SentenceTagDao struct { 16 | table string // table is the underlying table name of the DAO. 17 | group string // group is the database configuration group name of current DAO. 18 | columns SentenceTagColumns // columns contains all the column names of Table for convenient usage. 19 | } 20 | 21 | // SentenceTagColumns defines and stores column names for table sentence_tag. 22 | type SentenceTagColumns struct { 23 | SId string // 句子id 24 | TId string // tag id 25 | } 26 | 27 | // sentenceTagColumns holds the columns for table sentence_tag. 28 | var sentenceTagColumns = SentenceTagColumns{ 29 | SId: "s_id", 30 | TId: "t_id", 31 | } 32 | 33 | // NewSentenceTagDao creates and returns a new DAO object for table data access. 34 | func NewSentenceTagDao() *SentenceTagDao { 35 | return &SentenceTagDao{ 36 | group: "default", 37 | table: "sentence_tag", 38 | columns: sentenceTagColumns, 39 | } 40 | } 41 | 42 | // DB retrieves and returns the underlying raw database management object of current DAO. 43 | func (dao *SentenceTagDao) DB() gdb.DB { 44 | return g.DB(dao.group) 45 | } 46 | 47 | // Table returns the table name of current dao. 48 | func (dao *SentenceTagDao) Table() string { 49 | return dao.table 50 | } 51 | 52 | // Columns returns all column names of current dao. 53 | func (dao *SentenceTagDao) Columns() SentenceTagColumns { 54 | return dao.columns 55 | } 56 | 57 | // Group returns the configuration group name of database of current dao. 58 | func (dao *SentenceTagDao) Group() string { 59 | return dao.group 60 | } 61 | 62 | // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. 63 | func (dao *SentenceTagDao) Ctx(ctx context.Context) *gdb.Model { 64 | return dao.DB().Model(dao.table).Safe().Ctx(ctx) 65 | } 66 | 67 | // Transaction wraps the transaction logic using function f. 68 | // It rollbacks the transaction and returns the error from function f if it returns non-nil error. 69 | // It commits the transaction and returns nil if function f returns nil. 70 | // 71 | // Note that, you should not Commit or Rollback the transaction in function f 72 | // as it is automatically handled by this function. 73 | func (dao *SentenceTagDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { 74 | return dao.Ctx(ctx).Transaction(ctx, f) 75 | } 76 | -------------------------------------------------------------------------------- /internal/dao/internal/sentence_tags.go: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ========================================================================== 4 | 5 | package internal 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/gogf/gf/v2/database/gdb" 11 | "github.com/gogf/gf/v2/frame/g" 12 | ) 13 | 14 | // SentenceTagsDao is the data access object for table sentence_tags. 15 | type SentenceTagsDao struct { 16 | table string // table is the underlying table name of the DAO. 17 | group string // group is the database configuration group name of current DAO. 18 | columns SentenceTagsColumns // columns contains all the column names of Table for convenient usage. 19 | } 20 | 21 | // SentenceTagsColumns defines and stores column names for table sentence_tags. 22 | type SentenceTagsColumns struct { 23 | SId string // 24 | TId string // 25 | } 26 | 27 | // sentenceTagsColumns holds the columns for table sentence_tags. 28 | var sentenceTagsColumns = SentenceTagsColumns{ 29 | SId: "s_id", 30 | TId: "t_id", 31 | } 32 | 33 | // NewSentenceTagsDao creates and returns a new DAO object for table data access. 34 | func NewSentenceTagsDao() *SentenceTagsDao { 35 | return &SentenceTagsDao{ 36 | group: "default", 37 | table: "sentence_tags", 38 | columns: sentenceTagsColumns, 39 | } 40 | } 41 | 42 | // DB retrieves and returns the underlying raw database management object of current DAO. 43 | func (dao *SentenceTagsDao) DB() gdb.DB { 44 | return g.DB(dao.group) 45 | } 46 | 47 | // Table returns the table name of current dao. 48 | func (dao *SentenceTagsDao) Table() string { 49 | return dao.table 50 | } 51 | 52 | // Columns returns all column names of current dao. 53 | func (dao *SentenceTagsDao) Columns() SentenceTagsColumns { 54 | return dao.columns 55 | } 56 | 57 | // Group returns the configuration group name of database of current dao. 58 | func (dao *SentenceTagsDao) Group() string { 59 | return dao.group 60 | } 61 | 62 | // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. 63 | func (dao *SentenceTagsDao) Ctx(ctx context.Context) *gdb.Model { 64 | return dao.DB().Model(dao.table).Safe().Ctx(ctx) 65 | } 66 | 67 | // Transaction wraps the transaction logic using function f. 68 | // It rollbacks the transaction and returns the error from function f if it returns non-nil error. 69 | // It commits the transaction and returns nil if function f returns nil. 70 | // 71 | // Note that, you should not Commit or Rollback the transaction in function f 72 | // as it is automatically handled by this function. 73 | func (dao *SentenceTagsDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { 74 | return dao.Ctx(ctx).Transaction(ctx, f) 75 | } 76 | -------------------------------------------------------------------------------- /internal/dao/internal/tag.go: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ========================================================================== 4 | 5 | package internal 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/gogf/gf/v2/database/gdb" 11 | "github.com/gogf/gf/v2/frame/g" 12 | ) 13 | 14 | // TagDao is the data access object for table tag. 15 | type TagDao struct { 16 | table string // table is the underlying table name of the DAO. 17 | group string // group is the database configuration group name of current DAO. 18 | columns TagColumns // columns contains all the column names of Table for convenient usage. 19 | } 20 | 21 | // TagColumns defines and stores column names for table tag. 22 | type TagColumns struct { 23 | Id string // 24 | GrpId string // 分组id 25 | Name string // 标签名称 26 | } 27 | 28 | // tagColumns holds the columns for table tag. 29 | var tagColumns = TagColumns{ 30 | Id: "id", 31 | GrpId: "grp_id", 32 | Name: "name", 33 | } 34 | 35 | // NewTagDao creates and returns a new DAO object for table data access. 36 | func NewTagDao() *TagDao { 37 | return &TagDao{ 38 | group: "default", 39 | table: "tag", 40 | columns: tagColumns, 41 | } 42 | } 43 | 44 | // DB retrieves and returns the underlying raw database management object of current DAO. 45 | func (dao *TagDao) DB() gdb.DB { 46 | return g.DB(dao.group) 47 | } 48 | 49 | // Table returns the table name of current dao. 50 | func (dao *TagDao) Table() string { 51 | return dao.table 52 | } 53 | 54 | // Columns returns all column names of current dao. 55 | func (dao *TagDao) Columns() TagColumns { 56 | return dao.columns 57 | } 58 | 59 | // Group returns the configuration group name of database of current dao. 60 | func (dao *TagDao) Group() string { 61 | return dao.group 62 | } 63 | 64 | // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. 65 | func (dao *TagDao) Ctx(ctx context.Context) *gdb.Model { 66 | return dao.DB().Model(dao.table).Safe().Ctx(ctx) 67 | } 68 | 69 | // Transaction wraps the transaction logic using function f. 70 | // It rollbacks the transaction and returns the error from function f if it returns non-nil error. 71 | // It commits the transaction and returns nil if function f returns nil. 72 | // 73 | // Note that, you should not Commit or Rollback the transaction in function f 74 | // as it is automatically handled by this function. 75 | func (dao *TagDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { 76 | return dao.Ctx(ctx).Transaction(ctx, f) 77 | } 78 | -------------------------------------------------------------------------------- /internal/dao/internal/tag_grp.go: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ========================================================================== 4 | 5 | package internal 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/gogf/gf/v2/database/gdb" 11 | "github.com/gogf/gf/v2/frame/g" 12 | ) 13 | 14 | // TagGrpDao is the data access object for table tag_grp. 15 | type TagGrpDao struct { 16 | table string // table is the underlying table name of the DAO. 17 | group string // group is the database configuration group name of current DAO. 18 | columns TagGrpColumns // columns contains all the column names of Table for convenient usage. 19 | } 20 | 21 | // TagGrpColumns defines and stores column names for table tag_grp. 22 | type TagGrpColumns struct { 23 | Id string // 24 | Name string // 标签分组名称 25 | } 26 | 27 | // tagGrpColumns holds the columns for table tag_grp. 28 | var tagGrpColumns = TagGrpColumns{ 29 | Id: "id", 30 | Name: "name", 31 | } 32 | 33 | // NewTagGrpDao creates and returns a new DAO object for table data access. 34 | func NewTagGrpDao() *TagGrpDao { 35 | return &TagGrpDao{ 36 | group: "default", 37 | table: "tag_grp", 38 | columns: tagGrpColumns, 39 | } 40 | } 41 | 42 | // DB retrieves and returns the underlying raw database management object of current DAO. 43 | func (dao *TagGrpDao) DB() gdb.DB { 44 | return g.DB(dao.group) 45 | } 46 | 47 | // Table returns the table name of current dao. 48 | func (dao *TagGrpDao) Table() string { 49 | return dao.table 50 | } 51 | 52 | // Columns returns all column names of current dao. 53 | func (dao *TagGrpDao) Columns() TagGrpColumns { 54 | return dao.columns 55 | } 56 | 57 | // Group returns the configuration group name of database of current dao. 58 | func (dao *TagGrpDao) Group() string { 59 | return dao.group 60 | } 61 | 62 | // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. 63 | func (dao *TagGrpDao) Ctx(ctx context.Context) *gdb.Model { 64 | return dao.DB().Model(dao.table).Safe().Ctx(ctx) 65 | } 66 | 67 | // Transaction wraps the transaction logic using function f. 68 | // It rollbacks the transaction and returns the error from function f if it returns non-nil error. 69 | // It commits the transaction and returns nil if function f returns nil. 70 | // 71 | // Note that, you should not Commit or Rollback the transaction in function f 72 | // as it is automatically handled by this function. 73 | func (dao *TagGrpDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { 74 | return dao.Ctx(ctx).Transaction(ctx, f) 75 | } 76 | -------------------------------------------------------------------------------- /internal/dao/link.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package dao 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/internal/dao/internal" 9 | ) 10 | 11 | // internalLinkDao is internal type for wrapping internal DAO implements. 12 | type internalLinkDao = *internal.LinkDao 13 | 14 | // linkDao is the data access object for table link. 15 | // You can define custom methods on it to extend its functionality as you wish. 16 | type linkDao struct { 17 | internalLinkDao 18 | } 19 | 20 | var ( 21 | // Link is globally public accessible object for table link operations. 22 | Link = linkDao{ 23 | internal.NewLinkDao(), 24 | } 25 | ) 26 | 27 | // Fill with you ideas below. 28 | -------------------------------------------------------------------------------- /internal/dao/reading.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package dao 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/internal/dao/internal" 9 | ) 10 | 11 | // internalReadingDao is internal type for wrapping internal DAO implements. 12 | type internalReadingDao = *internal.ReadingDao 13 | 14 | // readingDao is the data access object for table reading. 15 | // You can define custom methods on it to extend its functionality as you wish. 16 | type readingDao struct { 17 | internalReadingDao 18 | } 19 | 20 | var ( 21 | // Reading is globally public accessible object for table reading operations. 22 | Reading = readingDao{ 23 | internal.NewReadingDao(), 24 | } 25 | ) 26 | 27 | // Fill with you ideas below. 28 | -------------------------------------------------------------------------------- /internal/dao/reply.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package dao 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/internal/dao/internal" 9 | ) 10 | 11 | // internalReplyDao is internal type for wrapping internal DAO implements. 12 | type internalReplyDao = *internal.ReplyDao 13 | 14 | // replyDao is the data access object for table reply. 15 | // You can define custom methods on it to extend its functionality as you wish. 16 | type replyDao struct { 17 | internalReplyDao 18 | } 19 | 20 | var ( 21 | // Reply is globally public accessible object for table reply operations. 22 | Reply = replyDao{ 23 | internal.NewReplyDao(), 24 | } 25 | ) 26 | 27 | // Fill with you ideas below. 28 | -------------------------------------------------------------------------------- /internal/dao/sentence.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package dao 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/internal/dao/internal" 9 | ) 10 | 11 | // internalSentenceDao is internal type for wrapping internal DAO implements. 12 | type internalSentenceDao = *internal.SentenceDao 13 | 14 | // sentenceDao is the data access object for table sentence. 15 | // You can define custom methods on it to extend its functionality as you wish. 16 | type sentenceDao struct { 17 | internalSentenceDao 18 | } 19 | 20 | var ( 21 | // Sentence is globally public accessible object for table sentence operations. 22 | Sentence = sentenceDao{ 23 | internal.NewSentenceDao(), 24 | } 25 | ) 26 | 27 | // Fill with you ideas below. 28 | -------------------------------------------------------------------------------- /internal/dao/sentence_tag.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package dao 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/internal/dao/internal" 9 | ) 10 | 11 | // internalSentenceTagDao is internal type for wrapping internal DAO implements. 12 | type internalSentenceTagDao = *internal.SentenceTagDao 13 | 14 | // sentenceTagDao is the data access object for table sentence_tag. 15 | // You can define custom methods on it to extend its functionality as you wish. 16 | type sentenceTagDao struct { 17 | internalSentenceTagDao 18 | } 19 | 20 | var ( 21 | // SentenceTag is globally public accessible object for table sentence_tag operations. 22 | SentenceTag = sentenceTagDao{ 23 | internal.NewSentenceTagDao(), 24 | } 25 | ) 26 | 27 | // Fill with you ideas below. 28 | -------------------------------------------------------------------------------- /internal/dao/tag.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package dao 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/internal/dao/internal" 9 | ) 10 | 11 | // internalTagDao is internal type for wrapping internal DAO implements. 12 | type internalTagDao = *internal.TagDao 13 | 14 | // tagDao is the data access object for table tag. 15 | // You can define custom methods on it to extend its functionality as you wish. 16 | type tagDao struct { 17 | internalTagDao 18 | } 19 | 20 | var ( 21 | // Tag is globally public accessible object for table tag operations. 22 | Tag = tagDao{ 23 | internal.NewTagDao(), 24 | } 25 | ) 26 | 27 | // Fill with you ideas below. 28 | -------------------------------------------------------------------------------- /internal/dao/tag_grp.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. 3 | // ================================================================================= 4 | 5 | package dao 6 | 7 | import ( 8 | "github.com/oldme-git/oldme-api/internal/dao/internal" 9 | ) 10 | 11 | // internalTagGrpDao is internal type for wrapping internal DAO implements. 12 | type internalTagGrpDao = *internal.TagGrpDao 13 | 14 | // tagGrpDao is the data access object for table tag_grp. 15 | // You can define custom methods on it to extend its functionality as you wish. 16 | type tagGrpDao struct { 17 | internalTagGrpDao 18 | } 19 | 20 | var ( 21 | // TagGrp is globally public accessible object for table tag_grp operations. 22 | TagGrp = tagGrpDao{ 23 | internal.NewTagGrpDao(), 24 | } 25 | ) 26 | 27 | // Fill with you ideas below. 28 | -------------------------------------------------------------------------------- /internal/logic/account/account.go: -------------------------------------------------------------------------------- 1 | package account 2 | 3 | import ( 4 | "context" 5 | "time" 6 | 7 | "github.com/gogf/gf/v2/frame/g" 8 | "github.com/golang-jwt/jwt/v5" 9 | "github.com/oldme-git/oldme-api/internal/dao" 10 | "github.com/oldme-git/oldme-api/internal/logic/admin" 11 | "github.com/oldme-git/oldme-api/internal/model" 12 | "github.com/oldme-git/oldme-api/internal/model/entity" 13 | "github.com/oldme-git/oldme-api/internal/utility" 14 | "github.com/oldme-git/oldme-api/utility/ujwt" 15 | ) 16 | 17 | var jwtKey = ujwt.JwtKey 18 | 19 | type AdminClaims struct { 20 | Id uint 21 | Username string 22 | jwt.RegisteredClaims 23 | } 24 | 25 | // Login 登录 26 | func Login(ctx context.Context, in *model.LoginInput) (tokenString string, err error) { 27 | adminOne := dao.Admin.GetAdmin(in.Username) 28 | // 校验账号和密码 29 | if adminOne.Id != 0 && admin.ValidPass(in.Password, adminOne) { 30 | adminClaims := &AdminClaims{ 31 | Id: adminOne.Id, 32 | Username: adminOne.Username, 33 | RegisteredClaims: jwt.RegisteredClaims{ 34 | ExpiresAt: jwt.NewNumericDate(time.Now().Add(6 * time.Hour)), 35 | }, 36 | } 37 | token := jwt.NewWithClaims(jwt.SigningMethodHS256, adminClaims) 38 | tokenString, _ = token.SignedString(jwtKey) 39 | err = nil 40 | } else { 41 | err = utility.Err.Skip(20100) 42 | } 43 | return 44 | } 45 | 46 | // Logout 登出 47 | func Logout(ctx context.Context) (err error) { 48 | // TODO 暂时依靠客户端,后续可以考虑改为Redis黑名单处理 49 | return nil 50 | } 51 | 52 | // Info 获取当前已经登录的管理员信息 53 | func Info(ctx context.Context) (admin *entity.Admin, err error) { 54 | tokenString := g.RequestFromCtx(ctx).Request.Header.Get("Authorization") 55 | tokenClaims, _ := jwt.ParseWithClaims(tokenString, &AdminClaims{}, func(token *jwt.Token) (interface{}, error) { 56 | return jwtKey, nil 57 | }) 58 | 59 | if claims, ok := tokenClaims.Claims.(*AdminClaims); ok && tokenClaims.Valid { 60 | admin = dao.Admin.GetAdmin(claims.Username) 61 | } else { 62 | err = utility.Err.Skip(10100) 63 | } 64 | return 65 | } 66 | -------------------------------------------------------------------------------- /internal/logic/admin/admin.go: -------------------------------------------------------------------------------- 1 | package admin 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/gogf/gf/v2/crypto/gmd5" 7 | "github.com/gogf/gf/v2/os/gtime" 8 | "github.com/gogf/gf/v2/util/grand" 9 | "github.com/oldme-git/oldme-api/internal/dao" 10 | "github.com/oldme-git/oldme-api/internal/model" 11 | "github.com/oldme-git/oldme-api/internal/model/do" 12 | "github.com/oldme-git/oldme-api/internal/model/entity" 13 | "github.com/oldme-git/oldme-api/internal/utility" 14 | ) 15 | 16 | // Create 创建管理员 17 | func Create(ctx context.Context, in *model.AdminInput) (err error) { 18 | var ( 19 | salt = genSalt() 20 | password = encryptPass(in.Password, salt) 21 | ) 22 | _, err = dao.Admin.Ctx(ctx).Data(do.Admin{ 23 | Username: in.Username, 24 | Password: password, 25 | Nickname: in.Nickname, 26 | Avatar: in.Avatar, 27 | Salt: salt, 28 | LastLogin: gtime.Now(), 29 | Register: gtime.Now(), 30 | }).Insert() 31 | if err != nil { 32 | err = utility.Err.Sys(err) 33 | } 34 | return 35 | } 36 | 37 | // ValidPass 校验密码 38 | func ValidPass(pass string, admin *entity.Admin) bool { 39 | return admin.Password == encryptPass(pass, admin.Salt) 40 | } 41 | 42 | // GenSalt 生成32位盐值盐值 43 | func genSalt() string { 44 | return grand.S(32, false) 45 | } 46 | 47 | // EncryptPass 加密密码 48 | func encryptPass(pass string, salt string) (encrypt string) { 49 | encrypt, _ = gmd5.EncryptString(pass + salt) 50 | return 51 | } 52 | -------------------------------------------------------------------------------- /internal/logic/article_grp/article_grp.go: -------------------------------------------------------------------------------- 1 | package article_grp 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/internal/dao" 7 | "github.com/oldme-git/oldme-api/internal/logic/article" 8 | "github.com/oldme-git/oldme-api/internal/model" 9 | "github.com/oldme-git/oldme-api/internal/model/do" 10 | "github.com/oldme-git/oldme-api/internal/model/entity" 11 | "github.com/oldme-git/oldme-api/internal/utility" 12 | ) 13 | 14 | // Cre 创建文章分类 15 | func Cre(ctx context.Context, in *model.ArticleGrpInput) (err error) { 16 | _, err = dao.ArticleGrp.Ctx(ctx).Data(do.ArticleGrp{ 17 | Name: in.Name, 18 | Tags: in.Tags, 19 | Description: in.Description, 20 | Onshow: in.Onshow, 21 | Order: in.Order, 22 | }).Insert() 23 | if err != nil { 24 | return utility.Err.Sys(err) 25 | } 26 | return 27 | } 28 | 29 | // Upd 更新文章分类 30 | func Upd(ctx context.Context, id model.Id, in *model.ArticleGrpInput) (err error) { 31 | _, err = dao.ArticleGrp.Ctx(ctx).Data(do.ArticleGrp{ 32 | Name: in.Name, 33 | Tags: in.Tags, 34 | Description: in.Description, 35 | Onshow: in.Onshow, 36 | Order: in.Order, 37 | }).Where("id", id).Update() 38 | if err != nil { 39 | return utility.Err.Sys(err) 40 | } 41 | return 42 | } 43 | 44 | // Del 删除文章分类 45 | func Del(ctx context.Context, id model.Id) (err error) { 46 | _, err = dao.ArticleGrp.Ctx(ctx).Where("id", id).Delete() 47 | // 软删除掉该分类下的文章 48 | data, err := dao.Article.Ctx(ctx).Fields("id").Where("grp_id", id).All() 49 | if err != nil { 50 | return utility.Err.Sys(err) 51 | } 52 | 53 | for _, v := range data { 54 | _ = article.Del(ctx, model.Id(v["id"].Uint()), false) 55 | } 56 | return 57 | } 58 | 59 | // List 读取文章分类列表 60 | func List(ctx context.Context) (list []entity.ArticleGrp, err error) { 61 | res, err := dao.ArticleGrp.Ctx(ctx).Order("order desc").All() 62 | _ = res.Structs(&list) 63 | return 64 | } 65 | 66 | // ListArticleCount 获取已经发布文章的文章分类列表统计 67 | func ListArticleCount(ctx context.Context) (map[uint]uint, error) { 68 | listCount, err := dao.Article.Ctx(ctx). 69 | Fields("count(*) count,grp_id"). 70 | Where("onshow", 1). 71 | Group("grp_id").All() 72 | if err != nil { 73 | return nil, utility.Err.Sys(err) 74 | } 75 | idCountMap := make(map[uint]uint, len(listCount)) 76 | for _, v := range listCount { 77 | idCountMap[v["grp_id"].Uint()] = v["count"].Uint() 78 | } 79 | 80 | return idCountMap, nil 81 | } 82 | 83 | // Show 读取文章分类详情 84 | func Show(ctx context.Context, id model.Id) (info *entity.ArticleGrp, err error) { 85 | err = dao.ArticleGrp.Ctx(ctx).Where("id", id).Scan(&info) 86 | if err != nil { 87 | err = utility.Err.Skip(10100) 88 | } 89 | return 90 | } 91 | 92 | // IsExist 根据id判断一个文章分类是否存在 93 | func IsExist(ctx context.Context, id model.Id) bool { 94 | num, _ := dao.ArticleGrp.Ctx(ctx).Where("id", id).Count() 95 | return num == 1 96 | } 97 | -------------------------------------------------------------------------------- /internal/logic/file/file.go: -------------------------------------------------------------------------------- 1 | package file 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | "path" 7 | "strings" 8 | "time" 9 | 10 | "github.com/gogf/gf/v2/net/ghttp" 11 | "github.com/gogf/gf/v2/os/gcfg" 12 | "github.com/gogf/gf/v2/os/gfile" 13 | "github.com/gogf/gf/v2/os/gtime" 14 | "github.com/gogf/gf/v2/os/gtimer" 15 | "github.com/gogf/gf/v2/text/gregex" 16 | "github.com/gogf/gf/v2/text/gstr" 17 | "github.com/oldme-git/oldme-api/internal/model" 18 | "github.com/oldme-git/oldme-api/internal/utility" 19 | ) 20 | 21 | // Upload 上传文件到临时库 22 | func Upload(ctx context.Context, file *ghttp.UploadFile) (info *model.FileInfo, err error) { 23 | var ( 24 | name string 25 | lib = "tmp" 26 | dirPath = getDir(ctx, lib) 27 | urlPath string 28 | ) 29 | name, err = file.Save(dirPath, true) 30 | if err != nil { 31 | return 32 | } 33 | urlPath = getUrlFile(ctx, "tmp", name) 34 | info = &model.FileInfo{ 35 | Name: name, 36 | Url: urlPath, 37 | } 38 | // 启动定时器,让临时图片只能存在30分钟 39 | gtimer.AddOnce(ctx, 30*time.Minute, func(ctx context.Context) { 40 | _ = Del(ctx, urlPath) 41 | }) 42 | return 43 | } 44 | 45 | // Save 保存文件到正式库,如果src不是tmp库中的文件,则不做操作,原路返回 46 | func Save(ctx context.Context, src string, lib string) (info *model.FileInfo, err error) { 47 | // 先从src获取文件名称 48 | name, err := getTmpName(ctx, src) 49 | if err != nil { 50 | return &model.FileInfo{ 51 | Name: path.Base(src), 52 | Url: src, 53 | }, err 54 | } 55 | // 移动 56 | info, err = moveTmp(ctx, lib+"/"+gtime.Now().Format("Ym"), name) 57 | if err != nil { 58 | return &model.FileInfo{ 59 | Name: path.Base(src), 60 | Url: src, 61 | }, utility.Err.Skip(10503, err.Error()) 62 | } 63 | return 64 | } 65 | 66 | // SaveImg 保存图片文件到img库 67 | func SaveImg(ctx context.Context, src string) (info *model.FileInfo, err error) { 68 | if err = utility.Ext.Img(src); err != nil { 69 | err = utility.Err.Skip(10501, err.Error()) 70 | return 71 | } 72 | return Save(ctx, src, "img") 73 | } 74 | 75 | // Del 删除 76 | func Del(ctx context.Context, src string) (err error) { 77 | conf, _ := getConf(ctx) 78 | // url换成dir形式 79 | src = strings.Replace(src, conf["url"], conf["dir"], 1) 80 | if !gfile.IsFile(src) { 81 | err = utility.Err.Skip(10503) 82 | return 83 | } 84 | err = gfile.Remove(src) 85 | if err != nil { 86 | return 87 | } 88 | return 89 | } 90 | 91 | // getLib 从url或者dir获取库的名称 92 | func getLib(ctx context.Context, src string) (lib string, err error) { 93 | conf, _ := getConf(ctx) 94 | var ( 95 | dir = conf["dir"] 96 | url = conf["url"] 97 | str string 98 | ) 99 | if strings.HasPrefix(src, dir) { 100 | dirLen := len(dir + "/") 101 | str = gstr.SubStrRune(src, dirLen) 102 | } else if strings.HasPrefix(src, url) { 103 | urlLen := len(url + "/") 104 | str = gstr.SubStrRune(src, urlLen) 105 | } else { 106 | err = errors.New("没有找到库") 107 | return 108 | } 109 | libSlice, err := gregex.MatchString(`(?i)\w+`, str) 110 | if err != nil { 111 | err = errors.New("没有找到库") 112 | return 113 | } 114 | lib = libSlice[0] 115 | return 116 | } 117 | 118 | // getName 从url或者dir读取库中文件名称 119 | func getName(ctx context.Context, lib string, src string) (name string, err error) { 120 | lib = lib + "/" 121 | var ( 122 | dirPath = getDir(ctx, lib) 123 | urlPath = getUrl(ctx, lib) 124 | ) 125 | 126 | if strings.HasPrefix(src, dirPath) || strings.HasPrefix(src, urlPath) { 127 | name = path.Base(src) 128 | } else { 129 | err = errors.New(src + "不存在") 130 | } 131 | return 132 | } 133 | 134 | // getTmpName 从url或者dir读取临时库中文件名称 135 | func getTmpName(ctx context.Context, src string) (name string, err error) { 136 | name, err = getName(ctx, "tmp", src) 137 | return 138 | } 139 | 140 | // moveTmp tmp库的文件移入到正式库 141 | func moveTmp(ctx context.Context, lib string, name string) (info *model.FileInfo, err error) { 142 | var ( 143 | srcPath = getDirFile(ctx, "tmp", name) 144 | dstPath = getDirFile(ctx, lib, name) 145 | ) 146 | if ok := gfile.IsFile(srcPath); !ok { 147 | err = errors.New(name + "不存在") 148 | return 149 | } 150 | err = gfile.Copy(srcPath, dstPath) 151 | if err != nil { 152 | return 153 | } 154 | // 删除原文件 155 | _ = gfile.Remove(srcPath) 156 | info = &model.FileInfo{ 157 | Name: name, 158 | Url: getUrlFile(ctx, lib, name), 159 | Dir: dstPath, 160 | } 161 | return 162 | } 163 | 164 | // getConf 获取upload配置 165 | func getConf(ctx context.Context) (upload map[string]string, err error) { 166 | cfg, _ := gcfg.New() 167 | uploadVar, err := cfg.Get(ctx, "upload") 168 | if err != nil { 169 | return 170 | } 171 | upload = uploadVar.MapStrStr() 172 | return 173 | } 174 | 175 | // getDir 获取disk dir路径 176 | func getDir(ctx context.Context, lib string) string { 177 | conf, err := getConf(ctx) 178 | if err != nil { 179 | panic(err) 180 | } 181 | return conf["dir"] + "/" + lib 182 | } 183 | 184 | // getUrl 获取http url路径 185 | func getUrl(ctx context.Context, lib string) string { 186 | conf, err := getConf(ctx) 187 | if err != nil { 188 | panic(err) 189 | } 190 | return conf["url"] + "/" + lib 191 | } 192 | 193 | // getDirFile 获取文件的disk dir路径 194 | func getDirFile(ctx context.Context, lib string, name string) string { 195 | dir := getDir(ctx, lib) 196 | return dir + "/" + name 197 | } 198 | 199 | // getUrlFile 获取文件的http url路径 200 | func getUrlFile(ctx context.Context, lib string, name string) string { 201 | url := getUrl(ctx, lib) 202 | return url + "/" + name 203 | } 204 | -------------------------------------------------------------------------------- /internal/logic/link/link.go: -------------------------------------------------------------------------------- 1 | package link 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/internal/dao" 7 | "github.com/oldme-git/oldme-api/internal/model" 8 | "github.com/oldme-git/oldme-api/internal/model/do" 9 | "github.com/oldme-git/oldme-api/internal/model/entity" 10 | "github.com/oldme-git/oldme-api/internal/utility" 11 | ) 12 | 13 | // Cre 创建友链 14 | func Cre(ctx context.Context, in *model.LinkInput) (err error) { 15 | _, err = dao.Link.Ctx(ctx).Data(do.Link{ 16 | Name: in.Name, 17 | Description: in.Description, 18 | Link: in.Link, 19 | }).Insert() 20 | if err != nil { 21 | err = utility.Err.Sys(err) 22 | } 23 | return 24 | } 25 | 26 | // Upd 更新友链 27 | func Upd(ctx context.Context, id model.Id, in *model.LinkInput) (err error) { 28 | _, err = dao.Link.Ctx(ctx).Data(do.Link{ 29 | Name: in.Name, 30 | Description: in.Description, 31 | Link: in.Link, 32 | }).Where("id", id).Update() 33 | if err != nil { 34 | err = utility.Err.Sys(err) 35 | } 36 | return 37 | } 38 | 39 | // Del 删除友链 40 | func Del(ctx context.Context, id model.Id) (err error) { 41 | _, err = dao.Link.Ctx(ctx).Where("id", id).Delete() 42 | if err != nil { 43 | err = utility.Err.Sys(err) 44 | } 45 | return 46 | } 47 | 48 | // List 读取友链列表 49 | func List(ctx context.Context) (list []entity.Link, err error) { 50 | res, err := dao.Link.Ctx(ctx).All() 51 | if err != nil { 52 | return nil, utility.Err.Sys(err) 53 | } 54 | _ = res.Structs(&list) 55 | return 56 | } 57 | -------------------------------------------------------------------------------- /internal/logic/logic.go: -------------------------------------------------------------------------------- 1 | // ========================================================================== 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ========================================================================== 4 | 5 | package logic 6 | 7 | import ( 8 | _ "github.com/oldme-git/oldme-api/internal/logic/account" 9 | _ "github.com/oldme-git/oldme-api/internal/logic/admin" 10 | _ "github.com/oldme-git/oldme-api/internal/logic/article" 11 | _ "github.com/oldme-git/oldme-api/internal/logic/article_grp" 12 | _ "github.com/oldme-git/oldme-api/internal/logic/file" 13 | _ "github.com/oldme-git/oldme-api/internal/logic/link" 14 | _ "github.com/oldme-git/oldme-api/internal/logic/middleware" 15 | _ "github.com/oldme-git/oldme-api/internal/logic/reading" 16 | _ "github.com/oldme-git/oldme-api/internal/logic/reply" 17 | _ "github.com/oldme-git/oldme-api/internal/logic/rich" 18 | _ "github.com/oldme-git/oldme-api/internal/logic/sentence" 19 | _ "github.com/oldme-git/oldme-api/internal/logic/tag" 20 | _ "github.com/oldme-git/oldme-api/internal/logic/tag_grp" 21 | ) 22 | -------------------------------------------------------------------------------- /internal/logic/middleware/auth.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/gogf/gf/v2/net/ghttp" 7 | "github.com/golang-jwt/jwt/v5" 8 | "github.com/oldme-git/oldme-api/utility/ujwt" 9 | ) 10 | 11 | func Auth(r *ghttp.Request) { 12 | var ( 13 | jwtKey = ujwt.JwtKey 14 | tokenString = r.Header.Get("Authorization") 15 | ) 16 | token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) { 17 | return jwtKey, nil 18 | }) 19 | if err != nil || !token.Valid { 20 | r.Response.WriteStatus(http.StatusForbidden) 21 | r.Exit() 22 | } 23 | 24 | r.Middleware.Next() 25 | } 26 | -------------------------------------------------------------------------------- /internal/logic/middleware/response.go: -------------------------------------------------------------------------------- 1 | // 统一响应处理 2 | 3 | package middleware 4 | 5 | import ( 6 | "net/http" 7 | 8 | "github.com/gogf/gf/v2/errors/gcode" 9 | "github.com/gogf/gf/v2/errors/gerror" 10 | "github.com/gogf/gf/v2/net/ghttp" 11 | "github.com/oldme-git/oldme-api/internal/utility" 12 | ) 13 | 14 | type ResponseData struct { 15 | Code int `json:"code" dc:"业务码"` 16 | Message string `json:"message" dc:"业务码说明"` 17 | Data interface{} `json:"data" dc:"返回的数据"` 18 | } 19 | 20 | func Response(r *ghttp.Request) { 21 | r.Middleware.Next() 22 | 23 | if r.Response.BufferLength() > 0 { 24 | return 25 | } 26 | 27 | // 先过滤掉服务器内部错误 28 | if r.Response.Status >= http.StatusInternalServerError { 29 | // 清除掉缓存区,防止服务器信息泄露到客户端 30 | r.Response.ClearBuffer() 31 | r.Response.Writeln("服务器打盹了,请稍后再来找他!") 32 | } 33 | 34 | var ( 35 | res = r.GetHandlerResponse() 36 | err = r.GetError() 37 | code = gerror.Code(err) 38 | codeInt = code.Code() 39 | msg string 40 | ) 41 | 42 | if err != nil { 43 | // 如果是系统错误,不要把错误信息抛出到客户端,防止泄露系统信息 44 | if codeInt == utility.CodeErrSys { 45 | msg = utility.Err.GetSysMsg() 46 | } else { 47 | msg = err.Error() 48 | } 49 | } else { 50 | code = gcode.CodeOK 51 | msg = utility.Err.GetMsg(code.Code()) 52 | } 53 | 54 | r.Response.WriteJson(ResponseData{ 55 | Code: code.Code(), 56 | Message: msg, 57 | Data: res, 58 | }) 59 | } 60 | -------------------------------------------------------------------------------- /internal/logic/reading/reading.go: -------------------------------------------------------------------------------- 1 | package reading 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/internal/dao" 7 | "github.com/oldme-git/oldme-api/internal/model/entity" 8 | "github.com/oldme-git/oldme-api/internal/utility" 9 | ) 10 | 11 | // List 读取列表 12 | func List(ctx context.Context) (list []entity.Reading, err error) { 13 | res, err := dao.Reading.Ctx(ctx). 14 | Order("status desc"). 15 | Order("finished_at desc"). 16 | All() 17 | if err != nil { 18 | return nil, utility.Err.Sys(err) 19 | } 20 | _ = res.Structs(&list) 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /internal/logic/rich/rich.go: -------------------------------------------------------------------------------- 1 | package rich 2 | 3 | import ( 4 | "context" 5 | "strings" 6 | 7 | "github.com/oldme-git/oldme-api/internal/logic/file" 8 | "github.com/oldme-git/oldme-api/utility" 9 | "github.com/oldme-git/oldme-api/utility/uregex" 10 | ) 11 | 12 | const ( 13 | imgTmpPattern = `(?i)(https?)://(((?!http).)*)tmp(((?!http).)*)?(.png|.jpg|.jpeg|.gif)` 14 | imgPattern = `(?i)(https?)://((?!http).)*?(.png|.jpg|.jpeg|.gif)` 15 | ) 16 | 17 | // Save 提取富文本中的 tmpimg,移入到正式库 18 | func Save(ctx context.Context, text *string) { 19 | // 正则所有的img:png、jpg、jpeg 20 | match, _ := uregex.MatchAllString(imgTmpPattern, *text) 21 | // 获取所有图片的链接 22 | for _, v := range match { 23 | info, err := file.Save(ctx, v, "rich") 24 | if err == nil { 25 | // 替换富文本中的内存 26 | *text = strings.Replace(*text, v, info.Url, -1) 27 | } 28 | } 29 | return 30 | } 31 | 32 | func Edit(ctx context.Context, oldText *string, newText *string) { 33 | // 新的富文本内存需要先保存 34 | Save(ctx, newText) 35 | 36 | // 正则出新旧的图片切片 37 | oldSlice, _ := uregex.MatchAllString(imgPattern, *oldText) 38 | newSlice, _ := uregex.MatchAllString(imgPattern, *newText) 39 | 40 | for _, v := range oldSlice { 41 | // 在newSlice的去除 42 | if ok, _ := utility.InArray(v, newSlice); !ok { 43 | _ = file.Del(ctx, v) 44 | } 45 | } 46 | } 47 | 48 | // Del 删除 49 | func Del(ctx context.Context, text *string) (err error) { 50 | // 正则所有的img:png、jpg、jpeg 51 | match, err := uregex.MatchAllString(imgPattern, *text) 52 | if err != nil { 53 | return err 54 | } 55 | // 获取所有图片的链接并删除 56 | for _, v := range match { 57 | _ = file.Del(ctx, v) 58 | } 59 | return 60 | } 61 | -------------------------------------------------------------------------------- /internal/logic/tag/tag.go: -------------------------------------------------------------------------------- 1 | package tag 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/internal/dao" 7 | "github.com/oldme-git/oldme-api/internal/model" 8 | "github.com/oldme-git/oldme-api/internal/model/do" 9 | "github.com/oldme-git/oldme-api/internal/model/entity" 10 | "github.com/oldme-git/oldme-api/internal/utility" 11 | ) 12 | 13 | // Cre 创建标签 14 | func Cre(ctx context.Context, grpId model.Id, name string) (err error) { 15 | if err := check(ctx, 0, name); err != nil { 16 | return err 17 | } 18 | _, err = dao.Tag.Ctx(ctx).Data(do.Tag{ 19 | GrpId: grpId, 20 | Name: name, 21 | }).Insert() 22 | if err != nil { 23 | return utility.Err.Sys(err) 24 | } 25 | return err 26 | } 27 | 28 | // Upd 更新标签 29 | func Upd(ctx context.Context, id, grpId model.Id, name string) (err error) { 30 | if err := check(ctx, id, name); err != nil { 31 | return err 32 | } 33 | 34 | _, err = dao.Tag.Ctx(ctx).Data(do.Tag{ 35 | GrpId: grpId, 36 | Name: name, 37 | }).Where("id", id).Update() 38 | if err != nil { 39 | return utility.Err.Sys(err) 40 | } 41 | 42 | return 43 | } 44 | 45 | // List 读取标签列表 46 | func List(ctx context.Context, grpId model.Id) (list []entity.Tag, err error) { 47 | list = make([]entity.Tag, 0) 48 | err = dao.Tag.Ctx(ctx).Where("grp_id", grpId).Scan(&list) 49 | return 50 | } 51 | 52 | // Del 删除标签 53 | func Del(ctx context.Context, id model.Id) (err error) { 54 | _, err = dao.Tag.Ctx(ctx).Where("id", id).Delete() 55 | return 56 | } 57 | 58 | // Show 读取详情 59 | func Show(ctx context.Context, id model.Id) (info *entity.Tag, err error) { 60 | err = dao.Tag.Ctx(ctx).Where("id", id).Scan(&info) 61 | if err != nil { 62 | err = utility.Err.Skip(10504) 63 | } 64 | return 65 | } 66 | 67 | // check 检查标签是否存在 68 | func check(ctx context.Context, id model.Id, name string) error { 69 | db := dao.Tag.Ctx(ctx).Where("name", name) 70 | if id > 0 { 71 | db = db.WhereNot("id", id) 72 | } 73 | count, err := db.Count() 74 | if err != nil { 75 | return utility.Err.Sys(err) 76 | } 77 | if count > 0 { 78 | return utility.Err.Skip(10601) 79 | } 80 | return nil 81 | } 82 | -------------------------------------------------------------------------------- /internal/logic/tag_grp/tag_grp.go: -------------------------------------------------------------------------------- 1 | package tag_grp 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/oldme-git/oldme-api/internal/dao" 7 | "github.com/oldme-git/oldme-api/internal/model" 8 | "github.com/oldme-git/oldme-api/internal/model/do" 9 | "github.com/oldme-git/oldme-api/internal/model/entity" 10 | "github.com/oldme-git/oldme-api/internal/utility" 11 | ) 12 | 13 | // Cre 创建标签分类 14 | func Cre(ctx context.Context, name string) (err error) { 15 | _, err = dao.TagGrp.Ctx(ctx).Data(do.TagGrp{ 16 | Name: name, 17 | }).Insert() 18 | if err != nil { 19 | return utility.Err.Sys(err) 20 | } 21 | return 22 | } 23 | 24 | // Upd 更新标签分类 25 | func Upd(ctx context.Context, id model.Id, name string) (err error) { 26 | _, err = dao.TagGrp.Ctx(ctx).Data(do.TagGrp{ 27 | Name: name, 28 | }).Where("id", id).Update() 29 | if err != nil { 30 | return utility.Err.Sys(err) 31 | } 32 | return 33 | } 34 | 35 | // Del 删除标签分类 36 | func Del(ctx context.Context, id model.Id) (err error) { 37 | _, err = dao.TagGrp.Ctx(ctx).Where("id", id).Delete() 38 | return 39 | } 40 | 41 | // List 读取标签分类列表 42 | func List(ctx context.Context) (list []entity.TagGrp, err error) { 43 | list = make([]entity.TagGrp, 0) 44 | err = dao.TagGrp.Ctx(ctx).Scan(&list) 45 | return 46 | } 47 | 48 | // Show 读取详情 49 | func Show(ctx context.Context, id model.Id) (info *entity.TagGrp, err error) { 50 | err = dao.TagGrp.Ctx(ctx).Where("id", id).Scan(&info) 51 | if err != nil { 52 | err = utility.Err.Skip(10504) 53 | } 54 | return 55 | } 56 | -------------------------------------------------------------------------------- /internal/model/admin.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | type AdminInput struct { 4 | Username string 5 | Password string 6 | Nickname string 7 | Avatar string 8 | } 9 | 10 | type LoginInput struct { 11 | Username string 12 | Password string 13 | } 14 | -------------------------------------------------------------------------------- /internal/model/article.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | type ArticleInput struct { 4 | GrpId Id 5 | Title string 6 | Author string 7 | Thumb string 8 | Tags string 9 | Description string 10 | Content string 11 | Order int 12 | Ontop uint 13 | Onshow uint 14 | Hist uint 15 | Post uint 16 | } 17 | 18 | type ArticleQuery struct { 19 | Paging 20 | GrpId Id 21 | Search string 22 | Onshow bool 23 | IsDel bool 24 | } 25 | -------------------------------------------------------------------------------- /internal/model/article_grp.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | type ArticleGrpInput struct { 4 | Name string 5 | Tags string 6 | Description string 7 | Onshow bool 8 | Order int 9 | } 10 | -------------------------------------------------------------------------------- /internal/model/dataType.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | // Id 主键类型 4 | type Id uint32 5 | 6 | // Out 标记剔除字段 7 | type Out bool 8 | 9 | // ReplyStatus 回复审核状态 10 | type ReplyStatus uint8 11 | 12 | // IdInput 公共Id input,一般用作api中的upd和del 13 | type IdInput struct { 14 | Id Id `json:"id" v:"required|integer|between:1,4294967295"` 15 | } 16 | 17 | // Paging 分页查询条件 18 | type Paging struct { 19 | Page int `v:"integer|between:1,9999999" json:"page" dc:"查询分页:页码,默认1"` 20 | Size int `v:"integer|between:1,100" json:"size" dc:"查询分页:条数,默认15"` 21 | } 22 | -------------------------------------------------------------------------------- /internal/model/do/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldme-git/oldme-api/70948f91c0f6f3d090b431541bca7350f82e1e22/internal/model/do/.gitkeep -------------------------------------------------------------------------------- /internal/model/do/admin.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package do 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/frame/g" 9 | "github.com/gogf/gf/v2/os/gtime" 10 | ) 11 | 12 | // Admin is the golang structure of table admin for DAO operations like Where/Data. 13 | type Admin struct { 14 | g.Meta `orm:"table:admin, do:true"` 15 | Id interface{} // 16 | Username interface{} // 用户名 17 | Password interface{} // 密码 18 | Nickname interface{} // 昵称 19 | Avatar interface{} // 头像,base64 20 | Register *gtime.Time // 注册时间 21 | Salt interface{} // 随机盐值 22 | LastLogin *gtime.Time // 最后登录时间 23 | } 24 | -------------------------------------------------------------------------------- /internal/model/do/article.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package do 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/frame/g" 9 | "github.com/gogf/gf/v2/os/gtime" 10 | ) 11 | 12 | // Article is the golang structure of table article for DAO operations like Where/Data. 13 | type Article struct { 14 | g.Meta `orm:"table:article, do:true"` 15 | Id interface{} // 16 | GrpId interface{} // 分组id 17 | Title interface{} // 标题 18 | Author interface{} // 作者 19 | Thumb interface{} // 图片地址 20 | Tags interface{} // 标签,依英文逗号隔开 21 | Description interface{} // 简介 22 | Content interface{} // 内容 23 | Order interface{} // 排序,越大越靠前 24 | Ontop interface{} // 是否置顶 25 | Onshow interface{} // 是否显示 26 | Hist interface{} // 点击数 27 | Post interface{} // 评论数 28 | CreatedAt *gtime.Time // 创建时间 29 | UpdatedAt *gtime.Time // 更新时间 30 | DeletedAt *gtime.Time // 删除时间 31 | LastedAt *gtime.Time // 最后浏览时间 32 | } 33 | -------------------------------------------------------------------------------- /internal/model/do/article_grp.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package do 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/frame/g" 9 | ) 10 | 11 | // ArticleGrp is the golang structure of table article_grp for DAO operations like Where/Data. 12 | type ArticleGrp struct { 13 | g.Meta `orm:"table:article_grp, do:true"` 14 | Id interface{} // 15 | Name interface{} // 名称 16 | Tags interface{} // 标签,依英文逗号隔开 17 | Description interface{} // 简介 18 | Onshow interface{} // 是否显示 19 | Order interface{} // 排序,越大越靠前 20 | } 21 | -------------------------------------------------------------------------------- /internal/model/do/link.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package do 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/frame/g" 9 | ) 10 | 11 | // Link is the golang structure of table link for DAO operations like Where/Data. 12 | type Link struct { 13 | g.Meta `orm:"table:link, do:true"` 14 | Id interface{} // 15 | Name interface{} // 名称 16 | Description interface{} // 描述 17 | Link interface{} // 链接 18 | } 19 | -------------------------------------------------------------------------------- /internal/model/do/reading.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package do 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/frame/g" 9 | "github.com/gogf/gf/v2/os/gtime" 10 | ) 11 | 12 | // Reading is the golang structure of table reading for DAO operations like Where/Data. 13 | type Reading struct { 14 | g.Meta `orm:"table:reading, do:true"` 15 | Id interface{} // 16 | Name interface{} // 书名 17 | Author interface{} // 作者 18 | Status interface{} // 状态: 1完结 2在读 3弃读 19 | FinishedAt *gtime.Time // 读完时间 20 | } 21 | -------------------------------------------------------------------------------- /internal/model/do/reply.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package do 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/frame/g" 9 | "github.com/gogf/gf/v2/os/gtime" 10 | ) 11 | 12 | // Reply is the golang structure of table reply for DAO operations like Where/Data. 13 | type Reply struct { 14 | g.Meta `orm:"table:reply, do:true"` 15 | Id interface{} // 16 | Aid interface{} // 文章id 17 | Rid interface{} // 根回复id,一个根可视为一个楼层 18 | Pid interface{} // 回复的id 19 | PName interface{} // 回复的名称 20 | Email interface{} // 回复人邮箱 21 | Name interface{} // 回复人名称 22 | Site interface{} // 回复人网站 23 | Content interface{} // 回复内容 24 | Status interface{} // 状态: 1待审核 2审核通过 3审核失败 25 | Reason interface{} // 审核失败原因 26 | CreatedAt *gtime.Time // 创建时间 27 | UpdatedAt *gtime.Time // 更新时间 28 | DeletedAt *gtime.Time // 删除时间 29 | } 30 | -------------------------------------------------------------------------------- /internal/model/do/sentence.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package do 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/frame/g" 9 | ) 10 | 11 | // Sentence is the golang structure of table sentence for DAO operations like Where/Data. 12 | type Sentence struct { 13 | g.Meta `orm:"table:sentence, do:true"` 14 | Id interface{} // 15 | BookId interface{} // 16 | Sentence interface{} // 17 | } 18 | -------------------------------------------------------------------------------- /internal/model/do/sentence_tag.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package do 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/frame/g" 9 | ) 10 | 11 | // SentenceTag is the golang structure of table sentence_tag for DAO operations like Where/Data. 12 | type SentenceTag struct { 13 | g.Meta `orm:"table:sentence_tag, do:true"` 14 | SId interface{} // 句子id 15 | TId interface{} // tag id 16 | } 17 | -------------------------------------------------------------------------------- /internal/model/do/tag.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package do 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/frame/g" 9 | ) 10 | 11 | // Tag is the golang structure of table tag for DAO operations like Where/Data. 12 | type Tag struct { 13 | g.Meta `orm:"table:tag, do:true"` 14 | Id interface{} // 15 | GrpId interface{} // 分组id 16 | Name interface{} // 标签名称 17 | } 18 | -------------------------------------------------------------------------------- /internal/model/do/tag_grp.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package do 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/frame/g" 9 | ) 10 | 11 | // TagGrp is the golang structure of table tag_grp for DAO operations like Where/Data. 12 | type TagGrp struct { 13 | g.Meta `orm:"table:tag_grp, do:true"` 14 | Id interface{} // 15 | Name interface{} // 标签分组名称 16 | } 17 | -------------------------------------------------------------------------------- /internal/model/entity/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldme-git/oldme-api/70948f91c0f6f3d090b431541bca7350f82e1e22/internal/model/entity/.gitkeep -------------------------------------------------------------------------------- /internal/model/entity/admin.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package entity 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/os/gtime" 9 | ) 10 | 11 | // Admin is the golang structure for table admin. 12 | type Admin struct { 13 | Id uint `json:"id" orm:"id" description:""` 14 | Username string `json:"username" orm:"username" description:"用户名"` 15 | Password string `json:"password" orm:"password" description:"密码"` 16 | Nickname string `json:"nickname" orm:"nickname" description:"昵称"` 17 | Avatar string `json:"avatar" orm:"avatar" description:"头像,base64"` 18 | Register *gtime.Time `json:"register" orm:"register" description:"注册时间"` 19 | Salt string `json:"salt" orm:"salt" description:"随机盐值"` 20 | LastLogin *gtime.Time `json:"lastLogin" orm:"last_login" description:"最后登录时间"` 21 | } 22 | -------------------------------------------------------------------------------- /internal/model/entity/article.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package entity 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/os/gtime" 9 | ) 10 | 11 | // Article is the golang structure for table article. 12 | type Article struct { 13 | Id uint `json:"id" orm:"id" description:""` 14 | GrpId uint `json:"grpId" orm:"grp_id" description:"分组id"` 15 | Title string `json:"title" orm:"title" description:"标题"` 16 | Author string `json:"author" orm:"author" description:"作者"` 17 | Thumb string `json:"thumb" orm:"thumb" description:"图片地址"` 18 | Tags string `json:"tags" orm:"tags" description:"标签,依英文逗号隔开"` 19 | Description string `json:"description" orm:"description" description:"简介"` 20 | Content string `json:"content" orm:"content" description:"内容"` 21 | Order int `json:"order" orm:"order" description:"排序,越大越靠前"` 22 | Ontop uint `json:"ontop" orm:"ontop" description:"是否置顶"` 23 | Onshow uint `json:"onshow" orm:"onshow" description:"是否显示"` 24 | Hist uint `json:"hist" orm:"hist" description:"点击数"` 25 | Post uint `json:"post" orm:"post" description:"评论数"` 26 | CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"创建时间"` 27 | UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` 28 | DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"删除时间"` 29 | LastedAt *gtime.Time `json:"lastedAt" orm:"lasted_at" description:"最后浏览时间"` 30 | } 31 | -------------------------------------------------------------------------------- /internal/model/entity/article_grp.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package entity 6 | 7 | // ArticleGrp is the golang structure for table article_grp. 8 | type ArticleGrp struct { 9 | Id uint `json:"id" orm:"id" description:""` 10 | Name string `json:"name" orm:"name" description:"名称"` 11 | Tags string `json:"tags" orm:"tags" description:"标签,依英文逗号隔开"` 12 | Description string `json:"description" orm:"description" description:"简介"` 13 | Onshow uint `json:"onshow" orm:"onshow" description:"是否显示"` 14 | Order int `json:"order" orm:"order" description:"排序,越大越靠前"` 15 | } 16 | -------------------------------------------------------------------------------- /internal/model/entity/link.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package entity 6 | 7 | // Link is the golang structure for table link. 8 | type Link struct { 9 | Id uint `json:"id" orm:"id" description:""` 10 | Name string `json:"name" orm:"name" description:"名称"` 11 | Description string `json:"description" orm:"description" description:"描述"` 12 | Link string `json:"link" orm:"link" description:"链接"` 13 | } 14 | -------------------------------------------------------------------------------- /internal/model/entity/reading.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package entity 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/os/gtime" 9 | ) 10 | 11 | // Reading is the golang structure for table reading. 12 | type Reading struct { 13 | Id uint `json:"id" orm:"id" description:""` 14 | Name string `json:"name" orm:"name" description:"书名"` 15 | Author string `json:"author" orm:"author" description:"作者"` 16 | Status uint `json:"status" orm:"status" description:"状态: 1完结 2在读 3弃读"` 17 | FinishedAt *gtime.Time `json:"finishedAt" orm:"finished_at" description:"读完时间"` 18 | } 19 | -------------------------------------------------------------------------------- /internal/model/entity/reply.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package entity 6 | 7 | import ( 8 | "github.com/gogf/gf/v2/os/gtime" 9 | ) 10 | 11 | // Reply is the golang structure for table reply. 12 | type Reply struct { 13 | Id uint `json:"id" orm:"id" description:""` 14 | Aid int `json:"aid" orm:"aid" description:"文章id"` 15 | Rid int `json:"rid" orm:"rid" description:"根回复id,一个根可视为一个楼层"` 16 | Pid int `json:"pid" orm:"pid" description:"回复的id"` 17 | PName string `json:"pName" orm:"p_name" description:"回复的名称"` 18 | Email string `json:"email" orm:"email" description:"回复人邮箱"` 19 | Name string `json:"name" orm:"name" description:"回复人名称"` 20 | Site string `json:"site" orm:"site" description:"回复人网站"` 21 | Content string `json:"content" orm:"content" description:"回复内容"` 22 | Status int `json:"status" orm:"status" description:"状态: 1待审核 2审核通过 3审核失败"` 23 | Reason string `json:"reason" orm:"reason" description:"审核失败原因"` 24 | CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"创建时间"` 25 | UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` 26 | DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"删除时间"` 27 | } 28 | -------------------------------------------------------------------------------- /internal/model/entity/sentence.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package entity 6 | 7 | // Sentence is the golang structure for table sentence. 8 | type Sentence struct { 9 | Id uint `json:"id" orm:"id" description:""` 10 | BookId uint `json:"bookId" orm:"book_id" description:""` 11 | Sentence string `json:"sentence" orm:"sentence" description:""` 12 | } 13 | -------------------------------------------------------------------------------- /internal/model/entity/sentence_tag.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package entity 6 | 7 | // SentenceTag is the golang structure for table sentence_tag. 8 | type SentenceTag struct { 9 | SId uint `json:"sId" orm:"s_id" description:"句子id"` 10 | TId uint `json:"tId" orm:"t_id" description:"tag id"` 11 | } 12 | -------------------------------------------------------------------------------- /internal/model/entity/tag.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package entity 6 | 7 | // Tag is the golang structure for table tag. 8 | type Tag struct { 9 | Id uint `json:"id" orm:"id" description:""` 10 | GrpId uint `json:"grpId" orm:"grp_id" description:"分组id"` 11 | Name string `json:"name" orm:"name" description:"标签名称"` 12 | } 13 | -------------------------------------------------------------------------------- /internal/model/entity/tag_grp.go: -------------------------------------------------------------------------------- 1 | // ================================================================================= 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // ================================================================================= 4 | 5 | package entity 6 | 7 | // TagGrp is the golang structure for table tag_grp. 8 | type TagGrp struct { 9 | Id uint `json:"id" orm:"id" description:""` 10 | Name string `json:"name" orm:"name" description:"标签分组名称"` 11 | } 12 | -------------------------------------------------------------------------------- /internal/model/file.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | type FileInfo struct { 4 | Name string `json:"name" dc:"文件名称"` 5 | Url string `json:"path" dc:"文件URL"` 6 | Dir string `json:"-" dc:"文件DIR"` // dir不能暴露到外部,他包含着服务器的目录结构 7 | } 8 | -------------------------------------------------------------------------------- /internal/model/link.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | type LinkInput struct { 4 | Name string `json:"name" v:"required|length:1, 20"` 5 | Description string `json:"description" v:"length:2, 200"` 6 | Link string `json:"link" v:"required|length:1, 200"` 7 | } 8 | -------------------------------------------------------------------------------- /internal/model/reply.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/os/gtime" 5 | "github.com/oldme-git/oldme-api/internal/model/entity" 6 | ) 7 | 8 | const ( 9 | AllStatus = iota 10 | CheckStatus 11 | SuccessStatus 12 | FailStatus 13 | ) 14 | 15 | // ReplyInput 新增回复,多了Status 16 | type ReplyInput struct { 17 | ReplyInputApp 18 | Status ReplyStatus `json:"status" v:"in:1,2,3" dc:"审核状态,1待审核 2审核通过 3审核失败,默认2"` 19 | } 20 | 21 | // ReplyInputApp App新增回复 22 | type ReplyInputApp struct { 23 | ReplyBody 24 | Aid Id `json:"aid" v:"required|integer|between:1,4294967295"` 25 | Pid Id `json:"pid" v:"required|integer|between:0,4294967295" dc:"如果传入pid,aid会自动跟随父回复"` 26 | } 27 | 28 | // ReplyBody 回复内容主体 29 | type ReplyBody struct { 30 | Name string `json:"name" v:"required|length:1,20"` 31 | Email string `json:"email" v:"required|email|length:1,100"` 32 | Site string `json:"site" v:"url|length:1,50"` 33 | Content string `json:"content" v:"required|length:2, 100000"` 34 | } 35 | 36 | type ReplyQuery struct { 37 | Paging 38 | Aid Id `json:"aid" v:"integer|between:1,4294967295"` 39 | Status ReplyStatus `json:"status" v:"in:1,2,3" dc:"查询状态,1待审核 2审核通过 3审核失败 ,不传则查询所有"` 40 | Search string `v:"length: 1,30" json:"search" dc:"查询文本,会检索名称,邮箱,内容"` 41 | } 42 | 43 | type ReplyShow struct { 44 | ArticleTitle string `json:"articleTitle" dc:"回复的文章标题"` 45 | ParentReply entity.Reply `json:"parentReply" dc:"父级回复"` 46 | entity.Reply 47 | } 48 | 49 | // ReplyFloorApp 回复楼,是一个二维结构 50 | type ReplyFloorApp struct { 51 | Id Id `json:"id" description:""` 52 | Pid Id `json:"pid" description:"回复父id"` 53 | PName string `json:"pName" description:"回复父名称"` 54 | Email string `json:"email" description:"回复人邮箱"` 55 | Name string `json:"name" description:"回复人名称"` 56 | Site string `json:"site" description:"回复人网站"` 57 | Content string `json:"content" description:"回复内容"` 58 | CreatedAt *gtime.Time `json:"createdAt" description:"创建时间"` 59 | UpdatedAt *gtime.Time `json:"updatedAt" description:"更新时间"` 60 | List []ReplyFloorApp `json:"list" description:"子回复列表"` 61 | } 62 | -------------------------------------------------------------------------------- /internal/model/sentence.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | type SentenceQuery struct { 4 | Paging 5 | BookId Id 6 | // 根据指定id查询 7 | Ids []Id 8 | Search string 9 | } 10 | 11 | type SentenceInput struct { 12 | Id Id 13 | BookId Id 14 | TagIds []Id 15 | Sentence string 16 | } 17 | -------------------------------------------------------------------------------- /internal/service/account.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | type () 9 | -------------------------------------------------------------------------------- /internal/service/admin.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | type () 9 | -------------------------------------------------------------------------------- /internal/service/article.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | type () 9 | -------------------------------------------------------------------------------- /internal/service/article_grp.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | type () 9 | -------------------------------------------------------------------------------- /internal/service/file.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | type () 9 | -------------------------------------------------------------------------------- /internal/service/link.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | type () 9 | -------------------------------------------------------------------------------- /internal/service/middleware.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | type () 9 | -------------------------------------------------------------------------------- /internal/service/reading.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | type () 9 | -------------------------------------------------------------------------------- /internal/service/reply.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | type () 9 | -------------------------------------------------------------------------------- /internal/service/rich.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | type () 9 | -------------------------------------------------------------------------------- /internal/service/saying.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | type () 9 | -------------------------------------------------------------------------------- /internal/service/sentence.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | type () 9 | -------------------------------------------------------------------------------- /internal/service/tag.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | type () 9 | -------------------------------------------------------------------------------- /internal/service/tag_grp.go: -------------------------------------------------------------------------------- 1 | // ================================================================================ 2 | // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 3 | // You can delete these comments if you wish manually maintain this interface file. 4 | // ================================================================================ 5 | 6 | package service 7 | 8 | type () 9 | -------------------------------------------------------------------------------- /internal/utility/err.go: -------------------------------------------------------------------------------- 1 | package utility 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/gogf/gf/v2/errors/gcode" 7 | "github.com/gogf/gf/v2/errors/gerror" 8 | ) 9 | 10 | type pErr struct { 11 | maps map[int]string 12 | } 13 | 14 | const CodeOk = 0 15 | const CodeErrSys = 99999 16 | 17 | var Err = &pErr{ 18 | maps: map[int]string{ 19 | CodeOk: "好耶", 20 | CodeErrSys: "未知错误", 21 | 10100: "sorry,数据走丢了", 22 | 10101: "你所在文章分类不存在", 23 | 10201: "你所在的文章不存在", 24 | 10301: "网站地址需要http协议奥", 25 | 10302: "回复的内容不在同一文章下", 26 | 10303: "你要回复的内容不见了", 27 | 10501: "图片类型不正确", 28 | 10503: "文件不存在", 29 | 10504: "资源不存在", 30 | 10601: "标签已存在", 31 | 20100: "你的账号或者密码不对哩", 32 | 20101: "不正确的或者过期的token,请重新获取", 33 | 20102: "┗|`O′|┛ 嗷~~,获取你信息失败了", 34 | }, 35 | } 36 | 37 | // GetMsg 获取code码对应的msg 38 | func (c *pErr) GetMsg(code int) string { 39 | return c.maps[code] 40 | } 41 | 42 | // Skip 抛出一个业务级别的错误,不会打印错误堆栈信息 43 | func (c *pErr) Skip(code int, msg ...string) (err error) { 44 | var msgStr string 45 | if len(msg) == 0 { 46 | msgStr = c.GetMsg(code) 47 | } else { 48 | msg = append([]string{c.GetMsg(code)}, msg...) 49 | msgStr = strings.Join(msg, ", ") 50 | } 51 | return gerror.NewWithOption(gerror.Option{ 52 | Stack: false, 53 | Text: msgStr, 54 | Code: gcode.New(code, "", nil), 55 | }) 56 | } 57 | 58 | // Sys 抛出一个系统级别的错误,使用特殊的code码:99999 59 | // !!! 使用该方法时,它会打印错误堆栈信息到日志,但是一定不要把任何错误信息抛出到客户端,防止泄露系统信息 60 | // !!! 推荐做法是在后置中间件中捕获 code 99999 的错误,然后返回给客户端一个统一的错误提示 61 | func (c *pErr) Sys(err error) error { 62 | return gerror.NewCode(gcode.New(CodeErrSys, "", nil), err.Error()) 63 | } 64 | 65 | // GetOkMsg 获取成功的msg 66 | func (c *pErr) GetOkMsg() string { 67 | return c.GetMsg(CodeOk) 68 | } 69 | 70 | // GetSysMsg 获取系统错误的msg 71 | func (c *pErr) GetSysMsg() string { 72 | return c.GetMsg(CodeErrSys) 73 | } 74 | -------------------------------------------------------------------------------- /internal/utility/ext.go: -------------------------------------------------------------------------------- 1 | package utility 2 | 3 | import ( 4 | "errors" 5 | "strings" 6 | 7 | "github.com/gogf/gf/v2/os/gfile" 8 | ) 9 | 10 | type pExt struct { 11 | } 12 | 13 | var Ext pExt 14 | 15 | // Img 限制图片类文件类型 16 | func (e pExt) Img(imgPath string) error { 17 | ext := "png, jpg, jpeg, gif" 18 | var ( 19 | pathExt = gfile.ExtName(imgPath) 20 | sliceExt = strings.Split(ext, ",") 21 | ) 22 | 23 | for _, item := range sliceExt { 24 | if strings.ToLower(pathExt) == strings.ToLower(item) { 25 | return nil 26 | } 27 | } 28 | return errors.New("图片类型不正确,应为" + ext) 29 | } 30 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | 7 | "github.com/gogf/gf/v2/frame/g" 8 | "github.com/gogf/gf/v2/os/gctx" 9 | "github.com/gogf/gf/v2/os/gtime" 10 | "github.com/oldme-git/oldme-api/internal/cmd" 11 | 12 | _ "github.com/gogf/gf/contrib/drivers/mysql/v2" 13 | _ "github.com/oldme-git/oldme-api/internal/logic" 14 | _ "github.com/oldme-git/oldme-api/internal/utility" 15 | _ "github.com/oldme-git/oldme-api/utility/uinit" 16 | ) 17 | 18 | const ( 19 | VERSION = "v1.6.0" 20 | ) 21 | 22 | func main() { 23 | var err error 24 | 25 | fmt.Println(VERSION) 26 | 27 | // 全局设置i18n 28 | g.I18n().SetLanguage("zh-CN") 29 | 30 | // 全局进程时间为Asia/shanghai 31 | err = gtime.SetTimeZone("Asia/Shanghai") 32 | if err != nil { 33 | panic(err) 34 | } 35 | 36 | // 检查数据库是否能连接 37 | err = connData() 38 | if err != nil { 39 | panic(err) 40 | } 41 | 42 | cmd.Main.Run(gctx.New()) 43 | } 44 | 45 | // 检查数据库连接是否正常 46 | func connData() error { 47 | err := g.DB().PingMaster() 48 | if err != nil { 49 | return errors.New("连接到数据库失败") 50 | } 51 | return nil 52 | } 53 | -------------------------------------------------------------------------------- /manifest/config/config.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | address: ":8000" 3 | clientMaxBodySize: "2MB" 4 | openapiPath: "/api.json" 5 | swaggerPath: "/swagger" 6 | logger: 7 | path: "./log" # 日志文件路径。默认为空,表示关闭,仅输出到终端 8 | file: "{Y-m-d}.log" 9 | level: "all" 10 | stdout: true 11 | 12 | # 生成登录token的key,请尽量写的越复杂 13 | jwtKey: "oldme-jwt" 14 | 15 | upload: 16 | url: "http://127.0.0.1:8001/static" # url访问路径,会在http接口中拼接返回 17 | dir: "D:/project/oldme-api/static" # 磁盘访问路径,使用绝对路径 18 | 19 | database: 20 | logger: 21 | path: "./log/sql" 22 | level: "all" 23 | stdout: true 24 | default: 25 | link: "mysql:root:12345678@tcp(srv.com:3306)/oldme?loc=Local" 26 | debug: true 27 | 28 | redis: 29 | default: 30 | address: 127.0.0.1:6379 31 | db: 1 32 | 33 | # 固定的saying tag_id 34 | sayingTagId: 17 -------------------------------------------------------------------------------- /manifest/deploy/kustomize/base/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: template-single 5 | labels: 6 | app: template-single 7 | spec: 8 | replicas: 1 9 | selector: 10 | matchLabels: 11 | app: template-single 12 | template: 13 | metadata: 14 | labels: 15 | app: template-single 16 | spec: 17 | containers: 18 | - name : main 19 | image: template-single 20 | imagePullPolicy: Always 21 | 22 | -------------------------------------------------------------------------------- /manifest/deploy/kustomize/base/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | resources: 4 | - deployment.yaml 5 | - service.yaml 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /manifest/deploy/kustomize/base/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: template-single 5 | spec: 6 | ports: 7 | - port: 80 8 | protocol: TCP 9 | targetPort: 8000 10 | selector: 11 | app: template-single 12 | 13 | -------------------------------------------------------------------------------- /manifest/deploy/kustomize/overlays/develop/configmap.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | name: template-single-configmap 5 | data: 6 | config.yaml: | 7 | server: 8 | address: ":8000" 9 | openapiPath: "/api.json" 10 | swaggerPath: "/swagger" 11 | 12 | logger: 13 | level : "all" 14 | stdout: true 15 | -------------------------------------------------------------------------------- /manifest/deploy/kustomize/overlays/develop/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: template-single 5 | spec: 6 | template: 7 | spec: 8 | containers: 9 | - name : main 10 | image: template-single:develop -------------------------------------------------------------------------------- /manifest/deploy/kustomize/overlays/develop/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | 4 | resources: 5 | - ../../base 6 | - configmap.yaml 7 | 8 | patchesStrategicMerge: 9 | - deployment.yaml 10 | 11 | namespace: default 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /manifest/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM frolvlad/alpine-glibc:alpine-3 2 | 3 | RUN apk update && apk add tzdata ca-certificates bash 4 | 5 | ENV WORKDIR /app 6 | ADD ./main $WORKDIR/main 7 | ADD ./manifest/i18n $WORKDIR/i18n 8 | 9 | RUN chmod +x $WORKDIR/main 10 | 11 | WORKDIR $WORKDIR 12 | CMD ./main -------------------------------------------------------------------------------- /manifest/i18n/zh-CN/validation.toml: -------------------------------------------------------------------------------- 1 | "gf.gvalid.rule.required" = "{field}字段不能为空" 2 | "gf.gvalid.rule.required-if" = "{field}字段不能为空" 3 | "gf.gvalid.rule.required-unless" = "{field}字段不能为空" 4 | "gf.gvalid.rule.required-with" = "{field}字段不能为空" 5 | "gf.gvalid.rule.required-with-all" = "{field}字段不能为空" 6 | "gf.gvalid.rule.required-without" = "{field}字段不能为空" 7 | "gf.gvalid.rule.required-without-all" = "{field}字段不能为空" 8 | "gf.gvalid.rule.date" = "{field}字段值`{value}`日期格式不满足Y-m-d格式,例如: 2001-02-03" 9 | "gf.gvalid.rule.datetime" = "{field}字段值`{value}`日期格式不满足Y-m-d H:i:s格式,例如: 2001-02-03 12:00:00" 10 | "gf.gvalid.rule.date-format" = "{field}字段值`{value}`日期格式不满足{format}" 11 | "gf.gvalid.rule.email" = "{field}字段值`{value}`邮箱地址格式不正确" 12 | "gf.gvalid.rule.phone" = "{field}字段值`{value}`手机号码格式不正确" 13 | "gf.gvalid.rule.phone-loose" = "{field}字段值`{value}`手机号码格式不正确" 14 | "gf.gvalid.rule.telephone" = "{field}字段值`{value}`电话号码格式不正确" 15 | "gf.gvalid.rule.passport" = "{field}字段值`{value}`账号格式不合法,必需以字母开头,只能包含字母、数字和下划线,长度在6~18之间" 16 | "gf.gvalid.rule.password" = "{field}字段值`{value}`密码格式不合法,密码格式为任意6-18位的可见字符" 17 | "gf.gvalid.rule.password2" = "{field}字段值`{value}`密码格式不合法,密码格式为任意6-18位的可见字符,必须包含大小写字母和数字" 18 | "gf.gvalid.rule.password3" = "{field}字段值`{value}`密码格式不合法,密码格式为任意6-18位的可见字符,必须包含大小写字母、数字和特殊字符" 19 | "gf.gvalid.rule.postcode" = "{field}字段值`{value}`邮政编码不正确" 20 | "gf.gvalid.rule.resident-id" = "{field}字段值`{value}`身份证号码格式不正确" 21 | "gf.gvalid.rule.bank-card" = "{field}字段值`{value}`银行卡号格式不正确" 22 | "gf.gvalid.rule.qq" = "{field}字段值`{value}`QQ号码格式不正确" 23 | "gf.gvalid.rule.ip" = "{field}字段值`{value}`IP地址格式不正确" 24 | "gf.gvalid.rule.ipv4" = "{field}字段值`{value}`IPv4地址格式不正确" 25 | "gf.gvalid.rule.ipv6" = "{field}字段值`{value}`IPv6地址格式不正确" 26 | "gf.gvalid.rule.mac" = "{field}字段值`{value}`MAC地址格式不正确" 27 | "gf.gvalid.rule.url" = "{field}字段值`{value}`URL地址格式不正确" 28 | "gf.gvalid.rule.domain" = "{field}字段值`{value}`域名格式不正确" 29 | "gf.gvalid.rule.length" = "{field}字段值`{value}`字段长度应当为{min}到{max}个字符" 30 | "gf.gvalid.rule.min-length" = "{field}字段值`{value}`字段最小长度应当为{min}" 31 | "gf.gvalid.rule.max-length" = "{field}字段值`{value}`字段最大长度应当为{max}" 32 | "gf.gvalid.rule.size" = "{field}字段值`{value}`字段长度必须应当为{size}" 33 | "gf.gvalid.rule.between" = "{field}字段值`{value}`字段大小应当为{min}到{max}" 34 | "gf.gvalid.rule.min" = "{field}字段值`{value}`字段最小值应当为{min}" 35 | "gf.gvalid.rule.max" = "{field}字段值`{value}`字段最大值应当为{max}" 36 | "gf.gvalid.rule.json" = "{field}字段值`{value}`字段应当为JSON格式" 37 | "gf.gvalid.rule.xml" = "{field}字段值`{value}`字段应当为XML格式" 38 | "gf.gvalid.rule.array" = "{field}字段值`{value}`字段应当为数组" 39 | "gf.gvalid.rule.integer" = "{field}字段值`{value}`字段应当为整数" 40 | "gf.gvalid.rule.float" = "{field}字段值`{value}`字段应当为浮点数" 41 | "gf.gvalid.rule.boolean" = "{field}字段值`{value}`字段应当为布尔值" 42 | "gf.gvalid.rule.same" = "{field}字段值`{value}`字段值必须和{field}相同" 43 | "gf.gvalid.rule.different" = "{field}字段值`{value}`字段值不能与{field}相同" 44 | "gf.gvalid.rule.in" = "{field}字段值`{value}`字段值应当满足取值范围:{pattern}" 45 | "gf.gvalid.rule.not-in" = "{field}字段值`{value}`字段值不应当满足取值范围:{pattern}" 46 | "gf.gvalid.rule.regex" = "{field}字段值`{value}`字段值不满足规则:{pattern}" 47 | "gf.gvalid.rule.__default__" = "{field}字段值`{value}`字段值不合法" 48 | -------------------------------------------------------------------------------- /manifest/webserver/oldme.conf: -------------------------------------------------------------------------------- 1 | limit_req_zone $binary_remote_addr zone=throttle:10m rate=10r/s; 2 | server { 3 | add_header 'Access-Control-Allow-Origin' $http_origin; 4 | add_header 'Access-Control-Allow-Credentials' 'true'; 5 | add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; 6 | add_header 'Access-Control-Allow-Headers' 'DNT,web-token,app-token,Authorization,Accept,Origin,Keep-Alive,User-Agent,X-Mx-ReqToken,X-Data-Type,X-Auth-Token,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; 7 | add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; 8 | proxy_set_header X-Real-IP $remote_addr; 9 | if ($request_method = 'OPTIONS') { 10 | return 204; 11 | } 12 | client_max_body_size 2m; 13 | server_name api.oldme.top; 14 | listen 80; 15 | index index.html index.htm index.php; 16 | limit_req zone=throttle burst=2 nodelay; 17 | location ~* /static { 18 | root /home/wwwroot/oldme-api; 19 | } 20 | 21 | location / { 22 | proxy_pass http://oldme-api:8000; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /resource/i18n/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldme-git/oldme-api/70948f91c0f6f3d090b431541bca7350f82e1e22/resource/i18n/.gitkeep -------------------------------------------------------------------------------- /resource/public/html/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldme-git/oldme-api/70948f91c0f6f3d090b431541bca7350f82e1e22/resource/public/html/.gitkeep -------------------------------------------------------------------------------- /resource/public/plugin/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldme-git/oldme-api/70948f91c0f6f3d090b431541bca7350f82e1e22/resource/public/plugin/.gitkeep -------------------------------------------------------------------------------- /resource/public/resource/css/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldme-git/oldme-api/70948f91c0f6f3d090b431541bca7350f82e1e22/resource/public/resource/css/.gitkeep -------------------------------------------------------------------------------- /resource/public/resource/image/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldme-git/oldme-api/70948f91c0f6f3d090b431541bca7350f82e1e22/resource/public/resource/image/.gitkeep -------------------------------------------------------------------------------- /resource/public/resource/js/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldme-git/oldme-api/70948f91c0f6f3d090b431541bca7350f82e1e22/resource/public/resource/js/.gitkeep -------------------------------------------------------------------------------- /resource/template/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldme-git/oldme-api/70948f91c0f6f3d090b431541bca7350f82e1e22/resource/template/.gitkeep -------------------------------------------------------------------------------- /test/gen_admin_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "testing" 5 | 6 | _ "github.com/gogf/gf/contrib/drivers/mysql/v2" 7 | "github.com/oldme-git/oldme-api/internal/logic/admin" 8 | 9 | "github.com/gogf/gf/v2/os/gctx" 10 | "github.com/oldme-git/oldme-api/internal/model" 11 | ) 12 | 13 | // 生成admin用户 14 | func TestGenAdmin(t *testing.T) { 15 | err := admin.Create(gctx.New(), &model.AdminInput{ 16 | Username: "admin", 17 | Password: "tyty1022", 18 | Nickname: "half", 19 | Avatar: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAA3NCSVQICAjb4U/gAAAAl3pUWHRSYXcgcHJvZmlsZSB0eXBlIEFQUDEAABiVVY5RCsQwCET/c4oeYdTEJMcJJV0Ky7b0/h+bNHa7fYIjI4y6V/3UY52n/diW9V3d1CFKzmefuQBIGDAgBOqKaJYO1ZwifBvI/IoHPurSKuqs4TSktzxyPMwSbtUyythb1k9Dwf+NcP11wbbjOzOwZEnmPW+RjCdO3BdH2DYTyjfH2QAACBdJREFUSIlVVkmPJEcVfu9FRmbWXtXVNd09m2fxzHTPeMHGZizbJyxsQLI4I1niZ/BHOHFF3PABCQsBxjKLARl78IbXMW171t6quroqszIzIt7HIWtakIcIKTPfixff970vgn/8o58yERGBiIkAgAhQ1cDCTIaZRYSJARCgBCIiIq4HJgaBl6HMLMwAB0X9RKSoPxPzMpSICHy8JjFAAAxzpeHBSzBzHVdXt5wBJQL0uIgIxxUtaweRAgCB60ygTsueWmmQCx4mSmKB8Wrv7o8P82lsDDErQMAyDaGOqmfBg7KX2aEAlpsnAvGKLUdm4ovx3e1Pk7ToJGHQjTph9/GTpy5tXAghqOIYsnoEwKREIFI53g4AQEGg43LAqXib3Tm4fU/nB09cv9SOwr1vvsx95ZLmrZvvSJ4P2j1oQE3dMkkdXi8oAhBUgTrz8Z/LJ/Uzl+fDlWS41ms34zRy6yuyfeOfOzt3JtD5YufkcNUyk2oN7hLTYxIBAVSDagiqgaDL8gECmDkO2aw057bOTY+y0vm8CgqstN29m59Jimy8Nx1P1lIm5joEAHGNrdbYmKuXnsUSnSU9TMxCTALibrSQpGmTcGK1/9kn27O8bKWGob2+fedf2y3biGyUzXaSKKnILDngpWZraQkIDyS9lAET8ZI2zHyC6jCbF6uj4aXN849snf/WE48zUTMma6NFmPdstpjvLyZ3a1yWWDHhgYCFAK5Fw8wMQJV0SQO0sr0T673nvnN1dbi6OujFUbQ4vH/l8mi8nzVjM1jfmOQu96ETV6bWz/81EwGIQERQZiYQG9k4ucYwRa5lOS/LBavbWO3euXXPLz5fFMYZHjS535ZuP42/KYr8yKTdzIvYTkt0HhhLqpcgEVEELCEyhptd+/4/3iYtDfPauTPZLBPF6x9UhffPX+xlrmoZMf1eWWXzPJw52/3P7pHmC1LHNjEuF9NVeMbSPwgAc0QAiIXJpjKbFBtnzzFLns2//PijjfVTouXh/sG4RG9rMGx1hg+t5tO9UJZFjriRlMW0KstGI5lPxp3BWlBfNxeIiZbNFAFgIoC9d0SsUAZaPXvl8aeKnMTIKGnb3VutUePr25PG2Lsqq1xIEslKbUQhSRsL78XALWam0XIAE7jWJBERzObF68wskSAEIQFTVbj+avLFBx+1u0OAWiknUTqZlP2mHOzsZXk1noYTp0bNhl2gcThbqKvmpR82BEm7VCEGEyuIluZKRIBI0CDEHJw++czV2fjo5EPXmIVIM5/AJFmBMj1x6sKIW8OL1y6dPzfcunSqLYiFXaC8DNP5LAqV1M6KYwsleWBzaowQURTbNDHlImEhJmIwgRupnft458ANVrrD1V4jjZmNie2TT1+5eLofJ7bfkN1ZNSkqMNP/6LS2a6IlKVSW/oUXn/rjb/7W6LSIlr3NQpbVkh5m8F5t0g4eXsyiclEcPffD717f3pG3Ph9eOe2NvJ8VfyqR4vikYLN58boIEROUT58dwS0OD4t6Y1BiglNiE0Xz7PLDJwWHPpjIxrbZU4oODo6qm3fjtz7vdTsMn/iwkY0riW+RWFp2rxATCzRwWfqrW2du/P1LMUwEUmLCTHWzaZ+x1UvX169cTN5/75s0aaat9sraqVZnUN34Kn3vTrOdFL68f7A3K/Ksql7g6rKwIzDAIKm7oirDs89vffjux41+U2szJZorvdI2L0dB3tsePfrw+GD3wuaFtJUO1tapqMa/fnMT1jat+rJcZM4HV5Us0Ww2fcnnMVj5AclEqKoQMe7emzMTAFb2Sk9bnHXZzVu3B5dHttW/fXfS7/eGGxt6ONv+2a9OV+KhlhmquXOxteqcTRtFCFwtfqBFASKQEFOeFa/85HtvvfGBbSQEZjBADvg28rysTGQxzl2B0fkLreEqHUz3f/67jeFKamWaZaWrGIhNpK5S1SI7OpjPPHF3sveosCeS4MLmIydf//0bUWQe+Dgc9FlLcVEeHM1MxFXQ8Y0PH3tsc81EB7/468aZjVQkKxbq3KjbJ5LDfN5ptACU3oHC+HDnMJtvVXkJjYrSX3vk2i//8Orw4pnaPUBwRFu+yPLcO5c5d3519PFv324Ui/t//mRttNK0Se6rygXP1Gm0fZ71Er8/HWuZZT50E1u4UDbWv3AUG5Lvv3z9zdfeZFMRUB80ID4nlLrCV5Uy95OEmFZH/d2//Ls3aHul3clBHMXOexvCrTtfHc0n27u7vsonzjfTpkSWWW63Wp8liSBII5a3X3s3XWmFqqxPPAJyQlVVQanUoET7s6P708POoFdVbppnxshsPjMiAHnvxMiceVxVkY2d4VbcSKwsIokAApl8j+2KHd/Z6Y3WRSJAmXSidAG+6cudsqQQMufGZdm3VpgXRWU5kFBVZJWrrCBfZEF4z4VR2mjFacIMQjNufSpRRBx1egOaRcNzJ1lEVZlIiVcYwhxb646OFkFnwUtkmKlpIm/KvKym+/uDVrrwJSDWiNEwC/AaSP08+NTGg2qhaQomSZoNYrlz7wta3oxUoAcgdkVkE/ah8K4K/sj52ERE3DJMLO1mY54X9XVXgSroAlAFsek2ukLGajUgYqFosrebxM0kaSpIVJlJCV2iuVPjZuq9ExEjMTQVCmWRL7LcWASvrEQsxIkxEasyhGiaZ0ZMK20lhNXgv5ZYOoMNZmJhQBVa38+94tXu2o5N20wdoY41D/db3lWL2TSo7hwdzUpHzEZYVRUEoh4bk7bOrm5EQceTvcNsPiRVov8C4Y5mgM1zu1oAAAAASUVORK5CYII=", 20 | }) 21 | if err != nil { 22 | panic(err) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/rich_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/gogf/gf/v2/os/gctx" 7 | _ "github.com/oldme-git/oldme-api/internal/logic/file" 8 | "github.com/oldme-git/oldme-api/internal/logic/rich" 9 | _ "github.com/oldme-git/oldme-api/internal/logic/rich" 10 | ) 11 | 12 | func TestEdit(t *testing.T) { 13 | var ( 14 | oldText = "http://127.0.0.1:8001/static/rich/202212/33.pnghttp://127.0.0.1:8001/static/rich/202212/44.png" 15 | newText = "" 16 | ) 17 | rich.Edit(gctx.New(), &oldText, &newText) 18 | t.Log(newText) 19 | } 20 | 21 | func TestDel(t *testing.T) { 22 | var text = "http://127.0.0.1:8001/static/rich/202212/cp1b74s25srkibxxwu.pnghttp://127.0.0.1:8001/static/rich/202212/cp1b77mc9nycaffuo9.png" 23 | rich.Del(gctx.New(), &text) 24 | } 25 | -------------------------------------------------------------------------------- /utility/gother.go: -------------------------------------------------------------------------------- 1 | // 这里面的函数依赖与gf 2 | 3 | package utility 4 | 5 | import ( 6 | "github.com/gogf/gf/v2/frame/g" 7 | "github.com/gogf/gf/v2/net/ghttp" 8 | "github.com/gogf/gf/v2/os/gctx" 9 | ) 10 | 11 | func Log(v interface{}) { 12 | l := g.Log() 13 | l.Info(gctx.New(), v) 14 | } 15 | 16 | func GetUrl(r *ghttp.Request) string { 17 | var proto = "http://" 18 | if r.TLS != nil { 19 | proto = "https://" 20 | } 21 | return proto + r.Host 22 | } 23 | -------------------------------------------------------------------------------- /utility/other.go: -------------------------------------------------------------------------------- 1 | package utility 2 | 3 | import ( 4 | "errors" 5 | "net" 6 | "net/http" 7 | "reflect" 8 | "strings" 9 | ) 10 | 11 | // InArray 判断某个值是否存在与切片或者数组中,此函数的命名十分优秀ヾ(≧▽≦*)o 12 | func InArray(v interface{}, i interface{}) (b bool, err error) { 13 | kind := reflect.TypeOf(i).Kind() 14 | if kind != reflect.Slice && kind != reflect.Array { 15 | return false, errors.New("给定类型必须是切片或者数组") 16 | } 17 | // 将i转换为map 18 | var ( 19 | value = reflect.ValueOf(i) 20 | m = make(map[interface{}]bool, value.Len()) 21 | ) 22 | for j := 0; j < value.Len(); j++ { 23 | m[value.Index(j).Interface()] = true 24 | } 25 | 26 | return m[v], nil 27 | } 28 | 29 | // GetIP 获取http客户端真实ip 30 | func GetIP(r *http.Request) (string, error) { 31 | ip := r.Header.Get("X-Real-IP") 32 | if net.ParseIP(ip) != nil { 33 | return ip, nil 34 | } 35 | 36 | ip = r.Header.Get("X-Forward-For") 37 | for _, i := range strings.Split(ip, ",") { 38 | if net.ParseIP(i) != nil { 39 | return i, nil 40 | } 41 | } 42 | 43 | ip, _, err := net.SplitHostPort(r.RemoteAddr) 44 | if err != nil { 45 | return "", err 46 | } 47 | 48 | if net.ParseIP(ip) != nil { 49 | return ip, nil 50 | } 51 | 52 | return "", errors.New("no valid ip found") 53 | } 54 | -------------------------------------------------------------------------------- /utility/ufile/file.go: -------------------------------------------------------------------------------- 1 | package ufile 2 | 3 | import ( 4 | "encoding/hex" 5 | "io" 6 | "strings" 7 | "sync" 8 | ) 9 | 10 | var tMap sync.Map 11 | 12 | // 注册文件类型 13 | func init() { 14 | tMap.Store("ffd8ffe000104a464946", "jpg") // JPEG (jpg) 15 | tMap.Store("89504e470d0a1a0a0000", "png") // PNG (png) 16 | tMap.Store("47494638396126026f01", "gif") // GIF (gif) 17 | tMap.Store("49492a00227105008037", "tif") // TIFF (tif) 18 | tMap.Store("424d228c010000000000", "bmp") // 16 color bitmap (bmp) 19 | tMap.Store("424d8240090000000000", "bmp") // 24 color bitmap (bmp) 20 | tMap.Store("424d8e1b030000000000", "bmp") // 256 color bitmap (bmp) 21 | tMap.Store("41433130313500000000", "dwg") // CAD (dwg) 22 | tMap.Store("3c21444f435459504520", "html") // HTML (html) 23 | tMap.Store("3c68746d6c3e0", "html") // HTML (html) 24 | tMap.Store("3c21646f637479706520", "htm") // HTM (htm) 25 | tMap.Store("48544d4c207b0d0a0942", "css") // css 26 | tMap.Store("696b2e71623d696b2e71", "js") // js 27 | tMap.Store("7b5c727466315c616e73", "rtf") // Rich Text Format (rtf) 28 | tMap.Store("38425053000100000000", "psd") // Photoshop (psd) 29 | tMap.Store("46726f6d3a203d3f6762", "eml") // Email [Outlook Express 6] (eml) 30 | tMap.Store("d0cf11e0a1b11ae10000", "doc") // MS Excel Note: Word, msi and excel file headers are the same 31 | tMap.Store("d0cf11e0a1b11ae10000", "vsd") // Visio 32 | tMap.Store("5374616E64617264204A", "mdb") // MS Access (mdb) 33 | tMap.Store("252150532D41646F6265", "ps") 34 | tMap.Store("255044462d312e350d0a", "pdf") // Adobe Acrobat (pdf) 35 | tMap.Store("2e524d46000000120001", "rmvb") // rmvb/rm 36 | tMap.Store("464c5601050000000900", "flv") // flv/f4v 37 | tMap.Store("00000020667479706d70", "mp4") 38 | tMap.Store("49443303000000002176", "mp3") 39 | tMap.Store("000001ba210001000180", "mpg") // 40 | tMap.Store("3026b2758e66cf11a6d9", "wmv") // wmv/asf 41 | tMap.Store("52494646e27807005741", "wav") // Wave (wav) 42 | tMap.Store("52494646d07d60074156", "avi") 43 | tMap.Store("4d546864000000060001", "mid") // MIDI (mid) 44 | tMap.Store("504b0304140000000800", "zip") 45 | tMap.Store("526172211a0700cf9073", "rar") 46 | tMap.Store("235468697320636f6e66", "ini") 47 | tMap.Store("504b03040a0000000000", "jar") 48 | tMap.Store("4d5a9000030000000400", "exe") // executable 49 | tMap.Store("3c25402070616765206c", "jsp") // jsp 50 | tMap.Store("4d616e69666573742d56", "mf") // MF 51 | tMap.Store("3c3f786d6c2076657273", "xml") // xml 52 | tMap.Store("494e5345525420494e54", "sql") // xml 53 | tMap.Store("7061636b616765207765", "java") // java 54 | tMap.Store("406563686f206f66660d", "bat") // bat 55 | tMap.Store("1f8b0800000000000000", "gz") // gz 56 | tMap.Store("6c6f67346a2e726f6f74", "properties") // bat 57 | tMap.Store("cafebabe0000002e0041", "class") // bat 58 | tMap.Store("49545346030000006000", "chm") // bat 59 | tMap.Store("04000000010000001300", "mxp") // bat 60 | tMap.Store("504b0304140006000800", "docx") // docx 61 | tMap.Store("d0cf11e0a1b11ae10000", "wps") // WPS 62 | tMap.Store("6431303a637265617465", "torrent") 63 | tMap.Store("6D6F6F76", "mov") // Quicktime (mov) 64 | tMap.Store("FF575043", "wpd") // WordPerfect (wpd) 65 | tMap.Store("CFAD12FEC5FD746F", "dbx") // Outlook Express (dbx) 66 | tMap.Store("2142444E", "pst") // Outlook (pst) 67 | tMap.Store("AC9EBD8F", "qdf") // Quicken (qdf) 68 | tMap.Store("E3828596", "pwl") // Windows Password (pwl) 69 | tMap.Store("2E7261FD", "ram") // Real Audio (ram) 70 | } 71 | 72 | type File interface { 73 | io.Reader 74 | io.ReaderAt 75 | io.Seeker 76 | io.Closer 77 | } 78 | 79 | // Ext 根据二进制流获取文件类型 80 | func Ext(b []byte) string { 81 | var t string 82 | enCodeStr := hex.EncodeToString(b[:10]) 83 | tMap.Range(func(key, value any) bool { 84 | k := key.(string) 85 | if strings.HasPrefix(enCodeStr, strings.ToLower(k)) || strings.HasPrefix(k, strings.ToLower(enCodeStr)) { 86 | t = value.(string) 87 | return false 88 | } 89 | return true 90 | }) 91 | return t 92 | } 93 | 94 | // IsExt 根据二进制流判断文件类型是否是所需要的 95 | func IsExt(b []byte, t string) bool { 96 | typeSlice := strings.Split(t, ",") 97 | // 获取文件类型 98 | fileType := Ext(b) 99 | for _, item := range typeSlice { 100 | if strings.ToLower(fileType) == strings.ToLower(item) { 101 | return true 102 | } 103 | } 104 | return false 105 | } 106 | -------------------------------------------------------------------------------- /utility/uinit/uinit.go: -------------------------------------------------------------------------------- 1 | // 此包可用作初始化一些配置 2 | 3 | package uinit 4 | 5 | import ( 6 | "github.com/gogf/gf/v2/os/gcfg" 7 | "github.com/gogf/gf/v2/os/gctx" 8 | ) 9 | 10 | var SayingTagId uint32 11 | 12 | func init() { 13 | sayingTagId() 14 | } 15 | 16 | // sayingTagId 获取短句标签id,用于首页展示 17 | // 从配置文件中获取 18 | func sayingTagId() { 19 | cfg, _ := gcfg.New() 20 | idRaw, err := cfg.Get(gctx.New(), "sayingTagId") 21 | if err != nil { 22 | SayingTagId = 0 23 | } else { 24 | SayingTagId = idRaw.Uint32() 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /utility/ujwt/jwt.go: -------------------------------------------------------------------------------- 1 | package ujwt 2 | 3 | import ( 4 | "github.com/gogf/gf/v2/os/gcfg" 5 | "github.com/gogf/gf/v2/os/gctx" 6 | ) 7 | 8 | var JwtKey []byte 9 | 10 | func init() { 11 | jwtInit() 12 | } 13 | 14 | func jwtInit() { 15 | cfg, _ := gcfg.New() 16 | Jwt, err := cfg.Get(gctx.New(), "jwtKey") 17 | if err != nil { 18 | panic(err) 19 | } 20 | JwtKey = Jwt.Bytes() 21 | } 22 | -------------------------------------------------------------------------------- /utility/uregex/uregex.go: -------------------------------------------------------------------------------- 1 | // Golang原生正则不支持零宽断言,该包对regexp2二次封装,方便使用。regexp2:https://github.com/dlclark/regexp2 2 | 3 | package uregex 4 | 5 | import "github.com/dlclark/regexp2" 6 | 7 | func MatchAllString(pattern string, s string) (matches []string, err error) { 8 | var re = regexp2.MustCompile(pattern, 0) 9 | m, err := re.FindStringMatch(s) 10 | if err != nil { 11 | return 12 | } 13 | for m != nil { 14 | matches = append(matches, m.String()) 15 | m, _ = re.FindNextMatch(m) 16 | } 17 | return 18 | } 19 | --------------------------------------------------------------------------------