commit 00122cc66d465e180fc67bee3a160364cd66b5f2 Author: zp Date: Fri Jan 12 18:08:51 2024 +0800 initial commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1fbf887 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* linguist-language=GO \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..18646b6 --- /dev/null +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2af9d48 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..939fef7 --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +ROOT_DIR = $(shell pwd) +NAMESPACE = "default" +DEPLOY_NAME = "template-single" +DOCKER_NAME = "template-single" + +include ./hack/hack.mk \ No newline at end of file diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..83405ed --- /dev/null +++ b/README.MD @@ -0,0 +1,4 @@ +# GoFrame Template For SingleRepo + +Quick Start: +- https://goframe.org/pages/viewpage.action?pageId=1114399 \ No newline at end of file diff --git a/api/backend/login.go b/api/backend/login.go new file mode 100644 index 0000000..05d2b2d --- /dev/null +++ b/api/backend/login.go @@ -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 +} diff --git a/api/user/user.go b/api/user/user.go new file mode 100644 index 0000000..68b048e --- /dev/null +++ b/api/user/user.go @@ -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{} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9beb982 --- /dev/null +++ b/go.mod @@ -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 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..f73ff2e --- /dev/null +++ b/go.sum @@ -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= diff --git a/hack/config.yaml b/hack/config.yaml new file mode 100644 index 0000000..6b8e98d --- /dev/null +++ b/hack/config.yaml @@ -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 \ No newline at end of file diff --git a/hack/hack-cli.mk b/hack/hack-cli.mk new file mode 100644 index 0000000..7ba0d72 --- /dev/null +++ b/hack/hack-cli.mk @@ -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; \ No newline at end of file diff --git a/hack/hack.mk b/hack/hack.mk new file mode 100644 index 0000000..1a42d77 --- /dev/null +++ b/hack/hack.mk @@ -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 \ No newline at end of file diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go new file mode 100644 index 0000000..77b3131 --- /dev/null +++ b/internal/cmd/cmd.go @@ -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 + }, + } +) diff --git a/internal/consts/consts.go b/internal/consts/consts.go new file mode 100644 index 0000000..8e7da78 --- /dev/null +++ b/internal/consts/consts.go @@ -0,0 +1,8 @@ +package consts + +const ( + PageSize = 10 + PhoneVerifyType1 = 1 // 1-注册/登录 + PhoneVerifyType2 = 2 // 2-找回密码 + ContextKey = "ContextKey" // 上下文变量存储键名,前后端系统共享 +) diff --git a/internal/controller/backend/login.go b/internal/controller/backend/login.go new file mode 100644 index 0000000..de4a3d1 --- /dev/null +++ b/internal/controller/backend/login.go @@ -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 +} diff --git a/internal/dao/.gitkeep b/internal/dao/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/internal/dao/category.go b/internal/dao/category.go new file mode 100644 index 0000000..7899667 --- /dev/null +++ b/internal/dao/category.go @@ -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. diff --git a/internal/dao/internal/category.go b/internal/dao/internal/category.go new file mode 100644 index 0000000..71dbf01 --- /dev/null +++ b/internal/dao/internal/category.go @@ -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) +} diff --git a/internal/dao/internal/phone_verify.go b/internal/dao/internal/phone_verify.go new file mode 100644 index 0000000..e21a533 --- /dev/null +++ b/internal/dao/internal/phone_verify.go @@ -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) +} diff --git a/internal/dao/internal/read_log.go b/internal/dao/internal/read_log.go new file mode 100644 index 0000000..5cebc40 --- /dev/null +++ b/internal/dao/internal/read_log.go @@ -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) +} diff --git a/internal/dao/internal/short_story.go b/internal/dao/internal/short_story.go new file mode 100644 index 0000000..5e42613 --- /dev/null +++ b/internal/dao/internal/short_story.go @@ -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) +} diff --git a/internal/dao/internal/user.go b/internal/dao/internal/user.go new file mode 100644 index 0000000..e478eac --- /dev/null +++ b/internal/dao/internal/user.go @@ -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) +} diff --git a/internal/dao/internal/writer.go b/internal/dao/internal/writer.go new file mode 100644 index 0000000..2b4003d --- /dev/null +++ b/internal/dao/internal/writer.go @@ -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) +} diff --git a/internal/dao/phone_verify.go b/internal/dao/phone_verify.go new file mode 100644 index 0000000..bbf0d4e --- /dev/null +++ b/internal/dao/phone_verify.go @@ -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. diff --git a/internal/dao/read_log.go b/internal/dao/read_log.go new file mode 100644 index 0000000..0d28f63 --- /dev/null +++ b/internal/dao/read_log.go @@ -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. diff --git a/internal/dao/short_story.go b/internal/dao/short_story.go new file mode 100644 index 0000000..318ebf6 --- /dev/null +++ b/internal/dao/short_story.go @@ -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. diff --git a/internal/dao/writer.go b/internal/dao/writer.go new file mode 100644 index 0000000..c826350 --- /dev/null +++ b/internal/dao/writer.go @@ -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. diff --git a/internal/logic/.gitkeep b/internal/logic/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/internal/logic/bizctx/bizctx.go b/internal/logic/bizctx/bizctx.go new file mode 100644 index 0000000..2c07a78 --- /dev/null +++ b/internal/logic/bizctx/bizctx.go @@ -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 +} diff --git a/internal/logic/logic.go b/internal/logic/logic.go new file mode 100644 index 0000000..eff613b --- /dev/null +++ b/internal/logic/logic.go @@ -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" +) diff --git a/internal/logic/phone_verify/phone_verify.go b/internal/logic/phone_verify/phone_verify.go new file mode 100644 index 0000000..6ec339b --- /dev/null +++ b/internal/logic/phone_verify/phone_verify.go @@ -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 +} diff --git a/internal/logic/session/session.go b/internal/logic/session/session.go new file mode 100644 index 0000000..ec0e59f --- /dev/null +++ b/internal/logic/session/session.go @@ -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) +} diff --git a/internal/logic/writer/writer.go b/internal/logic/writer/writer.go new file mode 100644 index 0000000..7f1de14 --- /dev/null +++ b/internal/logic/writer/writer.go @@ -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 +} diff --git a/internal/model/.gitkeep b/internal/model/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/internal/model/context.go b/internal/model/context.go new file mode 100644 index 0000000..2314240 --- /dev/null +++ b/internal/model/context.go @@ -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 // 是否是管理员 +} diff --git a/internal/model/do/.gitkeep b/internal/model/do/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/internal/model/do/category.go b/internal/model/do/category.go new file mode 100644 index 0000000..2a51c32 --- /dev/null +++ b/internal/model/do/category.go @@ -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 // +} diff --git a/internal/model/do/phone_verify.go b/internal/model/do/phone_verify.go new file mode 100644 index 0000000..723b579 --- /dev/null +++ b/internal/model/do/phone_verify.go @@ -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 // +} diff --git a/internal/model/do/read_log.go b/internal/model/do/read_log.go new file mode 100644 index 0000000..a411438 --- /dev/null +++ b/internal/model/do/read_log.go @@ -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 // +} diff --git a/internal/model/do/short_story.go b/internal/model/do/short_story.go new file mode 100644 index 0000000..1afab67 --- /dev/null +++ b/internal/model/do/short_story.go @@ -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 // +} diff --git a/internal/model/do/writer.go b/internal/model/do/writer.go new file mode 100644 index 0000000..7da0ada --- /dev/null +++ b/internal/model/do/writer.go @@ -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 // +} diff --git a/internal/model/entity/.gitkeep b/internal/model/entity/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/internal/model/entity/category.go b/internal/model/entity/category.go new file mode 100644 index 0000000..c28fa62 --- /dev/null +++ b/internal/model/entity/category.go @@ -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:""` +} diff --git a/internal/model/entity/phone_verify.go b/internal/model/entity/phone_verify.go new file mode 100644 index 0000000..632f0f4 --- /dev/null +++ b/internal/model/entity/phone_verify.go @@ -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:""` +} diff --git a/internal/model/entity/read_log.go b/internal/model/entity/read_log.go new file mode 100644 index 0000000..adda827 --- /dev/null +++ b/internal/model/entity/read_log.go @@ -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:""` +} diff --git a/internal/model/entity/short_story.go b/internal/model/entity/short_story.go new file mode 100644 index 0000000..7c625d7 --- /dev/null +++ b/internal/model/entity/short_story.go @@ -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:""` +} diff --git a/internal/model/entity/writer.go b/internal/model/entity/writer.go new file mode 100644 index 0000000..2ef413f --- /dev/null +++ b/internal/model/entity/writer.go @@ -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:""` +} diff --git a/internal/model/phone_verify.go b/internal/model/phone_verify.go new file mode 100644 index 0000000..b0f0f74 --- /dev/null +++ b/internal/model/phone_verify.go @@ -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 +} diff --git a/internal/model/writer.go b/internal/model/writer.go new file mode 100644 index 0000000..9ddded2 --- /dev/null +++ b/internal/model/writer.go @@ -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 +// } diff --git a/internal/packed/packed.go b/internal/packed/packed.go new file mode 100644 index 0000000..e20ab1e --- /dev/null +++ b/internal/packed/packed.go @@ -0,0 +1 @@ +package packed diff --git a/internal/service/.gitkeep b/internal/service/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/internal/service/bizctx.go b/internal/service/bizctx.go new file mode 100644 index 0000000..10a71eb --- /dev/null +++ b/internal/service/bizctx.go @@ -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 +} diff --git a/internal/service/phone_verify.go b/internal/service/phone_verify.go new file mode 100644 index 0000000..5151d99 --- /dev/null +++ b/internal/service/phone_verify.go @@ -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 +} diff --git a/internal/service/session.go b/internal/service/session.go new file mode 100644 index 0000000..a92fd6c --- /dev/null +++ b/internal/service/session.go @@ -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 +} diff --git a/internal/service/writer.go b/internal/service/writer.go new file mode 100644 index 0000000..1d09574 --- /dev/null +++ b/internal/service/writer.go @@ -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 +} diff --git a/main.exe~ b/main.exe~ new file mode 100644 index 0000000..6f8d88c Binary files /dev/null and b/main.exe~ differ diff --git a/main.go b/main.go new file mode 100644 index 0000000..8d1e71f --- /dev/null +++ b/main.go @@ -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()) +} diff --git a/manifest/deploy/kustomize/base/deployment.yaml b/manifest/deploy/kustomize/base/deployment.yaml new file mode 100644 index 0000000..28f1d69 --- /dev/null +++ b/manifest/deploy/kustomize/base/deployment.yaml @@ -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 + diff --git a/manifest/deploy/kustomize/base/kustomization.yaml b/manifest/deploy/kustomize/base/kustomization.yaml new file mode 100644 index 0000000..302d92d --- /dev/null +++ b/manifest/deploy/kustomize/base/kustomization.yaml @@ -0,0 +1,8 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- deployment.yaml +- service.yaml + + + diff --git a/manifest/deploy/kustomize/base/service.yaml b/manifest/deploy/kustomize/base/service.yaml new file mode 100644 index 0000000..608771c --- /dev/null +++ b/manifest/deploy/kustomize/base/service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: template-single +spec: + ports: + - port: 80 + protocol: TCP + targetPort: 8000 + selector: + app: template-single + diff --git a/manifest/deploy/kustomize/overlays/develop/configmap.yaml b/manifest/deploy/kustomize/overlays/develop/configmap.yaml new file mode 100644 index 0000000..3b1d0af --- /dev/null +++ b/manifest/deploy/kustomize/overlays/develop/configmap.yaml @@ -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 diff --git a/manifest/deploy/kustomize/overlays/develop/deployment.yaml b/manifest/deploy/kustomize/overlays/develop/deployment.yaml new file mode 100644 index 0000000..04e4851 --- /dev/null +++ b/manifest/deploy/kustomize/overlays/develop/deployment.yaml @@ -0,0 +1,10 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: template-single +spec: + template: + spec: + containers: + - name : main + image: template-single:develop \ No newline at end of file diff --git a/manifest/deploy/kustomize/overlays/develop/kustomization.yaml b/manifest/deploy/kustomize/overlays/develop/kustomization.yaml new file mode 100644 index 0000000..4731c47 --- /dev/null +++ b/manifest/deploy/kustomize/overlays/develop/kustomization.yaml @@ -0,0 +1,14 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: +- ../../base +- configmap.yaml + +patchesStrategicMerge: +- deployment.yaml + +namespace: default + + + diff --git a/manifest/docker/Dockerfile b/manifest/docker/Dockerfile new file mode 100644 index 0000000..d3abe8f --- /dev/null +++ b/manifest/docker/Dockerfile @@ -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 diff --git a/manifest/docker/docker.sh b/manifest/docker/docker.sh new file mode 100644 index 0000000..ff393f9 --- /dev/null +++ b/manifest/docker/docker.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# This shell is executed before docker build. + + + + + diff --git a/manifest/i18n/.gitkeep b/manifest/i18n/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/manifest/protobuf/.keep-if-necessary b/manifest/protobuf/.keep-if-necessary new file mode 100644 index 0000000..e69de29 diff --git a/resource/public/html/.gitkeep b/resource/public/html/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/resource/public/plugin/.gitkeep b/resource/public/plugin/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/resource/public/resource/css/.gitkeep b/resource/public/resource/css/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/resource/public/resource/image/.gitkeep b/resource/public/resource/image/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/resource/public/resource/js/.gitkeep b/resource/public/resource/js/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/resource/template/.gitkeep b/resource/template/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/utility/.gitkeep b/utility/.gitkeep new file mode 100644 index 0000000..e69de29