mirror of
https://github.com/PengZhangs2017582/novel.git
synced 2025-06-16 15:31:22 +08:00
initial commit
This commit is contained in:
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
* linguist-language=GO
|
19
.gitignore
vendored
Normal file
19
.gitignore
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
.buildpath
|
||||||
|
.hgignore.swp
|
||||||
|
.project
|
||||||
|
.orig
|
||||||
|
.swp
|
||||||
|
.idea/
|
||||||
|
.settings/
|
||||||
|
.vscode/
|
||||||
|
bin/
|
||||||
|
**/.DS_Store
|
||||||
|
gf
|
||||||
|
main
|
||||||
|
main.exe
|
||||||
|
output/
|
||||||
|
manifest/output/
|
||||||
|
temp/
|
||||||
|
temp.yaml
|
||||||
|
bin
|
||||||
|
**/config/config.yaml
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 Peng Zhang
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
6
Makefile
Normal file
6
Makefile
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
ROOT_DIR = $(shell pwd)
|
||||||
|
NAMESPACE = "default"
|
||||||
|
DEPLOY_NAME = "template-single"
|
||||||
|
DOCKER_NAME = "template-single"
|
||||||
|
|
||||||
|
include ./hack/hack.mk
|
4
README.MD
Normal file
4
README.MD
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# GoFrame Template For SingleRepo
|
||||||
|
|
||||||
|
Quick Start:
|
||||||
|
- https://goframe.org/pages/viewpage.action?pageId=1114399
|
26
api/backend/login.go
Normal file
26
api/backend/login.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package backend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
)
|
||||||
|
|
||||||
|
// verify code
|
||||||
|
type GetCodeReq struct {
|
||||||
|
g.Meta `path:"/get-code" method:"post" tags:"获取验证码" summary:"获取验证码"`
|
||||||
|
Phone string `json:"phone" v:"required|phone" description:"手机号"`
|
||||||
|
CodeType int `json:"codeType" v:"required|in:1,2#类型不合法" description:"验证码类型"`
|
||||||
|
}
|
||||||
|
type GetCodeRes struct {
|
||||||
|
Code int
|
||||||
|
}
|
||||||
|
|
||||||
|
// createOrLogin
|
||||||
|
type CreateOrLoginReq struct {
|
||||||
|
g.Meta `path:"/create-or-login" method:"post" tags:"注册或登录" summary:"注册或者登录"`
|
||||||
|
Phone string `json:"phone" v:"required|phone" description:"手机号"`
|
||||||
|
Code int `json:"code" v:"required|size:6" description:"验证码"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateOrLoginRes struct {
|
||||||
|
Id uint
|
||||||
|
}
|
61
api/user/user.go
Normal file
61
api/user/user.go
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
// Package user -----------------------------
|
||||||
|
// @file : login.go
|
||||||
|
// @author : Allen
|
||||||
|
// @contact : 364438619@qq.com
|
||||||
|
// @time : 2024/1/4 22:11
|
||||||
|
// -------------------------------------------
|
||||||
|
package user
|
||||||
|
|
||||||
|
import "github.com/gogf/gf/v2/frame/g"
|
||||||
|
|
||||||
|
type CommonAddUpdate struct {
|
||||||
|
Name string `json:"name" description:"用户名"`
|
||||||
|
Phone string `json:"phone" description:"用户手机号"`
|
||||||
|
Age int `json:"age" description:"用户年龄"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add
|
||||||
|
type AddReq struct {
|
||||||
|
g.Meta `path:"/add" method:"post"`
|
||||||
|
Name string `v:"required|length:5,20"`
|
||||||
|
Phone string `v:"required|length:11,11"`
|
||||||
|
}
|
||||||
|
type AddRes struct {
|
||||||
|
Id uint
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select
|
||||||
|
type GetListReq struct {
|
||||||
|
g.Meta `path:"/get-list" method:"get"`
|
||||||
|
Id uint
|
||||||
|
Name string
|
||||||
|
Page int `v:"min:0#分页号码错误" dc:"分页号码" d:"1"`
|
||||||
|
Size int `v:"max:50#分页数量最大100条" dc:"分页数量,最大100" d:"10"`
|
||||||
|
OrderBy string
|
||||||
|
OrderByType int `v:"in:1,2#排序类型不合法" dc:"1-正序,2-逆序"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetListRes struct {
|
||||||
|
List interface{} `json:"list" description:"列表"`
|
||||||
|
Page int `json:"page" description:"分页码"`
|
||||||
|
Size int `json:"size" description:"分页数量"`
|
||||||
|
Total int `json:"total" description:"数据总数"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update
|
||||||
|
type UpdateReq struct {
|
||||||
|
g.Meta `path:"/user-update" method:"post"`
|
||||||
|
Id uint `json:"id" v:"min:1#请选择需要修改的用户" dc:"用户id"`
|
||||||
|
CommonAddUpdate
|
||||||
|
}
|
||||||
|
type UpdateRes struct {
|
||||||
|
Id uint `json:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete
|
||||||
|
type DelReq struct {
|
||||||
|
g.Meta `path:"/user-del" method:"post"`
|
||||||
|
Id uint `json:"id" v:"min:1#请选择需要刪除的用户" dc:"用户id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DelRes struct{}
|
30
go.mod
Normal file
30
go.mod
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
module novel
|
||||||
|
|
||||||
|
go 1.18
|
||||||
|
|
||||||
|
require github.com/gogf/gf/v2 v2.6.1
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/BurntSushi/toml v1.2.0 // indirect
|
||||||
|
github.com/clbanning/mxj/v2 v2.7.0 // indirect
|
||||||
|
github.com/fatih/color v1.15.0 // indirect
|
||||||
|
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||||
|
github.com/go-logr/logr v1.2.4 // indirect
|
||||||
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
|
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.6.1 // indirect
|
||||||
|
github.com/gorilla/websocket v1.5.0 // indirect
|
||||||
|
github.com/grokify/html-strip-tags-go v0.0.1 // indirect
|
||||||
|
github.com/magiconair/properties v1.8.6 // indirect
|
||||||
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
|
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||||
|
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||||
|
github.com/rivo/uniseg v0.4.4 // indirect
|
||||||
|
go.opentelemetry.io/otel v1.14.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/sdk v1.14.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/trace v1.14.0 // indirect
|
||||||
|
golang.org/x/net v0.17.0 // indirect
|
||||||
|
golang.org/x/sys v0.13.0 // indirect
|
||||||
|
golang.org/x/text v0.13.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
60
go.sum
Normal file
60
go.sum
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
|
||||||
|
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||||
|
github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
|
||||||
|
github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||||
|
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
||||||
|
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||||
|
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||||
|
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||||
|
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
|
||||||
|
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||||
|
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||||
|
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||||
|
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
|
||||||
|
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||||
|
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.6.1 h1:5VW1vlaFNSHHhMliRkGTcDshMeA52Il8T+gffJJaVMc=
|
||||||
|
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.6.1/go.mod h1:jxCa1WV/W+q0F4ILebakUsqRrl7iL3qvP+Uci0eXAew=
|
||||||
|
github.com/gogf/gf/v2 v2.6.1 h1:n/cfXM506WjhPa6Z1CEDuHNM1XZ7C8JzSDPn2AfuxgQ=
|
||||||
|
github.com/gogf/gf/v2 v2.6.1/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0=
|
||||||
|
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||||
|
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||||
|
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
|
github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0=
|
||||||
|
github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78=
|
||||||
|
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
|
||||||
|
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
|
||||||
|
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||||
|
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||||
|
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
|
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||||
|
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
|
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||||
|
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||||
|
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
|
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||||
|
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
|
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
|
||||||
|
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
|
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||||
|
go.opentelemetry.io/otel v1.14.0 h1:/79Huy8wbf5DnIPhemGB+zEPVwnN6fuQybr/SRXa6hM=
|
||||||
|
go.opentelemetry.io/otel v1.14.0/go.mod h1:o4buv+dJzx8rohcUeRmWUZhqupFvzWis188WlggnNeU=
|
||||||
|
go.opentelemetry.io/otel/sdk v1.14.0 h1:PDCppFRDq8A1jL9v6KMI6dYesaq+DFcDZvjsoGvxGzY=
|
||||||
|
go.opentelemetry.io/otel/sdk v1.14.0/go.mod h1:bwIC5TjrNG6QDCHNWvW4HLHtUQ4I+VQDsnjhvyZCALM=
|
||||||
|
go.opentelemetry.io/otel/trace v1.14.0 h1:wp2Mmvj41tDsyAJXiWDWpfNsOiIyd38fy85pyKcFq/M=
|
||||||
|
go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+gozhnZjy/rw9G8=
|
||||||
|
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||||
|
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||||
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||||
|
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
||||||
|
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
16
hack/config.yaml
Normal file
16
hack/config.yaml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
# CLI tool, only in development environment.
|
||||||
|
# https://goframe.org/pages/viewpage.action?pageId=3673173
|
||||||
|
gfcli:
|
||||||
|
docker:
|
||||||
|
build: "-a amd64 -s linux -p temp -ew"
|
||||||
|
tagPrefixes:
|
||||||
|
- my.image.pub/my-app
|
||||||
|
|
||||||
|
gen:
|
||||||
|
dao:
|
||||||
|
- link: "mysql:root:root@tcp(127.0.0.1:3306)/novel?charset=utf8&parseTime=True&loc=Local"
|
||||||
|
# tables: "nv_writer"
|
||||||
|
removePrefix: "nv_"
|
||||||
|
descriptionTag: true
|
||||||
|
noModelComment: true
|
19
hack/hack-cli.mk
Normal file
19
hack/hack-cli.mk
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
# Install/Update to the latest CLI tool.
|
||||||
|
.PHONY: cli
|
||||||
|
cli:
|
||||||
|
@set -e; \
|
||||||
|
wget -O gf https://github.com/gogf/gf/releases/latest/download/gf_$(shell go env GOOS)_$(shell go env GOARCH) && \
|
||||||
|
chmod +x gf && \
|
||||||
|
./gf install -y && \
|
||||||
|
rm ./gf
|
||||||
|
|
||||||
|
|
||||||
|
# Check and install CLI tool.
|
||||||
|
.PHONY: cli.install
|
||||||
|
cli.install:
|
||||||
|
@set -e; \
|
||||||
|
gf -v > /dev/null 2>&1 || if [[ "$?" -ne "0" ]]; then \
|
||||||
|
echo "GoFame CLI is not installed, start proceeding auto installation..."; \
|
||||||
|
make cli; \
|
||||||
|
fi;
|
75
hack/hack.mk
Normal file
75
hack/hack.mk
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
include ./hack/hack-cli.mk
|
||||||
|
|
||||||
|
# Update GoFrame and its CLI to latest stable version.
|
||||||
|
.PHONY: up
|
||||||
|
up: cli.install
|
||||||
|
@gf up -a
|
||||||
|
|
||||||
|
# Build binary using configuration from hack/config.yaml.
|
||||||
|
.PHONY: build
|
||||||
|
build: cli.install
|
||||||
|
@gf build -ew
|
||||||
|
|
||||||
|
# Parse api and generate controller/sdk.
|
||||||
|
.PHONY: ctrl
|
||||||
|
ctrl: cli.install
|
||||||
|
@gf gen ctrl
|
||||||
|
|
||||||
|
# Generate Go files for DAO/DO/Entity.
|
||||||
|
.PHONY: dao
|
||||||
|
dao: cli.install
|
||||||
|
@gf gen dao
|
||||||
|
|
||||||
|
# Parse current project go files and generate enums go file.
|
||||||
|
.PHONY: enums
|
||||||
|
enums: cli.install
|
||||||
|
@gf gen enums
|
||||||
|
|
||||||
|
# Generate Go files for Service.
|
||||||
|
.PHONY: service
|
||||||
|
service: cli.install
|
||||||
|
@gf gen service
|
||||||
|
|
||||||
|
|
||||||
|
# Build docker image.
|
||||||
|
.PHONY: image
|
||||||
|
image: cli.install
|
||||||
|
$(eval _TAG = $(shell git describe --dirty --always --tags --abbrev=8 --match 'v*' | sed 's/-/./2' | sed 's/-/./2'))
|
||||||
|
ifneq (, $(shell git status --porcelain 2>/dev/null))
|
||||||
|
$(eval _TAG = $(_TAG).dirty)
|
||||||
|
endif
|
||||||
|
$(eval _TAG = $(if ${TAG}, ${TAG}, $(_TAG)))
|
||||||
|
$(eval _PUSH = $(if ${PUSH}, ${PUSH}, ))
|
||||||
|
@gf docker ${_PUSH} -tn $(DOCKER_NAME):${_TAG};
|
||||||
|
|
||||||
|
|
||||||
|
# Build docker image and automatically push to docker repo.
|
||||||
|
.PHONY: image.push
|
||||||
|
image.push:
|
||||||
|
@make image PUSH=-p;
|
||||||
|
|
||||||
|
|
||||||
|
# Deploy image and yaml to current kubectl environment.
|
||||||
|
.PHONY: deploy
|
||||||
|
deploy:
|
||||||
|
$(eval _TAG = $(if ${TAG}, ${TAG}, develop))
|
||||||
|
|
||||||
|
@set -e; \
|
||||||
|
mkdir -p $(ROOT_DIR)/temp/kustomize;\
|
||||||
|
cd $(ROOT_DIR)/manifest/deploy/kustomize/overlays/${_ENV};\
|
||||||
|
kustomize build > $(ROOT_DIR)/temp/kustomize.yaml;\
|
||||||
|
kubectl apply -f $(ROOT_DIR)/temp/kustomize.yaml; \
|
||||||
|
if [ $(DEPLOY_NAME) != "" ]; then \
|
||||||
|
kubectl patch -n $(NAMESPACE) deployment/$(DEPLOY_NAME) -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"$(shell date +%s)\"}}}}}"; \
|
||||||
|
fi;
|
||||||
|
|
||||||
|
|
||||||
|
# Parsing protobuf files and generating go files.
|
||||||
|
.PHONY: pb
|
||||||
|
pb: cli.install
|
||||||
|
@gf gen pb
|
||||||
|
|
||||||
|
# Generate protobuf files for database tables.
|
||||||
|
.PHONY: pbentity
|
||||||
|
pbentity: cli.install
|
||||||
|
@gf gen pbentity
|
56
internal/cmd/cmd.go
Normal file
56
internal/cmd/cmd.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/net/ghttp"
|
||||||
|
"github.com/gogf/gf/v2/os/gcmd"
|
||||||
|
|
||||||
|
"novel/internal/controller/backend"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
Main = gcmd.Command{
|
||||||
|
Name: "main",
|
||||||
|
Usage: "main",
|
||||||
|
Brief: "start http server",
|
||||||
|
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
|
||||||
|
s := g.Server()
|
||||||
|
|
||||||
|
// s.Group("/backend", func(group *ghttp.RouterGroup) {
|
||||||
|
// group.Middleware(ghttp.MiddlewareHandlerResponse)
|
||||||
|
// group.Group("/writer", func(group2 *ghttp.RouterGroup) {
|
||||||
|
// group2.Bind(backend.New())
|
||||||
|
// })
|
||||||
|
// })
|
||||||
|
|
||||||
|
// 管理后台路由组
|
||||||
|
s.Group("/backend", func(group *ghttp.RouterGroup) {
|
||||||
|
// group.Middleware(
|
||||||
|
// service.Middleware().CORS,
|
||||||
|
// service.Middleware().Ctx,
|
||||||
|
// service.Middleware().ResponseHandler,
|
||||||
|
// )
|
||||||
|
// 不需要登录的路由组绑定
|
||||||
|
// group.Bind(
|
||||||
|
// controller.Admin.Create, // 管理员
|
||||||
|
// controller.Login, // 登录
|
||||||
|
// )
|
||||||
|
// 需要登录的路由组绑定
|
||||||
|
group.Group("/", func(group *ghttp.RouterGroup) {
|
||||||
|
// err := gfAdminToken.Middleware(ctx, group)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
group.Bind(
|
||||||
|
backend.Login, // 数据大屏相关
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
s.Run()
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
8
internal/consts/consts.go
Normal file
8
internal/consts/consts.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package consts
|
||||||
|
|
||||||
|
const (
|
||||||
|
PageSize = 10
|
||||||
|
PhoneVerifyType1 = 1 // 1-注册/登录
|
||||||
|
PhoneVerifyType2 = 2 // 2-找回密码
|
||||||
|
ContextKey = "ContextKey" // 上下文变量存储键名,前后端系统共享
|
||||||
|
)
|
58
internal/controller/backend/login.go
Normal file
58
internal/controller/backend/login.go
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
// Package backend -----------------------------
|
||||||
|
// @file : login.go
|
||||||
|
// @author : Allen zhang
|
||||||
|
// @contact : 364438619@qq.com
|
||||||
|
// @time : 2024/1/10 14:07
|
||||||
|
// -------------------------------------------
|
||||||
|
package backend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
|
|
||||||
|
"novel/api/backend"
|
||||||
|
"novel/internal/model"
|
||||||
|
"novel/internal/service"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 登录管理
|
||||||
|
var Login = cLogin{}
|
||||||
|
|
||||||
|
type cLogin struct{}
|
||||||
|
|
||||||
|
func New() *cLogin {
|
||||||
|
return &cLogin{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *cLogin) CreateOrLogin(ctx context.Context, req *backend.CreateOrLoginReq) (res *backend.CreateOrLoginRes, err error) {
|
||||||
|
input := model.WriterCreateOrLoginInput{}
|
||||||
|
err = gconv.Scan(req, &input)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
writer, err := service.Writer().CreateOrLogin(ctx, model.WriterCreateOrLoginInput{
|
||||||
|
Phone: req.Phone,
|
||||||
|
Code: req.Code,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &backend.CreateOrLoginRes{Id: writer.Id}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *cLogin) GetPhoneCode(ctx context.Context, req *backend.GetCodeReq) (res *backend.GetCodeRes, err error) {
|
||||||
|
input := model.GetCodeInput{}
|
||||||
|
err = gconv.Scan(req, &input)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
code, err := service.PhoneVerify().GenerateCode(ctx, req.Phone, req.CodeType)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &backend.GetCodeRes{Code: code.Code}, nil
|
||||||
|
}
|
0
internal/dao/.gitkeep
Normal file
0
internal/dao/.gitkeep
Normal file
27
internal/dao/category.go
Normal file
27
internal/dao/category.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// =================================================================================
|
||||||
|
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||||
|
// =================================================================================
|
||||||
|
|
||||||
|
package dao
|
||||||
|
|
||||||
|
import (
|
||||||
|
"novel/internal/dao/internal"
|
||||||
|
)
|
||||||
|
|
||||||
|
// internalCategoryDao is internal type for wrapping internal DAO implements.
|
||||||
|
type internalCategoryDao = *internal.CategoryDao
|
||||||
|
|
||||||
|
// categoryDao is the data access object for table nv_category.
|
||||||
|
// You can define custom methods on it to extend its functionality as you wish.
|
||||||
|
type categoryDao struct {
|
||||||
|
internalCategoryDao
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Category is globally public accessible object for table nv_category operations.
|
||||||
|
Category = categoryDao{
|
||||||
|
internal.NewCategoryDao(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Fill with you ideas below.
|
85
internal/dao/internal/category.go
Normal file
85
internal/dao/internal/category.go
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
// ==========================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// ==========================================================================
|
||||||
|
|
||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CategoryDao is the data access object for table nv_category.
|
||||||
|
type CategoryDao struct {
|
||||||
|
table string // table is the underlying table name of the DAO.
|
||||||
|
group string // group is the database configuration group name of current DAO.
|
||||||
|
columns CategoryColumns // columns contains all the column names of Table for convenient usage.
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryColumns defines and stores column names for table nv_category.
|
||||||
|
type CategoryColumns struct {
|
||||||
|
Id string //
|
||||||
|
Name string // 分类名称
|
||||||
|
ParentId string // 父级id
|
||||||
|
CateType string // 分类类型:1-主题,2-角色,3-情节
|
||||||
|
CreatedAt string //
|
||||||
|
UpdatedAt string //
|
||||||
|
DeletedAt string //
|
||||||
|
}
|
||||||
|
|
||||||
|
// categoryColumns holds the columns for table nv_category.
|
||||||
|
var categoryColumns = CategoryColumns{
|
||||||
|
Id: "id",
|
||||||
|
Name: "name",
|
||||||
|
ParentId: "parent_id",
|
||||||
|
CateType: "cate_type",
|
||||||
|
CreatedAt: "created_at",
|
||||||
|
UpdatedAt: "updated_at",
|
||||||
|
DeletedAt: "deleted_at",
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCategoryDao creates and returns a new DAO object for table data access.
|
||||||
|
func NewCategoryDao() *CategoryDao {
|
||||||
|
return &CategoryDao{
|
||||||
|
group: "default",
|
||||||
|
table: "nv_category",
|
||||||
|
columns: categoryColumns,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||||
|
func (dao *CategoryDao) DB() gdb.DB {
|
||||||
|
return g.DB(dao.group)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Table returns the table name of current dao.
|
||||||
|
func (dao *CategoryDao) Table() string {
|
||||||
|
return dao.table
|
||||||
|
}
|
||||||
|
|
||||||
|
// Columns returns all column names of current dao.
|
||||||
|
func (dao *CategoryDao) Columns() CategoryColumns {
|
||||||
|
return dao.columns
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group returns the configuration group name of database of current dao.
|
||||||
|
func (dao *CategoryDao) Group() string {
|
||||||
|
return dao.group
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||||
|
func (dao *CategoryDao) Ctx(ctx context.Context) *gdb.Model {
|
||||||
|
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transaction wraps the transaction logic using function f.
|
||||||
|
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
|
||||||
|
// It commits the transaction and returns nil if function f returns nil.
|
||||||
|
//
|
||||||
|
// Note that, you should not Commit or Rollback the transaction in function f
|
||||||
|
// as it is automatically handled by this function.
|
||||||
|
func (dao *CategoryDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
|
||||||
|
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||||
|
}
|
83
internal/dao/internal/phone_verify.go
Normal file
83
internal/dao/internal/phone_verify.go
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
// ==========================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// ==========================================================================
|
||||||
|
|
||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PhoneVerifyDao is the data access object for table nv_phone_verify.
|
||||||
|
type PhoneVerifyDao struct {
|
||||||
|
table string // table is the underlying table name of the DAO.
|
||||||
|
group string // group is the database configuration group name of current DAO.
|
||||||
|
columns PhoneVerifyColumns // columns contains all the column names of Table for convenient usage.
|
||||||
|
}
|
||||||
|
|
||||||
|
// PhoneVerifyColumns defines and stores column names for table nv_phone_verify.
|
||||||
|
type PhoneVerifyColumns struct {
|
||||||
|
Id string //
|
||||||
|
Phone string // 手机号
|
||||||
|
Code string // 验证码
|
||||||
|
Type string // 类型:1-注册/登录,2-找回密码
|
||||||
|
CreatedAt string //
|
||||||
|
UpdatedAt string //
|
||||||
|
}
|
||||||
|
|
||||||
|
// phoneVerifyColumns holds the columns for table nv_phone_verify.
|
||||||
|
var phoneVerifyColumns = PhoneVerifyColumns{
|
||||||
|
Id: "id",
|
||||||
|
Phone: "phone",
|
||||||
|
Code: "code",
|
||||||
|
Type: "type",
|
||||||
|
CreatedAt: "created_at",
|
||||||
|
UpdatedAt: "updated_at",
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewPhoneVerifyDao creates and returns a new DAO object for table data access.
|
||||||
|
func NewPhoneVerifyDao() *PhoneVerifyDao {
|
||||||
|
return &PhoneVerifyDao{
|
||||||
|
group: "default",
|
||||||
|
table: "nv_phone_verify",
|
||||||
|
columns: phoneVerifyColumns,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||||
|
func (dao *PhoneVerifyDao) DB() gdb.DB {
|
||||||
|
return g.DB(dao.group)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Table returns the table name of current dao.
|
||||||
|
func (dao *PhoneVerifyDao) Table() string {
|
||||||
|
return dao.table
|
||||||
|
}
|
||||||
|
|
||||||
|
// Columns returns all column names of current dao.
|
||||||
|
func (dao *PhoneVerifyDao) Columns() PhoneVerifyColumns {
|
||||||
|
return dao.columns
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group returns the configuration group name of database of current dao.
|
||||||
|
func (dao *PhoneVerifyDao) Group() string {
|
||||||
|
return dao.group
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||||
|
func (dao *PhoneVerifyDao) Ctx(ctx context.Context) *gdb.Model {
|
||||||
|
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transaction wraps the transaction logic using function f.
|
||||||
|
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
|
||||||
|
// It commits the transaction and returns nil if function f returns nil.
|
||||||
|
//
|
||||||
|
// Note that, you should not Commit or Rollback the transaction in function f
|
||||||
|
// as it is automatically handled by this function.
|
||||||
|
func (dao *PhoneVerifyDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
|
||||||
|
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||||
|
}
|
87
internal/dao/internal/read_log.go
Normal file
87
internal/dao/internal/read_log.go
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
// ==========================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// ==========================================================================
|
||||||
|
|
||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ReadLogDao is the data access object for table nv_read_log.
|
||||||
|
type ReadLogDao struct {
|
||||||
|
table string // table is the underlying table name of the DAO.
|
||||||
|
group string // group is the database configuration group name of current DAO.
|
||||||
|
columns ReadLogColumns // columns contains all the column names of Table for convenient usage.
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadLogColumns defines and stores column names for table nv_read_log.
|
||||||
|
type ReadLogColumns struct {
|
||||||
|
Id string //
|
||||||
|
ShortStoryId string //
|
||||||
|
OperateType string // 操作类型:1-阅读,2-加入书架
|
||||||
|
OperateTime string // 操作时间
|
||||||
|
ReadDuration string // 阅读时长,秒为单位
|
||||||
|
CreatedAt string //
|
||||||
|
UpdatedAt string //
|
||||||
|
DeletedAt string //
|
||||||
|
}
|
||||||
|
|
||||||
|
// readLogColumns holds the columns for table nv_read_log.
|
||||||
|
var readLogColumns = ReadLogColumns{
|
||||||
|
Id: "id",
|
||||||
|
ShortStoryId: "short_story_id",
|
||||||
|
OperateType: "operate_type",
|
||||||
|
OperateTime: "operate_time",
|
||||||
|
ReadDuration: "read_duration",
|
||||||
|
CreatedAt: "created_at",
|
||||||
|
UpdatedAt: "updated_at",
|
||||||
|
DeletedAt: "deleted_at",
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewReadLogDao creates and returns a new DAO object for table data access.
|
||||||
|
func NewReadLogDao() *ReadLogDao {
|
||||||
|
return &ReadLogDao{
|
||||||
|
group: "default",
|
||||||
|
table: "nv_read_log",
|
||||||
|
columns: readLogColumns,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||||
|
func (dao *ReadLogDao) DB() gdb.DB {
|
||||||
|
return g.DB(dao.group)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Table returns the table name of current dao.
|
||||||
|
func (dao *ReadLogDao) Table() string {
|
||||||
|
return dao.table
|
||||||
|
}
|
||||||
|
|
||||||
|
// Columns returns all column names of current dao.
|
||||||
|
func (dao *ReadLogDao) Columns() ReadLogColumns {
|
||||||
|
return dao.columns
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group returns the configuration group name of database of current dao.
|
||||||
|
func (dao *ReadLogDao) Group() string {
|
||||||
|
return dao.group
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||||
|
func (dao *ReadLogDao) Ctx(ctx context.Context) *gdb.Model {
|
||||||
|
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transaction wraps the transaction logic using function f.
|
||||||
|
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
|
||||||
|
// It commits the transaction and returns nil if function f returns nil.
|
||||||
|
//
|
||||||
|
// Note that, you should not Commit or Rollback the transaction in function f
|
||||||
|
// as it is automatically handled by this function.
|
||||||
|
func (dao *ReadLogDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
|
||||||
|
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||||
|
}
|
95
internal/dao/internal/short_story.go
Normal file
95
internal/dao/internal/short_story.go
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
// ==========================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// ==========================================================================
|
||||||
|
|
||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ShortStoryDao is the data access object for table nv_short_story.
|
||||||
|
type ShortStoryDao struct {
|
||||||
|
table string // table is the underlying table name of the DAO.
|
||||||
|
group string // group is the database configuration group name of current DAO.
|
||||||
|
columns ShortStoryColumns // columns contains all the column names of Table for convenient usage.
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShortStoryColumns defines and stores column names for table nv_short_story.
|
||||||
|
type ShortStoryColumns struct {
|
||||||
|
Id string //
|
||||||
|
Title string // 标题
|
||||||
|
Content string // 内容
|
||||||
|
RecommendCoverImg string // 推荐封面
|
||||||
|
BookCoverImg string // 书籍封面
|
||||||
|
RecommendTitle string // 推荐标题
|
||||||
|
CatId string // 分类,多个用逗号隔开
|
||||||
|
PreReadPercent string // 试读百分比
|
||||||
|
IsAudit string // 是否审核:1-已审核,2-未审核,3-草稿
|
||||||
|
CreatedAt string //
|
||||||
|
UpdatedAt string //
|
||||||
|
DeletedAt string //
|
||||||
|
}
|
||||||
|
|
||||||
|
// shortStoryColumns holds the columns for table nv_short_story.
|
||||||
|
var shortStoryColumns = ShortStoryColumns{
|
||||||
|
Id: "id",
|
||||||
|
Title: "title",
|
||||||
|
Content: "content",
|
||||||
|
RecommendCoverImg: "recommend_cover_img",
|
||||||
|
BookCoverImg: "book_cover_img",
|
||||||
|
RecommendTitle: "recommend_title",
|
||||||
|
CatId: "cat_id",
|
||||||
|
PreReadPercent: "pre_read_percent",
|
||||||
|
IsAudit: "is_audit",
|
||||||
|
CreatedAt: "created_at",
|
||||||
|
UpdatedAt: "updated_at",
|
||||||
|
DeletedAt: "deleted_at",
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewShortStoryDao creates and returns a new DAO object for table data access.
|
||||||
|
func NewShortStoryDao() *ShortStoryDao {
|
||||||
|
return &ShortStoryDao{
|
||||||
|
group: "default",
|
||||||
|
table: "nv_short_story",
|
||||||
|
columns: shortStoryColumns,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||||
|
func (dao *ShortStoryDao) DB() gdb.DB {
|
||||||
|
return g.DB(dao.group)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Table returns the table name of current dao.
|
||||||
|
func (dao *ShortStoryDao) Table() string {
|
||||||
|
return dao.table
|
||||||
|
}
|
||||||
|
|
||||||
|
// Columns returns all column names of current dao.
|
||||||
|
func (dao *ShortStoryDao) Columns() ShortStoryColumns {
|
||||||
|
return dao.columns
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group returns the configuration group name of database of current dao.
|
||||||
|
func (dao *ShortStoryDao) Group() string {
|
||||||
|
return dao.group
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||||
|
func (dao *ShortStoryDao) Ctx(ctx context.Context) *gdb.Model {
|
||||||
|
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transaction wraps the transaction logic using function f.
|
||||||
|
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
|
||||||
|
// It commits the transaction and returns nil if function f returns nil.
|
||||||
|
//
|
||||||
|
// Note that, you should not Commit or Rollback the transaction in function f
|
||||||
|
// as it is automatically handled by this function.
|
||||||
|
func (dao *ShortStoryDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
|
||||||
|
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||||
|
}
|
85
internal/dao/internal/user.go
Normal file
85
internal/dao/internal/user.go
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
// ==========================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// ==========================================================================
|
||||||
|
|
||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserDao is the data access object for table gf_user.
|
||||||
|
type UserDao struct {
|
||||||
|
table string // table is the underlying table name of the DAO.
|
||||||
|
group string // group is the database configuration group name of current DAO.
|
||||||
|
columns UserColumns // columns contains all the column names of Table for convenient usage.
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserColumns defines and stores column names for table gf_user.
|
||||||
|
type UserColumns struct {
|
||||||
|
Id string //
|
||||||
|
Name string // 用户名
|
||||||
|
Phone string // 手机号
|
||||||
|
Age string // 年龄
|
||||||
|
CreatedAt string //
|
||||||
|
UpdatedAt string //
|
||||||
|
DeletedAt string //
|
||||||
|
}
|
||||||
|
|
||||||
|
// userColumns holds the columns for table gf_user.
|
||||||
|
var userColumns = UserColumns{
|
||||||
|
Id: "id",
|
||||||
|
Name: "name",
|
||||||
|
Phone: "phone",
|
||||||
|
Age: "age",
|
||||||
|
CreatedAt: "created_at",
|
||||||
|
UpdatedAt: "updated_at",
|
||||||
|
DeletedAt: "deleted_at",
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewUserDao creates and returns a new DAO object for table data access.
|
||||||
|
func NewUserDao() *UserDao {
|
||||||
|
return &UserDao{
|
||||||
|
group: "default",
|
||||||
|
table: "gf_user",
|
||||||
|
columns: userColumns,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||||
|
func (dao *UserDao) DB() gdb.DB {
|
||||||
|
return g.DB(dao.group)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Table returns the table name of current dao.
|
||||||
|
func (dao *UserDao) Table() string {
|
||||||
|
return dao.table
|
||||||
|
}
|
||||||
|
|
||||||
|
// Columns returns all column names of current dao.
|
||||||
|
func (dao *UserDao) Columns() UserColumns {
|
||||||
|
return dao.columns
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group returns the configuration group name of database of current dao.
|
||||||
|
func (dao *UserDao) Group() string {
|
||||||
|
return dao.group
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||||
|
func (dao *UserDao) Ctx(ctx context.Context) *gdb.Model {
|
||||||
|
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transaction wraps the transaction logic using function f.
|
||||||
|
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
|
||||||
|
// It commits the transaction and returns nil if function f returns nil.
|
||||||
|
//
|
||||||
|
// Note that, you should not Commit or Rollback the transaction in function f
|
||||||
|
// as it is automatically handled by this function.
|
||||||
|
func (dao *UserDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
|
||||||
|
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||||
|
}
|
95
internal/dao/internal/writer.go
Normal file
95
internal/dao/internal/writer.go
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
// ==========================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// ==========================================================================
|
||||||
|
|
||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
)
|
||||||
|
|
||||||
|
// WriterDao is the data access object for table nv_writer.
|
||||||
|
type WriterDao struct {
|
||||||
|
table string // table is the underlying table name of the DAO.
|
||||||
|
group string // group is the database configuration group name of current DAO.
|
||||||
|
columns WriterColumns // columns contains all the column names of Table for convenient usage.
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriterColumns defines and stores column names for table nv_writer.
|
||||||
|
type WriterColumns struct {
|
||||||
|
Id string //
|
||||||
|
PenName string // 笔名
|
||||||
|
Phone string // 手机号
|
||||||
|
Password string // 密码
|
||||||
|
Introduction string // 简介
|
||||||
|
Avatar string // 头像
|
||||||
|
Qq string //
|
||||||
|
RealName string // 真名
|
||||||
|
IdNo string // 身份证号
|
||||||
|
CreatedAt string //
|
||||||
|
UpdatedAt string //
|
||||||
|
DeletedAt string //
|
||||||
|
}
|
||||||
|
|
||||||
|
// writerColumns holds the columns for table nv_writer.
|
||||||
|
var writerColumns = WriterColumns{
|
||||||
|
Id: "id",
|
||||||
|
PenName: "pen_name",
|
||||||
|
Phone: "phone",
|
||||||
|
Password: "password",
|
||||||
|
Introduction: "introduction",
|
||||||
|
Avatar: "avatar",
|
||||||
|
Qq: "qq",
|
||||||
|
RealName: "real_name",
|
||||||
|
IdNo: "id_no",
|
||||||
|
CreatedAt: "created_at",
|
||||||
|
UpdatedAt: "updated_at",
|
||||||
|
DeletedAt: "deleted_at",
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewWriterDao creates and returns a new DAO object for table data access.
|
||||||
|
func NewWriterDao() *WriterDao {
|
||||||
|
return &WriterDao{
|
||||||
|
group: "default",
|
||||||
|
table: "nv_writer",
|
||||||
|
columns: writerColumns,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||||
|
func (dao *WriterDao) DB() gdb.DB {
|
||||||
|
return g.DB(dao.group)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Table returns the table name of current dao.
|
||||||
|
func (dao *WriterDao) Table() string {
|
||||||
|
return dao.table
|
||||||
|
}
|
||||||
|
|
||||||
|
// Columns returns all column names of current dao.
|
||||||
|
func (dao *WriterDao) Columns() WriterColumns {
|
||||||
|
return dao.columns
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group returns the configuration group name of database of current dao.
|
||||||
|
func (dao *WriterDao) Group() string {
|
||||||
|
return dao.group
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||||
|
func (dao *WriterDao) Ctx(ctx context.Context) *gdb.Model {
|
||||||
|
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transaction wraps the transaction logic using function f.
|
||||||
|
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
|
||||||
|
// It commits the transaction and returns nil if function f returns nil.
|
||||||
|
//
|
||||||
|
// Note that, you should not Commit or Rollback the transaction in function f
|
||||||
|
// as it is automatically handled by this function.
|
||||||
|
func (dao *WriterDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
|
||||||
|
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||||
|
}
|
27
internal/dao/phone_verify.go
Normal file
27
internal/dao/phone_verify.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// =================================================================================
|
||||||
|
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||||
|
// =================================================================================
|
||||||
|
|
||||||
|
package dao
|
||||||
|
|
||||||
|
import (
|
||||||
|
"novel/internal/dao/internal"
|
||||||
|
)
|
||||||
|
|
||||||
|
// internalPhoneVerifyDao is internal type for wrapping internal DAO implements.
|
||||||
|
type internalPhoneVerifyDao = *internal.PhoneVerifyDao
|
||||||
|
|
||||||
|
// phoneVerifyDao is the data access object for table nv_phone_verify.
|
||||||
|
// You can define custom methods on it to extend its functionality as you wish.
|
||||||
|
type phoneVerifyDao struct {
|
||||||
|
internalPhoneVerifyDao
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// PhoneVerify is globally public accessible object for table nv_phone_verify operations.
|
||||||
|
PhoneVerify = phoneVerifyDao{
|
||||||
|
internal.NewPhoneVerifyDao(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Fill with you ideas below.
|
27
internal/dao/read_log.go
Normal file
27
internal/dao/read_log.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// =================================================================================
|
||||||
|
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||||
|
// =================================================================================
|
||||||
|
|
||||||
|
package dao
|
||||||
|
|
||||||
|
import (
|
||||||
|
"novel/internal/dao/internal"
|
||||||
|
)
|
||||||
|
|
||||||
|
// internalReadLogDao is internal type for wrapping internal DAO implements.
|
||||||
|
type internalReadLogDao = *internal.ReadLogDao
|
||||||
|
|
||||||
|
// readLogDao is the data access object for table nv_read_log.
|
||||||
|
// You can define custom methods on it to extend its functionality as you wish.
|
||||||
|
type readLogDao struct {
|
||||||
|
internalReadLogDao
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ReadLog is globally public accessible object for table nv_read_log operations.
|
||||||
|
ReadLog = readLogDao{
|
||||||
|
internal.NewReadLogDao(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Fill with you ideas below.
|
27
internal/dao/short_story.go
Normal file
27
internal/dao/short_story.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// =================================================================================
|
||||||
|
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||||
|
// =================================================================================
|
||||||
|
|
||||||
|
package dao
|
||||||
|
|
||||||
|
import (
|
||||||
|
"novel/internal/dao/internal"
|
||||||
|
)
|
||||||
|
|
||||||
|
// internalShortStoryDao is internal type for wrapping internal DAO implements.
|
||||||
|
type internalShortStoryDao = *internal.ShortStoryDao
|
||||||
|
|
||||||
|
// shortStoryDao is the data access object for table nv_short_story.
|
||||||
|
// You can define custom methods on it to extend its functionality as you wish.
|
||||||
|
type shortStoryDao struct {
|
||||||
|
internalShortStoryDao
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ShortStory is globally public accessible object for table nv_short_story operations.
|
||||||
|
ShortStory = shortStoryDao{
|
||||||
|
internal.NewShortStoryDao(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Fill with you ideas below.
|
27
internal/dao/writer.go
Normal file
27
internal/dao/writer.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// =================================================================================
|
||||||
|
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||||
|
// =================================================================================
|
||||||
|
|
||||||
|
package dao
|
||||||
|
|
||||||
|
import (
|
||||||
|
"novel/internal/dao/internal"
|
||||||
|
)
|
||||||
|
|
||||||
|
// internalWriterDao is internal type for wrapping internal DAO implements.
|
||||||
|
type internalWriterDao = *internal.WriterDao
|
||||||
|
|
||||||
|
// writerDao is the data access object for table nv_writer.
|
||||||
|
// You can define custom methods on it to extend its functionality as you wish.
|
||||||
|
type writerDao struct {
|
||||||
|
internalWriterDao
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Writer is globally public accessible object for table nv_writer operations.
|
||||||
|
Writer = writerDao{
|
||||||
|
internal.NewWriterDao(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Fill with you ideas below.
|
0
internal/logic/.gitkeep
Normal file
0
internal/logic/.gitkeep
Normal file
49
internal/logic/bizctx/bizctx.go
Normal file
49
internal/logic/bizctx/bizctx.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package bizctx
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/net/ghttp"
|
||||||
|
|
||||||
|
"novel/internal/consts"
|
||||||
|
"novel/internal/model"
|
||||||
|
"novel/internal/service"
|
||||||
|
)
|
||||||
|
|
||||||
|
type sBizCtx struct{}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
service.RegisterBizCtx(New())
|
||||||
|
}
|
||||||
|
|
||||||
|
func New() *sBizCtx {
|
||||||
|
return &sBizCtx{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init 初始化上下文对象指针到上下文对象中,以便后续的请求流程中可以修改。
|
||||||
|
func (s *sBizCtx) Init(r *ghttp.Request, customCtx *model.Context) {
|
||||||
|
r.SetCtxVar(consts.ContextKey, customCtx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get 获得上下文变量,如果没有设置,那么返回nil
|
||||||
|
func (s *sBizCtx) Get(ctx context.Context) *model.Context {
|
||||||
|
value := ctx.Value(consts.ContextKey)
|
||||||
|
if value == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if localCtx, ok := value.(*model.Context); ok {
|
||||||
|
return localCtx
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUser 将上下文信息设置到上下文请求中,注意是完整覆盖
|
||||||
|
func (s *sBizCtx) SetUser(ctx context.Context, ctxUser *model.ContextUser) {
|
||||||
|
s.Get(ctx).User = ctxUser
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetData 将上下文信息设置到上下文请求中,注意是完整覆盖
|
||||||
|
func (s *sBizCtx) SetData(ctx context.Context, data g.Map) {
|
||||||
|
s.Get(ctx).Data = data
|
||||||
|
}
|
12
internal/logic/logic.go
Normal file
12
internal/logic/logic.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// ==========================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// ==========================================================================
|
||||||
|
|
||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "novel/internal/logic/bizctx"
|
||||||
|
_ "novel/internal/logic/phone_verify"
|
||||||
|
_ "novel/internal/logic/session"
|
||||||
|
_ "novel/internal/logic/writer"
|
||||||
|
)
|
59
internal/logic/phone_verify/phone_verify.go
Normal file
59
internal/logic/phone_verify/phone_verify.go
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
// Package phone_verify -----------------------------
|
||||||
|
// @file : phone_verify.go
|
||||||
|
// @author : Allen zhang
|
||||||
|
// @contact : 364438619@qq.com
|
||||||
|
// @time : 2024/1/11 15:17
|
||||||
|
// -------------------------------------------
|
||||||
|
package phone_verify
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
|
"github.com/gogf/gf/v2/util/grand"
|
||||||
|
|
||||||
|
"novel/internal/dao"
|
||||||
|
"novel/internal/model"
|
||||||
|
"novel/internal/model/do"
|
||||||
|
"novel/internal/service"
|
||||||
|
)
|
||||||
|
|
||||||
|
type sPhoneVerify struct{}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
service.RegisterPhoneVerify(New())
|
||||||
|
}
|
||||||
|
func New() *sPhoneVerify {
|
||||||
|
return &sPhoneVerify{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *sPhoneVerify) GenerateCode(ctx context.Context, phone string, codeType int) (out *model.GetCodeOutput, err error) {
|
||||||
|
// once within a minute
|
||||||
|
time1 := time.Now().Add(-1 * time.Minute)
|
||||||
|
dateTime := time1.Format("2006-01-02 15:04:05")
|
||||||
|
// record := entity.PhoneVerify{}
|
||||||
|
count, recordErr := dao.PhoneVerify.Ctx(ctx).Where(do.PhoneVerify{
|
||||||
|
Phone: phone,
|
||||||
|
Type: codeType,
|
||||||
|
}).Where("created_at >=", dateTime).Count()
|
||||||
|
// fmt.Println(dateTime, count)
|
||||||
|
if recordErr != nil {
|
||||||
|
return nil, recordErr
|
||||||
|
}
|
||||||
|
if count > 0 {
|
||||||
|
return nil, gerror.New(`一分钟内只能发送一次验证码`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// generate new code
|
||||||
|
code := grand.N(100000, 999999)
|
||||||
|
_, insertErr := dao.PhoneVerify.Ctx(ctx).Data(do.PhoneVerify{
|
||||||
|
Phone: phone,
|
||||||
|
Code: code,
|
||||||
|
Type: codeType,
|
||||||
|
}).Insert()
|
||||||
|
if insertErr != nil {
|
||||||
|
return nil, gerror.New(`内部错误`)
|
||||||
|
}
|
||||||
|
return &model.GetCodeOutput{Code: code}, nil
|
||||||
|
}
|
43
internal/logic/session/session.go
Normal file
43
internal/logic/session/session.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
// // Package session -----------------------------
|
||||||
|
// // @file : session.go
|
||||||
|
// // @author : Allen zhang
|
||||||
|
// // @contact : 364438619@qq.com
|
||||||
|
// // @time : 2024/1/10 15:51
|
||||||
|
// // -------------------------------------------
|
||||||
|
package session
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"novel/internal/model/entity"
|
||||||
|
"novel/internal/service"
|
||||||
|
)
|
||||||
|
|
||||||
|
// type (
|
||||||
|
// sSession struct{}
|
||||||
|
// )
|
||||||
|
|
||||||
|
type sSession struct{}
|
||||||
|
|
||||||
|
const (
|
||||||
|
sessionKeyWriter = "SessionKeyWriter" // 用户信息存放在Session中的Key
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
service.RegisterSession(New())
|
||||||
|
}
|
||||||
|
func New() *sSession {
|
||||||
|
return &sSession{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *sSession) SetWriter(ctx context.Context, writer *entity.Writer) error {
|
||||||
|
// fmt.Println(writer)
|
||||||
|
// fmt.Println(ctx)
|
||||||
|
// fmt.Println(sessionKeyWriter)
|
||||||
|
fmt.Printf("writer: %p \n", &writer)
|
||||||
|
fmt.Printf("ctx: %p \n", &ctx)
|
||||||
|
// fmt.Printf("sessionKeyWriter: %p \n", &sessionKeyWriter)
|
||||||
|
fmt.Println(*writer, &writer, writer)
|
||||||
|
return service.BizCtx().Get(ctx).Session.Set(sessionKeyWriter, writer)
|
||||||
|
}
|
114
internal/logic/writer/writer.go
Normal file
114
internal/logic/writer/writer.go
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
// Package backend -----------------------------
|
||||||
|
// @file : writer.go
|
||||||
|
// @author : Allen zhang
|
||||||
|
// @contact : 364438619@qq.com
|
||||||
|
// @time : 2024/1/10 14:49
|
||||||
|
// -------------------------------------------
|
||||||
|
package writer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
|
|
||||||
|
"novel/internal/dao"
|
||||||
|
"novel/internal/model"
|
||||||
|
"novel/internal/model/do"
|
||||||
|
"novel/internal/model/entity"
|
||||||
|
"novel/internal/service"
|
||||||
|
)
|
||||||
|
|
||||||
|
// type sWriter struct{}
|
||||||
|
type (
|
||||||
|
sWriter struct{}
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
service.RegisterWriter(New())
|
||||||
|
}
|
||||||
|
func New() *sWriter {
|
||||||
|
return &sWriter{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *sWriter) CreateOrLogin(ctx context.Context, in model.WriterCreateOrLoginInput) (out *model.WriterCreateOrLoginOutput, err error) {
|
||||||
|
// writerInfo := entity.Writer{}
|
||||||
|
var writerInfo entity.Writer
|
||||||
|
// writerInfo := new(entity.Writer)
|
||||||
|
|
||||||
|
// check code
|
||||||
|
codeCheck, codeErr := s.CheckPhoneVerifyCode(ctx, in.Phone, in.Code, 1)
|
||||||
|
if codeErr != nil {
|
||||||
|
return out, codeErr
|
||||||
|
}
|
||||||
|
if !codeCheck {
|
||||||
|
return out, gerror.New(`验证码错误`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// check account
|
||||||
|
writerCheck, writerErr := s.CheckWriter(ctx, in.Phone)
|
||||||
|
if writerErr != nil {
|
||||||
|
return out, codeErr
|
||||||
|
}
|
||||||
|
if !writerCheck {
|
||||||
|
// create new account
|
||||||
|
_, insertErr := dao.Writer.Ctx(ctx).Data(do.Writer{
|
||||||
|
Phone: in.Phone,
|
||||||
|
}).Insert()
|
||||||
|
if insertErr != nil {
|
||||||
|
return out, gerror.New(`内部错误`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
infoErr := dao.Writer.Ctx(ctx).Where(do.Writer{
|
||||||
|
Phone: in.Phone,
|
||||||
|
}).Scan(&writerInfo)
|
||||||
|
if infoErr != nil {
|
||||||
|
return out, infoErr
|
||||||
|
// return out, gerror.New(`查找用户错误`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// if writerInfo == nil {
|
||||||
|
// return gerror.New(`Passport or Password not correct`)
|
||||||
|
// }
|
||||||
|
fmt.Println("-------------------------")
|
||||||
|
fmt.Println(writerInfo)
|
||||||
|
|
||||||
|
// err1 := service.Session().SetWriter(ctx, &writerInfo)
|
||||||
|
// if err1 != nil {
|
||||||
|
// return out, err1
|
||||||
|
// }
|
||||||
|
|
||||||
|
// service.BizCtx().SetUser(ctx, &model.ContextUser{
|
||||||
|
// Id: writerInfo.Id,
|
||||||
|
// })
|
||||||
|
|
||||||
|
return &model.WriterCreateOrLoginOutput{Id: writerInfo.Id}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *sWriter) CheckPhoneVerifyCode(ctx context.Context, phone string, code, codeType int) (bool, error) {
|
||||||
|
|
||||||
|
time1 := time.Now().Add(-1 * time.Minute)
|
||||||
|
dateTime := time1.Format("2006-01-02 15:04:05")
|
||||||
|
|
||||||
|
count, err := dao.PhoneVerify.Ctx(ctx).Where(do.PhoneVerify{
|
||||||
|
Phone: phone,
|
||||||
|
Code: code,
|
||||||
|
Type: codeType,
|
||||||
|
}).Where("created_at >=", dateTime).Count()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return count > 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *sWriter) CheckWriter(ctx context.Context, phone string) (bool, error) {
|
||||||
|
count, err := dao.Writer.Ctx(ctx).Where(do.Writer{
|
||||||
|
Phone: phone,
|
||||||
|
}).Count()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return count > 0, nil
|
||||||
|
}
|
0
internal/model/.gitkeep
Normal file
0
internal/model/.gitkeep
Normal file
22
internal/model/context.go
Normal file
22
internal/model/context.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/net/ghttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Context 请求上下文结构
|
||||||
|
type Context struct {
|
||||||
|
Session *ghttp.Session // 当前Session管理对象
|
||||||
|
User *ContextUser // 上下文用户信息
|
||||||
|
Data g.Map // 自定KV变量,业务模块根据需要设置,不固定
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContextUser 请求上下文中的用户信息
|
||||||
|
type ContextUser struct {
|
||||||
|
Id uint // 用户ID
|
||||||
|
// Name string // 用户账号
|
||||||
|
// //Nickname string // 用户名称
|
||||||
|
// //Avatar string // 用户头像
|
||||||
|
// IsAdmin uint8 // 是否是管理员
|
||||||
|
}
|
0
internal/model/do/.gitkeep
Normal file
0
internal/model/do/.gitkeep
Normal file
22
internal/model/do/category.go
Normal file
22
internal/model/do/category.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// =================================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// =================================================================================
|
||||||
|
|
||||||
|
package do
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Category is the golang structure of table nv_category for DAO operations like Where/Data.
|
||||||
|
type Category struct {
|
||||||
|
g.Meta `orm:"table:nv_category, do:true"`
|
||||||
|
Id interface{} //
|
||||||
|
Name interface{} // 分类名称
|
||||||
|
ParentId interface{} // 父级id
|
||||||
|
CateType interface{} // 分类类型:1-主题,2-角色,3-情节
|
||||||
|
CreatedAt *gtime.Time //
|
||||||
|
UpdatedAt *gtime.Time //
|
||||||
|
DeletedAt *gtime.Time //
|
||||||
|
}
|
21
internal/model/do/phone_verify.go
Normal file
21
internal/model/do/phone_verify.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// =================================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// =================================================================================
|
||||||
|
|
||||||
|
package do
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PhoneVerify is the golang structure of table nv_phone_verify for DAO operations like Where/Data.
|
||||||
|
type PhoneVerify struct {
|
||||||
|
g.Meta `orm:"table:nv_phone_verify, do:true"`
|
||||||
|
Id interface{} //
|
||||||
|
Phone interface{} // 手机号
|
||||||
|
Code interface{} // 验证码
|
||||||
|
Type interface{} // 类型:1-注册/登录,2-找回密码
|
||||||
|
CreatedAt *gtime.Time //
|
||||||
|
UpdatedAt *gtime.Time //
|
||||||
|
}
|
23
internal/model/do/read_log.go
Normal file
23
internal/model/do/read_log.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// =================================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// =================================================================================
|
||||||
|
|
||||||
|
package do
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ReadLog is the golang structure of table nv_read_log for DAO operations like Where/Data.
|
||||||
|
type ReadLog struct {
|
||||||
|
g.Meta `orm:"table:nv_read_log, do:true"`
|
||||||
|
Id interface{} //
|
||||||
|
ShortStoryId interface{} //
|
||||||
|
OperateType interface{} // 操作类型:1-阅读,2-加入书架
|
||||||
|
OperateTime *gtime.Time // 操作时间
|
||||||
|
ReadDuration interface{} // 阅读时长,秒为单位
|
||||||
|
CreatedAt *gtime.Time //
|
||||||
|
UpdatedAt *gtime.Time //
|
||||||
|
DeletedAt *gtime.Time //
|
||||||
|
}
|
27
internal/model/do/short_story.go
Normal file
27
internal/model/do/short_story.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// =================================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// =================================================================================
|
||||||
|
|
||||||
|
package do
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ShortStory is the golang structure of table nv_short_story for DAO operations like Where/Data.
|
||||||
|
type ShortStory struct {
|
||||||
|
g.Meta `orm:"table:nv_short_story, do:true"`
|
||||||
|
Id interface{} //
|
||||||
|
Title interface{} // 标题
|
||||||
|
Content interface{} // 内容
|
||||||
|
RecommendCoverImg interface{} // 推荐封面
|
||||||
|
BookCoverImg interface{} // 书籍封面
|
||||||
|
RecommendTitle interface{} // 推荐标题
|
||||||
|
CatId interface{} // 分类,多个用逗号隔开
|
||||||
|
PreReadPercent interface{} // 试读百分比
|
||||||
|
IsAudit interface{} // 是否审核:1-已审核,2-未审核,3-草稿
|
||||||
|
CreatedAt *gtime.Time //
|
||||||
|
UpdatedAt *gtime.Time //
|
||||||
|
DeletedAt *gtime.Time //
|
||||||
|
}
|
27
internal/model/do/writer.go
Normal file
27
internal/model/do/writer.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// =================================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// =================================================================================
|
||||||
|
|
||||||
|
package do
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Writer is the golang structure of table nv_writer for DAO operations like Where/Data.
|
||||||
|
type Writer struct {
|
||||||
|
g.Meta `orm:"table:nv_writer, do:true"`
|
||||||
|
Id interface{} //
|
||||||
|
PenName interface{} // 笔名
|
||||||
|
Phone interface{} // 手机号
|
||||||
|
Password interface{} // 密码
|
||||||
|
Introduction interface{} // 简介
|
||||||
|
Avatar interface{} // 头像
|
||||||
|
Qq interface{} //
|
||||||
|
RealName interface{} // 真名
|
||||||
|
IdNo interface{} // 身份证号
|
||||||
|
CreatedAt *gtime.Time //
|
||||||
|
UpdatedAt *gtime.Time //
|
||||||
|
DeletedAt *gtime.Time //
|
||||||
|
}
|
0
internal/model/entity/.gitkeep
Normal file
0
internal/model/entity/.gitkeep
Normal file
20
internal/model/entity/category.go
Normal file
20
internal/model/entity/category.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// =================================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// =================================================================================
|
||||||
|
|
||||||
|
package entity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Category is the golang structure for table category.
|
||||||
|
type Category struct {
|
||||||
|
Id uint `json:"id" description:""`
|
||||||
|
Name string `json:"name" description:"分类名称"`
|
||||||
|
ParentId uint `json:"parentId" description:"父级id"`
|
||||||
|
CateType uint `json:"cateType" description:"分类类型:1-主题,2-角色,3-情节"`
|
||||||
|
CreatedAt *gtime.Time `json:"createdAt" description:""`
|
||||||
|
UpdatedAt *gtime.Time `json:"updatedAt" description:""`
|
||||||
|
DeletedAt *gtime.Time `json:"deletedAt" description:""`
|
||||||
|
}
|
19
internal/model/entity/phone_verify.go
Normal file
19
internal/model/entity/phone_verify.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// =================================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// =================================================================================
|
||||||
|
|
||||||
|
package entity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PhoneVerify is the golang structure for table phone_verify.
|
||||||
|
type PhoneVerify struct {
|
||||||
|
Id uint64 `json:"id" description:""`
|
||||||
|
Phone string `json:"phone" description:"手机号"`
|
||||||
|
Code string `json:"code" description:"验证码"`
|
||||||
|
Type uint `json:"type" description:"类型:1-注册/登录,2-找回密码"`
|
||||||
|
CreatedAt *gtime.Time `json:"createdAt" description:""`
|
||||||
|
UpdatedAt *gtime.Time `json:"updatedAt" description:""`
|
||||||
|
}
|
21
internal/model/entity/read_log.go
Normal file
21
internal/model/entity/read_log.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// =================================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// =================================================================================
|
||||||
|
|
||||||
|
package entity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ReadLog is the golang structure for table read_log.
|
||||||
|
type ReadLog struct {
|
||||||
|
Id uint64 `json:"id" description:""`
|
||||||
|
ShortStoryId int `json:"shortStoryId" description:""`
|
||||||
|
OperateType int `json:"operateType" description:"操作类型:1-阅读,2-加入书架"`
|
||||||
|
OperateTime *gtime.Time `json:"operateTime" description:"操作时间"`
|
||||||
|
ReadDuration uint `json:"readDuration" description:"阅读时长,秒为单位"`
|
||||||
|
CreatedAt *gtime.Time `json:"createdAt" description:""`
|
||||||
|
UpdatedAt *gtime.Time `json:"updatedAt" description:""`
|
||||||
|
DeletedAt *gtime.Time `json:"deletedAt" description:""`
|
||||||
|
}
|
25
internal/model/entity/short_story.go
Normal file
25
internal/model/entity/short_story.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// =================================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// =================================================================================
|
||||||
|
|
||||||
|
package entity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ShortStory is the golang structure for table short_story.
|
||||||
|
type ShortStory struct {
|
||||||
|
Id uint `json:"id" description:""`
|
||||||
|
Title string `json:"title" description:"标题"`
|
||||||
|
Content string `json:"content" description:"内容"`
|
||||||
|
RecommendCoverImg string `json:"recommendCoverImg" description:"推荐封面"`
|
||||||
|
BookCoverImg string `json:"bookCoverImg" description:"书籍封面"`
|
||||||
|
RecommendTitle string `json:"recommendTitle" description:"推荐标题"`
|
||||||
|
CatId string `json:"catId" description:"分类,多个用逗号隔开"`
|
||||||
|
PreReadPercent uint `json:"preReadPercent" description:"试读百分比"`
|
||||||
|
IsAudit uint `json:"isAudit" description:"是否审核:1-已审核,2-未审核,3-草稿"`
|
||||||
|
CreatedAt *gtime.Time `json:"createdAt" description:""`
|
||||||
|
UpdatedAt *gtime.Time `json:"updatedAt" description:""`
|
||||||
|
DeletedAt *gtime.Time `json:"deletedAt" description:""`
|
||||||
|
}
|
25
internal/model/entity/writer.go
Normal file
25
internal/model/entity/writer.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// =================================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// =================================================================================
|
||||||
|
|
||||||
|
package entity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Writer is the golang structure for table writer.
|
||||||
|
type Writer struct {
|
||||||
|
Id uint `json:"id" description:""`
|
||||||
|
PenName string `json:"penName" description:"笔名"`
|
||||||
|
Phone string `json:"phone" description:"手机号"`
|
||||||
|
Password string `json:"password" description:"密码"`
|
||||||
|
Introduction string `json:"introduction" description:"简介"`
|
||||||
|
Avatar string `json:"avatar" description:"头像"`
|
||||||
|
Qq string `json:"qq" description:""`
|
||||||
|
RealName string `json:"realName" description:"真名"`
|
||||||
|
IdNo string `json:"idNo" description:"身份证号"`
|
||||||
|
CreatedAt *gtime.Time `json:"createdAt" description:""`
|
||||||
|
UpdatedAt *gtime.Time `json:"updatedAt" description:""`
|
||||||
|
DeletedAt *gtime.Time `json:"deletedAt" description:""`
|
||||||
|
}
|
16
internal/model/phone_verify.go
Normal file
16
internal/model/phone_verify.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Package model -----------------------------
|
||||||
|
// @file : phone_verify.go
|
||||||
|
// @author : Allen zhang
|
||||||
|
// @contact : 364438619@qq.com
|
||||||
|
// @time : 2024/1/11 15:30
|
||||||
|
// -------------------------------------------
|
||||||
|
package model
|
||||||
|
|
||||||
|
type GetCodeInput struct {
|
||||||
|
Phone string
|
||||||
|
CodeType int
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetCodeOutput struct {
|
||||||
|
Code int
|
||||||
|
}
|
24
internal/model/writer.go
Normal file
24
internal/model/writer.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Package model -----------------------------
|
||||||
|
// @file : login.go
|
||||||
|
// @author : Allen zhang
|
||||||
|
// @contact : 364438619@qq.com
|
||||||
|
// @time : 2024/1/10 14:40
|
||||||
|
// -------------------------------------------
|
||||||
|
package model
|
||||||
|
|
||||||
|
type WriterCreateOrLoginInput struct {
|
||||||
|
Phone string
|
||||||
|
Code int
|
||||||
|
}
|
||||||
|
|
||||||
|
type WriterCreateOrLoginOutput struct {
|
||||||
|
Id uint
|
||||||
|
}
|
||||||
|
|
||||||
|
// type GetCodeInput struct {
|
||||||
|
// Phone string
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// type GetCodeOutput struct {
|
||||||
|
// Code int
|
||||||
|
// }
|
1
internal/packed/packed.go
Normal file
1
internal/packed/packed.go
Normal file
@ -0,0 +1 @@
|
|||||||
|
package packed
|
0
internal/service/.gitkeep
Normal file
0
internal/service/.gitkeep
Normal file
42
internal/service/bizctx.go
Normal file
42
internal/service/bizctx.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// ================================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// You can delete these comments if you wish manually maintain this interface file.
|
||||||
|
// ================================================================================
|
||||||
|
|
||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"novel/internal/model"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/net/ghttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
IBizCtx interface {
|
||||||
|
// Init 初始化上下文对象指针到上下文对象中,以便后续的请求流程中可以修改。
|
||||||
|
Init(r *ghttp.Request, customCtx *model.Context)
|
||||||
|
// Get 获得上下文变量,如果没有设置,那么返回nil
|
||||||
|
Get(ctx context.Context) *model.Context
|
||||||
|
// SetUser 将上下文信息设置到上下文请求中,注意是完整覆盖
|
||||||
|
SetUser(ctx context.Context, ctxUser *model.ContextUser)
|
||||||
|
// SetData 将上下文信息设置到上下文请求中,注意是完整覆盖
|
||||||
|
SetData(ctx context.Context, data g.Map)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
localBizCtx IBizCtx
|
||||||
|
)
|
||||||
|
|
||||||
|
func BizCtx() IBizCtx {
|
||||||
|
if localBizCtx == nil {
|
||||||
|
panic("implement not found for interface IBizCtx, forgot register?")
|
||||||
|
}
|
||||||
|
return localBizCtx
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterBizCtx(i IBizCtx) {
|
||||||
|
localBizCtx = i
|
||||||
|
}
|
32
internal/service/phone_verify.go
Normal file
32
internal/service/phone_verify.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// ================================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// You can delete these comments if you wish manually maintain this interface file.
|
||||||
|
// ================================================================================
|
||||||
|
|
||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"novel/internal/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
IPhoneVerify interface {
|
||||||
|
GenerateCode(ctx context.Context, phone string, codeType int) (out *model.GetCodeOutput, err error)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
localPhoneVerify IPhoneVerify
|
||||||
|
)
|
||||||
|
|
||||||
|
func PhoneVerify() IPhoneVerify {
|
||||||
|
if localPhoneVerify == nil {
|
||||||
|
panic("implement not found for interface IPhoneVerify, forgot register?")
|
||||||
|
}
|
||||||
|
return localPhoneVerify
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterPhoneVerify(i IPhoneVerify) {
|
||||||
|
localPhoneVerify = i
|
||||||
|
}
|
32
internal/service/session.go
Normal file
32
internal/service/session.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// ================================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// You can delete these comments if you wish manually maintain this interface file.
|
||||||
|
// ================================================================================
|
||||||
|
|
||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"novel/internal/model/entity"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
ISession interface {
|
||||||
|
SetWriter(ctx context.Context, writer *entity.Writer) error
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
localSession ISession
|
||||||
|
)
|
||||||
|
|
||||||
|
func Session() ISession {
|
||||||
|
if localSession == nil {
|
||||||
|
panic("implement not found for interface ISession, forgot register?")
|
||||||
|
}
|
||||||
|
return localSession
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterSession(i ISession) {
|
||||||
|
localSession = i
|
||||||
|
}
|
34
internal/service/writer.go
Normal file
34
internal/service/writer.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// ================================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// You can delete these comments if you wish manually maintain this interface file.
|
||||||
|
// ================================================================================
|
||||||
|
|
||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"novel/internal/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
IWriter interface {
|
||||||
|
CreateOrLogin(ctx context.Context, in model.WriterCreateOrLoginInput) (out *model.WriterCreateOrLoginOutput, err error)
|
||||||
|
CheckPhoneVerifyCode(ctx context.Context, phone string, code, codeType int) (bool, error)
|
||||||
|
CheckWriter(ctx context.Context, phone string) (bool, error)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
localWriter IWriter
|
||||||
|
)
|
||||||
|
|
||||||
|
func Writer() IWriter {
|
||||||
|
if localWriter == nil {
|
||||||
|
panic("implement not found for interface IWriter, forgot register?")
|
||||||
|
}
|
||||||
|
return localWriter
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterWriter(i IWriter) {
|
||||||
|
localWriter = i
|
||||||
|
}
|
19
main.go
Normal file
19
main.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "novel/internal/packed"
|
||||||
|
|
||||||
|
// _ "novel/internal/logic/logic.go"
|
||||||
|
|
||||||
|
_ "novel/internal/logic"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
|
|
||||||
|
"novel/internal/cmd"
|
||||||
|
|
||||||
|
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
cmd.Main.Run(gctx.GetInitCtx())
|
||||||
|
}
|
21
manifest/deploy/kustomize/base/deployment.yaml
Normal file
21
manifest/deploy/kustomize/base/deployment.yaml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: template-single
|
||||||
|
labels:
|
||||||
|
app: template-single
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: template-single
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: template-single
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name : main
|
||||||
|
image: template-single
|
||||||
|
imagePullPolicy: Always
|
||||||
|
|
8
manifest/deploy/kustomize/base/kustomization.yaml
Normal file
8
manifest/deploy/kustomize/base/kustomization.yaml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
resources:
|
||||||
|
- deployment.yaml
|
||||||
|
- service.yaml
|
||||||
|
|
||||||
|
|
||||||
|
|
12
manifest/deploy/kustomize/base/service.yaml
Normal file
12
manifest/deploy/kustomize/base/service.yaml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: template-single
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 8000
|
||||||
|
selector:
|
||||||
|
app: template-single
|
||||||
|
|
14
manifest/deploy/kustomize/overlays/develop/configmap.yaml
Normal file
14
manifest/deploy/kustomize/overlays/develop/configmap.yaml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: template-single-configmap
|
||||||
|
data:
|
||||||
|
config.yaml: |
|
||||||
|
server:
|
||||||
|
address: ":8000"
|
||||||
|
openapiPath: "/api.json"
|
||||||
|
swaggerPath: "/swagger"
|
||||||
|
|
||||||
|
logger:
|
||||||
|
level : "all"
|
||||||
|
stdout: true
|
10
manifest/deploy/kustomize/overlays/develop/deployment.yaml
Normal file
10
manifest/deploy/kustomize/overlays/develop/deployment.yaml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: template-single
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name : main
|
||||||
|
image: template-single:develop
|
@ -0,0 +1,14 @@
|
|||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
|
||||||
|
resources:
|
||||||
|
- ../../base
|
||||||
|
- configmap.yaml
|
||||||
|
|
||||||
|
patchesStrategicMerge:
|
||||||
|
- deployment.yaml
|
||||||
|
|
||||||
|
namespace: default
|
||||||
|
|
||||||
|
|
||||||
|
|
16
manifest/docker/Dockerfile
Normal file
16
manifest/docker/Dockerfile
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
FROM loads/alpine:3.8
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# INSTALLATION
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
ENV WORKDIR /app
|
||||||
|
ADD resource $WORKDIR/
|
||||||
|
ADD ./temp/linux_amd64/main $WORKDIR/main
|
||||||
|
RUN chmod +x $WORKDIR/main
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# START
|
||||||
|
###############################################################################
|
||||||
|
WORKDIR $WORKDIR
|
||||||
|
CMD ./main
|
8
manifest/docker/docker.sh
Normal file
8
manifest/docker/docker.sh
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This shell is executed before docker build.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
0
manifest/i18n/.gitkeep
Normal file
0
manifest/i18n/.gitkeep
Normal file
0
manifest/protobuf/.keep-if-necessary
Normal file
0
manifest/protobuf/.keep-if-necessary
Normal file
0
resource/public/html/.gitkeep
Normal file
0
resource/public/html/.gitkeep
Normal file
0
resource/public/plugin/.gitkeep
Normal file
0
resource/public/plugin/.gitkeep
Normal file
0
resource/public/resource/css/.gitkeep
Normal file
0
resource/public/resource/css/.gitkeep
Normal file
0
resource/public/resource/image/.gitkeep
Normal file
0
resource/public/resource/image/.gitkeep
Normal file
0
resource/public/resource/js/.gitkeep
Normal file
0
resource/public/resource/js/.gitkeep
Normal file
0
resource/template/.gitkeep
Normal file
0
resource/template/.gitkeep
Normal file
0
utility/.gitkeep
Normal file
0
utility/.gitkeep
Normal file
Reference in New Issue
Block a user