Compare commits
11 Commits
master
...
zhouxinzho
| Author | SHA1 | Message | Date |
|---|---|---|---|
|
|
b399b19be6 |
4.2提交笔记
|
2 weeks ago |
|
|
17957b228e |
4.1提交笔记和代码
|
2 weeks ago |
|
|
557446df79 |
3.31提交笔记
|
2 weeks ago |
|
|
1089adc0d3 |
3.30提交笔记
|
2 weeks ago |
|
|
6f83eaf14a |
3.28补交笔记照片
|
2 weeks ago |
|
|
433eace492 |
3.28提交笔记
|
2 weeks ago |
|
|
21e208c8a7 |
删除旧文件夹
|
2 weeks ago |
|
|
ebf8ccab74 |
3.28提交3.28提交3.28提交
|
2 weeks ago |
|
|
2016bde7bf |
3.28提交学习笔记
|
2 weeks ago |
|
|
b240daf7da |
3.27提交学习笔记
|
3 weeks ago |
|
|
47d8240d7b |
周新忠3.26笔记
|
3 weeks ago |
-
BIN周新忠学习笔记/3.26/3.26周新忠.doc
-
BIN周新忠学习笔记/3.26/img_v3_02105_38857810-df73-49e4-bd95-da64f6ba747g.jpg
-
BIN周新忠学习笔记/3.26/img_v3_02105_7aaf57cd-1bac-4557-ad84-1ca9423f2eeg.jpg
-
BIN周新忠学习笔记/3.26/img_v3_02105_aed06a45-10b1-498c-842a-6e09ad05ff8g.jpg
-
BIN周新忠学习笔记/3.26/img_v3_02105_c300e793-9fa7-48a8-b698-075ac795e58g.jpg
-
BIN周新忠学习笔记/3.26/img_v3_02106_0c6b6038-891c-4657-a3cb-414c02ff1fbg.jpg
-
BIN周新忠学习笔记/3.27/1.jpg
-
BIN周新忠学习笔记/3.27/2.jpg
-
47周新忠学习笔记/3.27/3.27周新忠.md
-
BIN周新忠学习笔记/3.27/3.jpg
-
BIN周新忠学习笔记/3.27/4.jpg
-
BIN周新忠学习笔记/3.28/1.jpg
-
BIN周新忠学习笔记/3.28/2.jpg
-
180周新忠学习笔记/3.28/3.28.md
-
BIN周新忠学习笔记/3.28/3.jpg
-
BIN周新忠学习笔记/3.28/4.jpg
-
BIN周新忠学习笔记/3.28/5.jpg
-
BIN周新忠学习笔记/3.28/6.jpg
-
BIN周新忠学习笔记/3.28/7.jpg
-
BIN周新忠学习笔记/3.30/1.jpg
-
BIN周新忠学习笔记/3.30/2.jpg
-
BIN周新忠学习笔记/3.30/3.jpg
-
BIN周新忠学习笔记/3.30/4.jpg
-
BIN周新忠学习笔记/3.30/5.jpg
-
BIN周新忠学习笔记/3.30/6.jpg
-
145周新忠学习笔记/3.30/周新忠3.30笔记.md
-
BIN周新忠学习笔记/3.31/1.jpg
-
BIN周新忠学习笔记/3.31/2.jpg
-
BIN周新忠学习笔记/3.31/3.jpg
-
116周新忠学习笔记/3.31/周新忠笔记3.31.md
-
1周新忠学习笔记/4.1/gf_demo_02/.gitattributes
-
19周新忠学习笔记/4.1/gf_demo_02/.gitignore
-
7周新忠学习笔记/4.1/gf_demo_02/Makefile
-
6周新忠学习笔记/4.1/gf_demo_02/README.MD
-
57周新忠学习笔记/4.1/gf_demo_02/api/user/v1/user.go
-
38周新忠学习笔记/4.1/gf_demo_02/go.mod
-
70周新忠学习笔记/4.1/gf_demo_02/go.sum
-
13周新忠学习笔记/4.1/gf_demo_02/hack/config.yaml
-
20周新忠学习笔记/4.1/gf_demo_02/hack/hack-cli.mk
-
75周新忠学习笔记/4.1/gf_demo_02/hack/hack.mk
-
30周新忠学习笔记/4.1/gf_demo_02/internal/cmd/cmd.go
-
3周新忠学习笔记/4.1/gf_demo_02/internal/consts/consts.go
-
98周新忠学习笔记/4.1/gf_demo_02/internal/controller/user/user.go
-
0周新忠学习笔记/4.1/gf_demo_02/internal/dao/.gitkeep
-
27周新忠学习笔记/4.1/gf_demo_02/internal/dao/course.go
-
83周新忠学习笔记/4.1/gf_demo_02/internal/dao/internal/course.go
-
83周新忠学习笔记/4.1/gf_demo_02/internal/dao/internal/stock.go
-
85周新忠学习笔记/4.1/gf_demo_02/internal/dao/internal/user.go
-
75周新忠学习笔记/4.1/gf_demo_02/internal/dao/internal/user_course.go
-
27周新忠学习笔记/4.1/gf_demo_02/internal/dao/stock.go
-
27周新忠学习笔记/4.1/gf_demo_02/internal/dao/user.go
-
27周新忠学习笔记/4.1/gf_demo_02/internal/dao/user_course.go
-
0周新忠学习笔记/4.1/gf_demo_02/internal/logic/.gitkeep
-
12周新忠学习笔记/4.1/gf_demo_02/internal/logic/course/course.go
-
9周新忠学习笔记/4.1/gf_demo_02/internal/logic/logic.go
-
143周新忠学习笔记/4.1/gf_demo_02/internal/logic/user/user.go
-
0周新忠学习笔记/4.1/gf_demo_02/internal/model/.gitkeep
-
9周新忠学习笔记/4.1/gf_demo_02/internal/model/claim.go
-
0周新忠学习笔记/4.1/gf_demo_02/internal/model/do/.gitkeep
-
21周新忠学习笔记/4.1/gf_demo_02/internal/model/do/course.go
-
21周新忠学习笔记/4.1/gf_demo_02/internal/model/do/stock.go
-
22周新忠学习笔记/4.1/gf_demo_02/internal/model/do/user.go
-
16周新忠学习笔记/4.1/gf_demo_02/internal/model/do/user_course.go
-
0周新忠学习笔记/4.1/gf_demo_02/internal/model/entity/.gitkeep
-
19周新忠学习笔记/4.1/gf_demo_02/internal/model/entity/course.go
-
19周新忠学习笔记/4.1/gf_demo_02/internal/model/entity/stock.go
-
20周新忠学习笔记/4.1/gf_demo_02/internal/model/entity/user.go
-
11周新忠学习笔记/4.1/gf_demo_02/internal/model/entity/user_course.go
-
16周新忠学习笔记/4.1/gf_demo_02/internal/model/models.go
-
1周新忠学习笔记/4.1/gf_demo_02/internal/packed/packed.go
-
0周新忠学习笔记/4.1/gf_demo_02/internal/service/.gitkeep
-
65周新忠学习笔记/4.1/gf_demo_02/internal/service/JWTMiddleware.go
-
21周新忠学习笔记/4.1/gf_demo_02/internal/service/encode_pass.go
-
7周新忠学习笔记/4.1/gf_demo_02/internal/service/encode_pass_test.go
-
40周新忠学习笔记/4.1/gf_demo_02/internal/service/user.go
-
BIN周新忠学习笔记/4.1/gf_demo_02/main.exe~
-
17周新忠学习笔记/4.1/gf_demo_02/main.go
-
21周新忠学习笔记/4.1/gf_demo_02/manifest/deploy/kustomize/base/deployment.yaml
-
8周新忠学习笔记/4.1/gf_demo_02/manifest/deploy/kustomize/base/kustomization.yaml
-
12周新忠学习笔记/4.1/gf_demo_02/manifest/deploy/kustomize/base/service.yaml
-
14周新忠学习笔记/4.1/gf_demo_02/manifest/deploy/kustomize/overlays/develop/configmap.yaml
-
10周新忠学习笔记/4.1/gf_demo_02/manifest/deploy/kustomize/overlays/develop/deployment.yaml
-
14周新忠学习笔记/4.1/gf_demo_02/manifest/deploy/kustomize/overlays/develop/kustomization.yaml
-
16周新忠学习笔记/4.1/gf_demo_02/manifest/docker/Dockerfile
-
8周新忠学习笔记/4.1/gf_demo_02/manifest/docker/docker.sh
-
0周新忠学习笔记/4.1/gf_demo_02/manifest/i18n/.gitkeep
-
0周新忠学习笔记/4.1/gf_demo_02/manifest/protobuf/.keep-if-necessary
-
0周新忠学习笔记/4.1/gf_demo_02/resource/public/html/.gitkeep
-
0周新忠学习笔记/4.1/gf_demo_02/resource/public/plugin/.gitkeep
-
0周新忠学习笔记/4.1/gf_demo_02/resource/public/resource/css/.gitkeep
-
0周新忠学习笔记/4.1/gf_demo_02/resource/public/resource/image/.gitkeep
-
0周新忠学习笔记/4.1/gf_demo_02/resource/public/resource/js/.gitkeep
-
0周新忠学习笔记/4.1/gf_demo_02/resource/template/.gitkeep
-
0周新忠学习笔记/4.1/gf_demo_02/utility/.gitkeep
-
8周新忠学习笔记/4.1/vue_prj/.editorconfig
-
1周新忠学习笔记/4.1/vue_prj/.gitattributes
-
42周新忠学习笔记/4.1/vue_prj/.gitignore
-
10周新忠学习笔记/4.1/vue_prj/.oxlintrc.json
-
6周新忠学习笔记/4.1/vue_prj/.prettierrc.json
-
11周新忠学习笔记/4.1/vue_prj/.vscode/extensions.json
|
After Width: 2268 | Height: 4032 | Size: 2.8 MiB |
|
After Width: 2268 | Height: 4032 | Size: 3.1 MiB |
|
After Width: 2268 | Height: 4032 | Size: 3.0 MiB |
|
After Width: 2268 | Height: 4032 | Size: 3.0 MiB |
|
After Width: 1080 | Height: 1920 | Size: 1.2 MiB |
|
After Width: 1080 | Height: 1920 | Size: 1.2 MiB |
|
After Width: 1080 | Height: 1920 | Size: 1.3 MiB |
@ -0,0 +1,47 @@ |
|||
# 股票相关 |
|||
学习了股票相关的常用术语 |
|||
#### 投资者相关概念: |
|||
散户 大户 庄家 主力 |
|||
#### 从股票分析切入点划分: |
|||
基本面 政策面 技术面 |
|||
#### 市场: |
|||
级别: 一级 二级 |
|||
趋势: 多头市场 空头市场 |
|||
#### 股票类型: |
|||
蓝筹股 垃圾股 成长股 龙头股 大盘股 小盘股 |
|||
#### 技术词汇: |
|||
看多 看空 踏空 跳水 诱多 斩仓 对敲 护盘 洗盘 追涨 杀跌 |
|||
天量 地量 天价 地价 持仓量 满仓 空仓 清仓 盘整 反弹 |
|||
多头陷阱 空头陷阱 套牢 解套 含息 含权 送股 转增股 配股 |
|||
除权 填权 贴权 |
|||
|
|||
# 技术相关 |
|||
### 1.goframe框架的基本结构: |
|||
\api - 定义请求和响应 |
|||
\hack - 开发时配置文件 |
|||
\internal - 项目核心代码 |
|||
→\cmd - 项目启动位置,挂载路由 |
|||
\consts - 存常量 |
|||
\controller - 控制器 |
|||
\dao - 数据层 (spring的 mapper) |
|||
\logic - 实现层 (spring 的 impl) |
|||
\service - 服务层 |
|||
\manifest - 部署时需要的配置 |
|||
\resource - 资源文件 |
|||
\utility - 工具类 |
|||
|
|||
### 2.路由注册相关 |
|||
s:=g.Server() |
|||
单独注册 s.BindHandler |
|||
分组路由 s.Group(可嵌套) |
|||
静态资源绑定路径 s.SetServerRoot |
|||
结构体绑定 s.BindObject |
|||
单个方法绑定 s.BindObjectMethod |
|||
Restful风格 s.BindObjectRest |
|||
|
|||
### 3.规范路由 |
|||
Controller签名格式: func (Example) Execute (ctx context.Context,req *ExampleReq)(res *ExampleReq,err error) |
|||
|
|||
### 4.非规范路由获取请求参数 |
|||
获取请求:g.RequestFromCtx(ctx) |
|||
从请求中提取路径参数: request.GetQuery -> 然后用对应数据类型的转换方法提取内部的value属性值 |
|||
|
After Width: 1080 | Height: 1920 | Size: 1.2 MiB |
|
After Width: 1080 | Height: 1920 | Size: 1.2 MiB |
|
After Width: 1080 | Height: 1920 | Size: 1.2 MiB |
|
After Width: 1080 | Height: 1920 | Size: 1.1 MiB |
@ -0,0 +1,180 @@ |
|||
\# 技术相关: |
|||
|
|||
\### 获取请求参数剩余部分: |
|||
|
|||
用map提取参数: .GetQueryMap() .GetQueryMapStrStr .GetQueryMapStrVar |
|||
|
|||
取Form格式请求体参数: .GetForm()/.GetFormMap() |
|||
|
|||
获取Restful风格路由参数: GetRouter/GetRouterMap |
|||
|
|||
一次性取出各类参数: |
|||
|
|||
Get()=GetRequestMap() |
|||
|
|||
GetStruct()=GetRequestStruct() (规范路由默认调用) |
|||
|
|||
|
|||
|
|||
\### 标签: |
|||
|
|||
\#### meta标签: |
|||
|
|||
method: 请求方式(all/get/post...) |
|||
|
|||
path: 路径 |
|||
|
|||
sm: 总结 |
|||
|
|||
tags: 分组标签 |
|||
|
|||
\#### 普通字段标签: |
|||
|
|||
dc: 描述 |
|||
|
|||
p/params: 请求key |
|||
|
|||
m/orm: 数据库字段名 |
|||
|
|||
default: 默认值 |
|||
|
|||
v/vaild: 校验规则 |
|||
|
|||
ad: 补充说明 |
|||
|
|||
eg: 示例值 |
|||
|
|||
|
|||
|
|||
\### Dao部分 |
|||
|
|||
\####查询: |
|||
|
|||
\#####Select |
|||
|
|||
g.Model("table").One() 查询单条数据 |
|||
|
|||
g.Model("table").All() 查询全部数据 |
|||
|
|||
g.Model("table").Feilds()指定字段 |
|||
|
|||
g.Model("table").FeildsEx()排除字段 |
|||
|
|||
g.Model("table").Value()查询某一格的内容 |
|||
|
|||
g.Model("table").Array()查询整列 |
|||
|
|||
g.Model("table").LockUpdate()申请行级锁 |
|||
|
|||
\#####聚合函数 |
|||
|
|||
Count() Sum() Min() Max() Avg() |
|||
|
|||
\####条件: |
|||
|
|||
Where() |
|||
|
|||
WhereLT |
|||
|
|||
WhereGT |
|||
|
|||
WhereLTE |
|||
|
|||
WhereGTE |
|||
|
|||
WhereIn |
|||
|
|||
WhereBetween |
|||
|
|||
WhereNot |
|||
|
|||
WhereOr.......... |
|||
|
|||
|
|||
|
|||
\####排序 |
|||
|
|||
Order("feild","asc/desc") |
|||
|
|||
\####分组 |
|||
|
|||
Group() |
|||
|
|||
\####分页 |
|||
|
|||
Limit(origin,offset) |
|||
|
|||
Page(pageNum,pageCapcity) |
|||
|
|||
\####扫描为结构体 |
|||
|
|||
Scan(\&struct) |
|||
|
|||
\####插入 |
|||
|
|||
model.Insert()或model.Data().Insert() |
|||
|
|||
model.Replace() 删除或插入 |
|||
|
|||
model.Save()更新或插入 |
|||
|
|||
model.InsertAndGetId()插入并获取自增id |
|||
|
|||
\####更新 |
|||
|
|||
Update() |
|||
|
|||
Increment() |
|||
|
|||
Decrement() |
|||
|
|||
\####删除 |
|||
|
|||
Delete() |
|||
|
|||
\####时间字段 |
|||
|
|||
create\_at delete\_at update\_at 增删改时框架自动更新这些字段 |
|||
|
|||
delete\_at 会被作为逻辑删除的依据 |
|||
|
|||
\####事务 |
|||
|
|||
1\.手动管理事务 |
|||
|
|||
tx,err:=g.DB(),Begin(req.Context())开启事务 |
|||
|
|||
tx.Rollback()回滚 |
|||
|
|||
tx.Commit()提交 |
|||
|
|||
2\.靠抛出error管理的事务 |
|||
|
|||
err:=g.DB().Transaction(context.TODO(),func(ctx context.Context,tx gbd.Tx)error{}) |
|||
|
|||
|
|||
|
|||
\#股票相关: |
|||
|
|||
|
|||
|
|||
道氏理论观点: |
|||
|
|||
平均价格包容消化一切 |
|||
|
|||
市场同时存在三种趋势(基本运动,次级运动,日常运动) |
|||
|
|||
大趋势有三个阶段 |
|||
|
|||
平均价格互相验证 |
|||
|
|||
成交量验证趋势 |
|||
|
|||
确切的反转信号判定终结 |
|||
|
|||
操作口诀:先大后小,先长后短,做熟不做生 |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
After Width: 1080 | Height: 1920 | Size: 1.2 MiB |
|
After Width: 1080 | Height: 1920 | Size: 1.2 MiB |
|
After Width: 1080 | Height: 1920 | Size: 1.3 MiB |
|
After Width: 1080 | Height: 1920 | Size: 1.2 MiB |
|
After Width: 1080 | Height: 1920 | Size: 1.1 MiB |
|
After Width: 1080 | Height: 1920 | Size: 1.3 MiB |
|
After Width: 1080 | Height: 1920 | Size: 1.2 MiB |
|
After Width: 1080 | Height: 1920 | Size: 1.2 MiB |
|
After Width: 1080 | Height: 1920 | Size: 1.3 MiB |
|
After Width: 1080 | Height: 1920 | Size: 1.3 MiB |
|
After Width: 1080 | Height: 1920 | Size: 1.3 MiB |
@ -0,0 +1,145 @@ |
|||
# 技术部分 |
|||
### 手动编写SQL的方法: |
|||
g.DB().Query(ctx,sql,g.Array{}) //查询sql |
|||
g.DB().Exec(ctx,sql,g.Array{}) //修改的sql |
|||
### Dao代码生成 |
|||
config 中需要配置: |
|||
gfcli: |
|||
gen: |
|||
dao: |
|||
link: |
|||
tables: |
|||
执行gf gen dao命令 //即逆向工程 |
|||
或直接执行gf gen dao -l "link" -t "tables" 可不用改配置 |
|||
|
|||
生成代码: |
|||
entity包 数据库表对应结构体 |
|||
do包 经过包装的结构体,与entity区别是普通字段类型为interface{}而不是基本类型,可用来区分空值和空指针 |
|||
dao包 直接隶属dao包的go文件写自定义业务代码,隶属于internal包的go文件用来存储框架预设代码(再次执行gen命令会被覆盖) |
|||
|
|||
### 级联查询 |
|||
#### 一对一关系 |
|||
结构体中添加字段: Struct *Struct `orm:"with:id=s_id"` //标签指定关联规则 |
|||
查询时使用model.With(entity.Struct{})设置级联的表 |
|||
|
|||
#### 一对多关系 |
|||
结构体中添加字段: Structs []*Struct `orm:"with:id=s_id"` //标签指定关联规则 |
|||
|
|||
#### 多级级联 |
|||
直接在With()中添加多个结构体就行 |
|||
|
|||
### Service和Logic层 |
|||
|
|||
根据logic包生成service接口:gf gen service |
|||
|
|||
#### service |
|||
组成部分: |
|||
接口 |
|||
type IExample interface{ //命名以I开头 |
|||
定义业务函数 |
|||
} |
|||
|
|||
定义接口变量 |
|||
var localExample() IExample //私有化防止外部修改 |
|||
|
|||
定义获取接口方法 |
|||
func Example () IExample{ |
|||
if localExample==nil{ |
|||
panic(".....") |
|||
} |
|||
return localExample |
|||
} |
|||
|
|||
定义注册方法 |
|||
func RegisterExample(i IExample){ |
|||
localExample=i //用接口实现给接口变量赋值 |
|||
} |
|||
|
|||
#### Logic层 |
|||
定义结构体 |
|||
type sExample struct{} //以s开头命名 |
|||
|
|||
初始化方法中注册 |
|||
func init(){ |
|||
service.RegisterExample(&sExample{}) |
|||
} |
|||
|
|||
实现service的接口中的业务方法 |
|||
|
|||
#### 初始化接口 |
|||
在logic.go中统一import logic,然后再在main.go 中import一次logic.go 实现单例初始化服务接口 |
|||
|
|||
### 模板输出 |
|||
1. req.Response.Writef() //其实就是write套了层Sprintf |
|||
2. req.Response.WriteTplContent(string,g.Map{}) //此法是在string中预留{{}}占位符,用g.Map中的value替换占位符 |
|||
3. req.Response.WriteTpl(path string, g.Map{}) //此法与上一个区别是第一个参数是HTML文件路径,在文件路径中可以预留占位符进行替换,形式类似于JSP或Thymeleaf |
|||
4. 模板中的流程控制语句: |
|||
条件判断 |
|||
{{if [compare] variable1 variable2}} |
|||
{{else}} |
|||
{{end}} |
|||
循环遍历切片 |
|||
{{range.slice}} |
|||
{{end}} |
|||
循环遍历map |
|||
{{range $key,$value := .map}} |
|||
{{end}} |
|||
|
|||
### 文件上传 |
|||
file:=req.GetUploadFile("name") |
|||
规范路由写法: |
|||
属性: File *ghttp.UploadFile `p:"name"` |
|||
全局配置文件大小限制: |
|||
config文件中 |
|||
server: |
|||
clientMaxBodySize: "" |
|||
|
|||
局部配置文件大小限制: |
|||
标签:v:"max-size: xxx MB" |
|||
|
|||
### 文件下载 |
|||
req.Response.ServerFile("/path") // 图片会显示在前端而不主动下载 |
|||
req.Response.ServerFileDownload("/path","name") //无论是不是图片都会立刻开始下载 |
|||
|
|||
### Cookie和Session |
|||
req.Cookie.Set("key","value") |
|||
req.Cookie.SetCookie// 有多项设置,自由度较高 |
|||
req.Cookie.Remove("key") //移除cookie |
|||
req.Session.Set("key","value") |
|||
req.Session.Remove("key") |
|||
|
|||
### 时间工具 |
|||
gtime.Now() Date() DateTime() New() Format() TimeStamp().... |
|||
|
|||
### 随机工具 |
|||
grand.Intn() grand.N() grand.S() grand.Letters()..... |
|||
|
|||
### 中间件 |
|||
固定签名格式: |
|||
func 函数名 (r *ghttp.Request){ |
|||
前置中间件业务逻辑 |
|||
r.Middleware.Next() |
|||
后置中间件业务逻辑 |
|||
} |
|||
挂载方法: |
|||
1.全局中间件 2.分组路由中间件 |
|||
|
|||
|
|||
|
|||
# 业务部分 |
|||
|
|||
## 超级云脑-云脑探秘 功能总结 |
|||
|
|||
首先是可以根据股票代码或名称搜索股票 |
|||
#### 股票估值 |
|||
搜索出具体的股票后,显示当前股票估值和上一收盘日的基本情况 |
|||
#### 安全级别 |
|||
显示六色罗盘,分析支撑和压力情况,据此显示风险分级 |
|||
#### 压力支撑 |
|||
显示支撑位和压力位,根据支撑压力数据显示简短的总结 |
|||
#### 趋势研判 |
|||
显示K线图,并总结趋势 |
|||
#### 庄家成本 |
|||
显示筹码模型,根据筹码模型分析陈本价格 |
|||
#### 情绪价值 |
|||
对该支股票进行简短的总结陈述 |
|||
|
After Width: 1080 | Height: 1920 | Size: 1.3 MiB |
|
After Width: 1080 | Height: 1920 | Size: 1.3 MiB |
|
After Width: 1080 | Height: 1920 | Size: 1.2 MiB |
@ -0,0 +1,116 @@ |
|||
## 技术方面 |
|||
|
|||
### 打包指令 |
|||
|
|||
配置: |
|||
|
|||
```yaml |
|||
gfcli: |
|||
build: |
|||
name: "" |
|||
arch: "amd64" # 配置CPU架构 |
|||
system: "linux,darwin,windows" # 配置操作系统 |
|||
mod: "" #GoModules编译模式,默认留空 |
|||
cgo:0 # 是否允许调用C代码,0禁用1启用 |
|||
packSrc: "manifest,resource" # 指定一起打包的静态资源路径 |
|||
``` |
|||
|
|||
命令: gf build |
|||
|
|||
|
|||
|
|||
### Bcrypt加密 |
|||
|
|||
```go |
|||
//加密: |
|||
bcrypt.GenerateFromPassword([]byte("要加密的内容"),int 加密次数2^int次) |
|||
|
|||
//验证: |
|||
err:=bcrypt.CompareHashAndPassword(hash,password) |
|||
``` |
|||
|
|||
|
|||
|
|||
### JWT |
|||
|
|||
#### golang-jwt |
|||
|
|||
```go |
|||
//1.定义结构体 |
|||
type MyClaims struct{ |
|||
ID uint |
|||
Username string |
|||
jwt.RegisteredClaims |
|||
} |
|||
|
|||
//2.签发 |
|||
claims:=MyClaims{ |
|||
.... |
|||
RegisteredClaims: jwt.RegisteredClaims{ |
|||
设置token参数,如过期时间等 |
|||
} |
|||
} |
|||
token:=jwt.NewWithClaims(jwt.SigningMethodHS256,claims) |
|||
token =token.SignedString([]byte(密钥)) |
|||
|
|||
//3.验签 |
|||
token,err:= jwt.ParseWithClaims(tokenString, &model.MyClaim{}, func(token *jwt.Token) (interface{}, error) { |
|||
_, ok := token.Method.(*jwt.SigningMethodHMAC) //验证加密方式 |
|||
if !ok { |
|||
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) |
|||
} |
|||
return []byte(密钥), nil |
|||
}) |
|||
if err!=nil {return nil,err} |
|||
|
|||
if claims,ok:=token.Claims.(*MyClaims);ok&&token.Valid{ |
|||
return claims,nil |
|||
} |
|||
|
|||
``` |
|||
|
|||
#### gf-jwt |
|||
|
|||
gf-jwt是以中间件的形式管理token |
|||
|
|||
```go |
|||
//1.初始化中间件 |
|||
var Auth:=&gfjwt.GFJWTMiddleware{ |
|||
Realm:"name", |
|||
Key:[]byte(密钥), |
|||
Timeout:过期时间, |
|||
MaxRefresh: token刷新窗口期 |
|||
IdentityKey: "id" //payload中标识身份的key |
|||
Authenticator:func(r *ghttp.Request)(interface{},error)//回调函数,处理登录验签逻辑 |
|||
} |
|||
//2.注册中间件 |
|||
//3.从token中获取数据 |
|||
_,data:=Auth.GetIdentity(g.RequestFromCtx(ctx)) |
|||
userId:=gconv.Uint64(data(g.Map)["id"]) |
|||
|
|||
|
|||
``` |
|||
|
|||
|
|||
|
|||
## 夺宝奇兵功能 |
|||
|
|||
### 机构动向 |
|||
|
|||
#### --股票估值-- |
|||
|
|||
显示股票当前或上一次收盘的基本信息 |
|||
|
|||
### --当日资金-- |
|||
|
|||
分析资金流入流出方向,列出了主力资金状况、主力吸筹有无、庄散对决情况 |
|||
|
|||
|
|||
|
|||
### AI 预测大模型--股价预测 |
|||
|
|||
展示7项数据:现价、卖出价、买回价,预测高一高二、低一低二 |
|||
|
|||
展示K线图 |
|||
|
|||
功能亮点介绍 |
|||
@ -0,0 +1 @@ |
|||
* linguist-language=GO |
|||
@ -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 |
|||
@ -0,0 +1,7 @@ |
|||
ROOT_DIR = $(shell pwd) |
|||
NAMESPACE = "default" |
|||
DEPLOY_NAME = "template-single" |
|||
DOCKER_NAME = "template-single" |
|||
|
|||
include ./hack/hack-cli.mk |
|||
include ./hack/hack.mk |
|||
@ -0,0 +1,6 @@ |
|||
# GoFrame Template For SingleRepo |
|||
|
|||
Quick Start: |
|||
- https://goframe.org/quick |
|||
|
|||
没做规范化处理目前!! |
|||
@ -0,0 +1,57 @@ |
|||
package user |
|||
|
|||
import ( |
|||
"gf_demo_02/internal/model/entity" |
|||
"github.com/gogf/gf/v2/frame/g" |
|||
) |
|||
|
|||
type LoginReq struct { |
|||
g.Meta `path:"/login" method:"post"` |
|||
Username string |
|||
Password string |
|||
} |
|||
|
|||
type LoginRes struct { |
|||
Token string `json:"token"` //token加签后的字符串
|
|||
} |
|||
|
|||
type GetUserListReq struct { |
|||
g.Meta `path:"/getUsers" method:"get"` |
|||
} |
|||
|
|||
type GetUserListRes struct { |
|||
Users []entity.User `json:"users"` |
|||
} |
|||
|
|||
type EditUserReq struct { |
|||
g.Meta `path:"/admin/user/editUser" method:"post"` |
|||
Id uint `json:"id"` |
|||
Name string `json:"name" v:"required"` |
|||
Property uint `json:"property" v:"between:1,5 #权限必须为1-5"` |
|||
Pass string `json:"pass"` |
|||
} |
|||
|
|||
type EditUserRes struct { |
|||
} |
|||
|
|||
type DeleteUserReq struct { |
|||
g.Meta `path:"/admin/user/delete" method:"delete"` |
|||
Id uint `json:"id" v:"required#缺少用户id"` |
|||
} |
|||
type DeleteUserRes struct{} |
|||
|
|||
type GetSelfReq struct { |
|||
g.Meta `path:"/admin/user/getSelf" method:"get"` |
|||
} |
|||
type GetSelfRes struct { |
|||
User entity.User `json:"user"` |
|||
} |
|||
|
|||
type SearchUserReq struct { |
|||
g.Meta `path:"/admin/user/search" method:"get"` |
|||
Keyword string `json:"keyword" p:"keyword"` |
|||
} |
|||
|
|||
type SearchUserRes struct { |
|||
Users []entity.User `json:"users"` |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
module gf_demo_02 |
|||
|
|||
go 1.21 |
|||
|
|||
toolchain go1.21.13 |
|||
|
|||
require ( |
|||
github.com/dgrijalva/jwt-go v3.2.0+incompatible |
|||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.7.0 |
|||
github.com/gogf/gf/v2 v2.7.0 |
|||
github.com/golang-jwt/jwt/v5 v5.3.1 |
|||
golang.org/x/crypto v0.21.0 |
|||
) |
|||
|
|||
require ( |
|||
github.com/BurntSushi/toml v1.3.2 // indirect |
|||
github.com/clbanning/mxj/v2 v2.7.0 // indirect |
|||
github.com/fatih/color v1.16.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/go-sql-driver/mysql v1.7.1 // indirect |
|||
github.com/gorilla/websocket v1.5.1 // indirect |
|||
github.com/grokify/html-strip-tags-go v0.1.0 // indirect |
|||
github.com/magiconair/properties v1.8.7 // 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.23.0 // indirect |
|||
golang.org/x/sys v0.19.0 // indirect |
|||
golang.org/x/text v0.14.0 // indirect |
|||
gopkg.in/yaml.v3 v3.0.1 // indirect |
|||
) |
|||
@ -0,0 +1,70 @@ |
|||
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= |
|||
github.com/BurntSushi/toml v1.3.2/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/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
|||
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= |
|||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= |
|||
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= |
|||
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= |
|||
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.7.0 h1:5Igvtz4gy5UMvH+Ut4kLIpwSzggV9ZgDVBsIiOctH5E= |
|||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.7.0/go.mod h1:0+flZ0clMKjtH1sTI7YD2KG4FPr8xz0L9h1WMd5M2Z8= |
|||
github.com/gogf/gf/v2 v2.7.0 h1:CjxhbMiE7oqf6K8ZtGuKt3dQEwK4vL6LhiI+dI7tJGU= |
|||
github.com/gogf/gf/v2 v2.7.0/go.mod h1:Qu8nimKt9aupJQcdUL85tWF4Mfxocz97zUt8UC4abVI= |
|||
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY= |
|||
github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE= |
|||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= |
|||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= |
|||
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= |
|||
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= |
|||
github.com/grokify/html-strip-tags-go v0.1.0 h1:03UrQLjAny8xci+R+qjCce/MYnpNXCtgzltlQbOBae4= |
|||
github.com/grokify/html-strip-tags-go v0.1.0/go.mod h1:ZdzgfHEzAfz9X6Xe5eBLVblWIxXfYSQ40S/VKrAOGpc= |
|||
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= |
|||
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= |
|||
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/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= |
|||
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= |
|||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= |
|||
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/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= |
|||
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= |
|||
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= |
|||
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= |
|||
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.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= |
|||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= |
|||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= |
|||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= |
|||
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= |
|||
@ -0,0 +1,13 @@ |
|||
|
|||
# CLI tool, only in development environment. |
|||
# https://goframe.org/docs/cli |
|||
gfcli: |
|||
gen: |
|||
dao: |
|||
- link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test" |
|||
descriptionTag: true |
|||
|
|||
docker: |
|||
build: "-a amd64 -s linux -p temp -ew" |
|||
tagPrefixes: |
|||
- my.image.pub/my-app |
|||
@ -0,0 +1,20 @@ |
|||
|
|||
# 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; |
|||
@ -0,0 +1,75 @@ |
|||
.DEFAULT_GOAL := build |
|||
|
|||
# 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 rev-parse --short HEAD)) |
|||
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: cli.install |
|||
@make image PUSH=-p; |
|||
|
|||
|
|||
# Deploy image and yaml to current kubectl environment.
|
|||
.PHONY: deploy |
|||
deploy: cli.install |
|||
$(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 |
|||
@ -0,0 +1,30 @@ |
|||
package cmd |
|||
|
|||
import ( |
|||
"context" |
|||
"gf_demo_02/internal/controller/user" |
|||
"gf_demo_02/internal/service" |
|||
|
|||
"github.com/gogf/gf/v2/frame/g" |
|||
"github.com/gogf/gf/v2/net/ghttp" |
|||
"github.com/gogf/gf/v2/os/gcmd" |
|||
) |
|||
|
|||
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("/", func(group *ghttp.RouterGroup) { |
|||
group.Middleware(service.CorsMiddleware) |
|||
group.Middleware(ghttp.MiddlewareHandlerResponse) |
|||
group.Middleware(service.JWTMiddleware) |
|||
group.Bind(user.CUser{}) |
|||
}) |
|||
s.Run() |
|||
return nil |
|||
}, |
|||
} |
|||
) |
|||
@ -0,0 +1,3 @@ |
|||
package consts |
|||
|
|||
const TOKEN_KEY = "55558888" |
|||
@ -0,0 +1,98 @@ |
|||
package user |
|||
|
|||
import ( |
|||
"context" |
|||
"gf_demo_02/api/user/v1" |
|||
"gf_demo_02/internal/consts" |
|||
m "gf_demo_02/internal/model" |
|||
"gf_demo_02/internal/model/entity" |
|||
"gf_demo_02/internal/service" |
|||
"github.com/gogf/gf/v2/errors/gcode" |
|||
"github.com/gogf/gf/v2/errors/gerror" |
|||
"github.com/gogf/gf/v2/frame/g" |
|||
jwt "github.com/golang-jwt/jwt/v5" |
|||
"golang.org/x/crypto/bcrypt" |
|||
"time" |
|||
) |
|||
|
|||
type CUser struct{} |
|||
|
|||
func (*CUser) Login(ctx context.Context, req *user.LoginReq) (res *user.LoginRes, err error) { |
|||
model := g.DB().Model("user") |
|||
u := new(entity.User) |
|||
res = new(user.LoginRes) |
|||
err = model.Where("name", req.Username).Scan(&u) |
|||
if err != nil || u.Id == 0 { |
|||
return nil, gerror.NewCode(gcode.New(451, "用户名不存在", nil), "用户名不存在") |
|||
} |
|||
if bcrypt.CompareHashAndPassword([]byte(u.Pass), []byte(req.Password)) != nil { |
|||
return nil, gerror.NewCode(gcode.New(450, "密码错误", nil), "密码错误") |
|||
} |
|||
claims := m.UserClaim{ |
|||
UserId: u.Id, |
|||
UserName: u.Name, |
|||
RegisteredClaims: jwt.RegisteredClaims{ |
|||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(24 * time.Hour)), |
|||
IssuedAt: jwt.NewNumericDate(time.Now()), |
|||
NotBefore: jwt.NewNumericDate(time.Now()), |
|||
Issuer: "我"}, |
|||
} |
|||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) |
|||
tokenStr, err := token.SignedString([]byte(consts.TOKEN_KEY)) |
|||
res.Token = tokenStr |
|||
return res, nil |
|||
} |
|||
|
|||
func (*CUser) GetUserList(ctx context.Context, req *user.GetUserListReq) (res *user.GetUserListRes, err error) { |
|||
users, err := service.User().GetUserList(ctx) |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
res = new(user.GetUserListRes) |
|||
res.Users = users |
|||
return res, nil |
|||
} |
|||
|
|||
func (*CUser) EditUser(ctx context.Context, req *user.EditUserReq) (res *user.EditUserRes, err error) { |
|||
res = new(user.EditUserRes) |
|||
if req.Id == 0 { |
|||
err = service.User().AddUser(ctx, req) |
|||
} else { |
|||
err = service.User().UpdateUser(ctx, req) |
|||
} |
|||
if err != nil { |
|||
return res, err |
|||
} |
|||
return res, nil |
|||
} |
|||
|
|||
func (*CUser) DeleteUser(ctx context.Context, req *user.DeleteUserReq) (res *user.DeleteUserRes, err error) { |
|||
return nil, service.User().DeleteUser(ctx, req) |
|||
} |
|||
|
|||
func (*CUser) GetSelf(ctx context.Context, req *user.GetSelfReq) (res *user.GetSelfRes, err error) { |
|||
r := g.RequestFromCtx(ctx) |
|||
u := r.GetCtxVar("user") |
|||
res = new(user.GetSelfRes) |
|||
err = u.Struct(&res.User) |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
return res, nil |
|||
} |
|||
|
|||
func (*CUser) SearchUser(ctx context.Context, req *user.SearchUserReq) (res *user.SearchUserRes, err error) { |
|||
res = new(user.SearchUserRes) |
|||
if g.IsEmpty(req.Keyword) { |
|||
res.Users, err = service.User().GetUserList(ctx) |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
return res, nil |
|||
} |
|||
res.Users, err = service.User().SearchUser(ctx, req.Keyword) |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
return res, nil |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
// =================================================================================
|
|||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
|||
// =================================================================================
|
|||
|
|||
package dao |
|||
|
|||
import ( |
|||
"gf_demo_02/internal/dao/internal" |
|||
) |
|||
|
|||
// internalCourseDao is internal type for wrapping internal DAO implements.
|
|||
type internalCourseDao = *internal.CourseDao |
|||
|
|||
// courseDao is the data access object for table course.
|
|||
// You can define custom methods on it to extend its functionality as you wish.
|
|||
type courseDao struct { |
|||
internalCourseDao |
|||
} |
|||
|
|||
var ( |
|||
// Course is globally public accessible object for table course operations.
|
|||
Course = courseDao{ |
|||
internal.NewCourseDao(), |
|||
} |
|||
) |
|||
|
|||
// Fill with you ideas below.
|
|||
@ -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" |
|||
) |
|||
|
|||
// CourseDao is the data access object for table course.
|
|||
type CourseDao 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 CourseColumns // columns contains all the column names of Table for convenient usage.
|
|||
} |
|||
|
|||
// CourseColumns defines and stores column names for table course.
|
|||
type CourseColumns struct { |
|||
Id string //
|
|||
Name string //
|
|||
Day string //
|
|||
CreateAt string //
|
|||
UpdateAt string //
|
|||
DeleteAt string //
|
|||
} |
|||
|
|||
// courseColumns holds the columns for table course.
|
|||
var courseColumns = CourseColumns{ |
|||
Id: "id", |
|||
Name: "name", |
|||
Day: "day", |
|||
CreateAt: "create_at", |
|||
UpdateAt: "update_at", |
|||
DeleteAt: "delete_at", |
|||
} |
|||
|
|||
// NewCourseDao creates and returns a new DAO object for table data access.
|
|||
func NewCourseDao() *CourseDao { |
|||
return &CourseDao{ |
|||
group: "default", |
|||
table: "course", |
|||
columns: courseColumns, |
|||
} |
|||
} |
|||
|
|||
// DB retrieves and returns the underlying raw database management object of current DAO.
|
|||
func (dao *CourseDao) DB() gdb.DB { |
|||
return g.DB(dao.group) |
|||
} |
|||
|
|||
// Table returns the table name of current dao.
|
|||
func (dao *CourseDao) Table() string { |
|||
return dao.table |
|||
} |
|||
|
|||
// Columns returns all column names of current dao.
|
|||
func (dao *CourseDao) Columns() CourseColumns { |
|||
return dao.columns |
|||
} |
|||
|
|||
// Group returns the configuration group name of database of current dao.
|
|||
func (dao *CourseDao) Group() string { |
|||
return dao.group |
|||
} |
|||
|
|||
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
|||
func (dao *CourseDao) 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 *CourseDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { |
|||
return dao.Ctx(ctx).Transaction(ctx, f) |
|||
} |
|||
@ -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" |
|||
) |
|||
|
|||
// StockDao is the data access object for table stock.
|
|||
type StockDao 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 StockColumns // columns contains all the column names of Table for convenient usage.
|
|||
} |
|||
|
|||
// StockColumns defines and stores column names for table stock.
|
|||
type StockColumns struct { |
|||
Id string //
|
|||
Name string //
|
|||
Num string //
|
|||
CreateAt string //
|
|||
UpdateAt string //
|
|||
DeleteAt string //
|
|||
} |
|||
|
|||
// stockColumns holds the columns for table stock.
|
|||
var stockColumns = StockColumns{ |
|||
Id: "id", |
|||
Name: "name", |
|||
Num: "num", |
|||
CreateAt: "create_at", |
|||
UpdateAt: "update_at", |
|||
DeleteAt: "delete_at", |
|||
} |
|||
|
|||
// NewStockDao creates and returns a new DAO object for table data access.
|
|||
func NewStockDao() *StockDao { |
|||
return &StockDao{ |
|||
group: "default", |
|||
table: "stock", |
|||
columns: stockColumns, |
|||
} |
|||
} |
|||
|
|||
// DB retrieves and returns the underlying raw database management object of current DAO.
|
|||
func (dao *StockDao) DB() gdb.DB { |
|||
return g.DB(dao.group) |
|||
} |
|||
|
|||
// Table returns the table name of current dao.
|
|||
func (dao *StockDao) Table() string { |
|||
return dao.table |
|||
} |
|||
|
|||
// Columns returns all column names of current dao.
|
|||
func (dao *StockDao) Columns() StockColumns { |
|||
return dao.columns |
|||
} |
|||
|
|||
// Group returns the configuration group name of database of current dao.
|
|||
func (dao *StockDao) Group() string { |
|||
return dao.group |
|||
} |
|||
|
|||
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
|||
func (dao *StockDao) 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 *StockDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { |
|||
return dao.Ctx(ctx).Transaction(ctx, f) |
|||
} |
|||
@ -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 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 user.
|
|||
type UserColumns struct { |
|||
Id string //
|
|||
Name string //
|
|||
Pass string //
|
|||
Property string //
|
|||
CreateAt string //
|
|||
DeleteAt string //
|
|||
UpdateAt string //
|
|||
} |
|||
|
|||
// userColumns holds the columns for table user.
|
|||
var userColumns = UserColumns{ |
|||
Id: "id", |
|||
Name: "name", |
|||
Pass: "pass", |
|||
Property: "property", |
|||
CreateAt: "create_at", |
|||
DeleteAt: "delete_at", |
|||
UpdateAt: "update_at", |
|||
} |
|||
|
|||
// NewUserDao creates and returns a new DAO object for table data access.
|
|||
func NewUserDao() *UserDao { |
|||
return &UserDao{ |
|||
group: "default", |
|||
table: "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) |
|||
} |
|||
@ -0,0 +1,75 @@ |
|||
// ==========================================================================
|
|||
// 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" |
|||
) |
|||
|
|||
// UserCourseDao is the data access object for table user_course.
|
|||
type UserCourseDao 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 UserCourseColumns // columns contains all the column names of Table for convenient usage.
|
|||
} |
|||
|
|||
// UserCourseColumns defines and stores column names for table user_course.
|
|||
type UserCourseColumns struct { |
|||
Uid string //
|
|||
Cid string //
|
|||
} |
|||
|
|||
// userCourseColumns holds the columns for table user_course.
|
|||
var userCourseColumns = UserCourseColumns{ |
|||
Uid: "uid", |
|||
Cid: "cid", |
|||
} |
|||
|
|||
// NewUserCourseDao creates and returns a new DAO object for table data access.
|
|||
func NewUserCourseDao() *UserCourseDao { |
|||
return &UserCourseDao{ |
|||
group: "default", |
|||
table: "user_course", |
|||
columns: userCourseColumns, |
|||
} |
|||
} |
|||
|
|||
// DB retrieves and returns the underlying raw database management object of current DAO.
|
|||
func (dao *UserCourseDao) DB() gdb.DB { |
|||
return g.DB(dao.group) |
|||
} |
|||
|
|||
// Table returns the table name of current dao.
|
|||
func (dao *UserCourseDao) Table() string { |
|||
return dao.table |
|||
} |
|||
|
|||
// Columns returns all column names of current dao.
|
|||
func (dao *UserCourseDao) Columns() UserCourseColumns { |
|||
return dao.columns |
|||
} |
|||
|
|||
// Group returns the configuration group name of database of current dao.
|
|||
func (dao *UserCourseDao) Group() string { |
|||
return dao.group |
|||
} |
|||
|
|||
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
|||
func (dao *UserCourseDao) 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 *UserCourseDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { |
|||
return dao.Ctx(ctx).Transaction(ctx, f) |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
// =================================================================================
|
|||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
|||
// =================================================================================
|
|||
|
|||
package dao |
|||
|
|||
import ( |
|||
"gf_demo_02/internal/dao/internal" |
|||
) |
|||
|
|||
// internalStockDao is internal type for wrapping internal DAO implements.
|
|||
type internalStockDao = *internal.StockDao |
|||
|
|||
// stockDao is the data access object for table stock.
|
|||
// You can define custom methods on it to extend its functionality as you wish.
|
|||
type stockDao struct { |
|||
internalStockDao |
|||
} |
|||
|
|||
var ( |
|||
// Stock is globally public accessible object for table stock operations.
|
|||
Stock = stockDao{ |
|||
internal.NewStockDao(), |
|||
} |
|||
) |
|||
|
|||
// Fill with you ideas below.
|
|||
@ -0,0 +1,27 @@ |
|||
// =================================================================================
|
|||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
|||
// =================================================================================
|
|||
|
|||
package dao |
|||
|
|||
import ( |
|||
"gf_demo_02/internal/dao/internal" |
|||
) |
|||
|
|||
// internalUserDao is internal type for wrapping internal DAO implements.
|
|||
type internalUserDao = *internal.UserDao |
|||
|
|||
// userDao is the data access object for table user.
|
|||
// You can define custom methods on it to extend its functionality as you wish.
|
|||
type userDao struct { |
|||
internalUserDao |
|||
} |
|||
|
|||
var ( |
|||
// User is globally public accessible object for table user operations.
|
|||
User = userDao{ |
|||
internal.NewUserDao(), |
|||
} |
|||
) |
|||
|
|||
// Fill with you ideas below.
|
|||
@ -0,0 +1,27 @@ |
|||
// =================================================================================
|
|||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
|||
// =================================================================================
|
|||
|
|||
package dao |
|||
|
|||
import ( |
|||
"gf_demo_02/internal/dao/internal" |
|||
) |
|||
|
|||
// internalUserCourseDao is internal type for wrapping internal DAO implements.
|
|||
type internalUserCourseDao = *internal.UserCourseDao |
|||
|
|||
// userCourseDao is the data access object for table user_course.
|
|||
// You can define custom methods on it to extend its functionality as you wish.
|
|||
type userCourseDao struct { |
|||
internalUserCourseDao |
|||
} |
|||
|
|||
var ( |
|||
// UserCourse is globally public accessible object for table user_course operations.
|
|||
UserCourse = userCourseDao{ |
|||
internal.NewUserCourseDao(), |
|||
} |
|||
) |
|||
|
|||
// Fill with you ideas below.
|
|||
@ -0,0 +1,12 @@ |
|||
package course |
|||
|
|||
import ( |
|||
"context" |
|||
"gf_demo_02/internal/model" |
|||
"github.com/gogf/gf/v2/frame/g" |
|||
) |
|||
|
|||
func GetCourses(ctx context.Context) (courses []model.CourseWithUsers, err error) { |
|||
g.Redis().HGetAll() |
|||
g.Dump() |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
// ==========================================================================
|
|||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
|||
// ==========================================================================
|
|||
|
|||
package logic |
|||
|
|||
import ( |
|||
_ "gf_demo_02/internal/logic/user" |
|||
) |
|||
@ -0,0 +1,143 @@ |
|||
package user |
|||
|
|||
import ( |
|||
"context" |
|||
"gf_demo_02/api/user/v1" |
|||
"gf_demo_02/internal/model/entity" |
|||
"gf_demo_02/internal/service" |
|||
"github.com/gogf/gf/v2/database/gdb" |
|||
"github.com/gogf/gf/v2/errors/gcode" |
|||
"github.com/gogf/gf/v2/errors/gerror" |
|||
"github.com/gogf/gf/v2/frame/g" |
|||
"github.com/gogf/gf/v2/util/gconv" |
|||
"golang.org/x/crypto/bcrypt" |
|||
"strings" |
|||
) |
|||
|
|||
type sUser struct { |
|||
} |
|||
|
|||
func init() { |
|||
service.RegisterUser(&sUser{}) |
|||
} |
|||
|
|||
func (u *sUser) GetUser(cond g.Map) (user *entity.User, err error) { |
|||
model := g.Model("user") |
|||
if cond["id"] != nil && gconv.Uint(cond["id"]) != 0 { |
|||
model = model.Where("id", cond["id"]) |
|||
} else if cond["name"] != nil && gconv.String(cond["name"]) != "" { |
|||
model = model.Where("name", cond["name"]) |
|||
} else { |
|||
return nil, gerror.NewCode(gcode.New(88, "缺少查询条件", nil)) |
|||
} |
|||
err = model.Scan(&user) |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
if user == nil { |
|||
return nil, gerror.NewCode(gcode.New(483, "用户不存在!", nil)) |
|||
} |
|||
return user, nil |
|||
} |
|||
|
|||
func (*sUser) GetUserList(ctx context.Context) (users []entity.User, err error) { |
|||
all, err := g.DB().Model("user").All() |
|||
if err != nil { |
|||
return nil, gerror.NewCode(gcode.New(599, "数据库error", nil)) |
|||
} |
|||
err = all.Structs(&users) |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
return users, nil |
|||
} |
|||
|
|||
func (*sUser) AddUser(ctx context.Context, req *user.EditUserReq) error { |
|||
u := entity.User{ |
|||
Id: req.Id, |
|||
Name: req.Name, |
|||
Pass: req.Pass, |
|||
Property: req.Property, |
|||
} |
|||
one, _ := g.Model("user").Where("name", req.Name).One() |
|||
if one != nil { |
|||
return gerror.NewCode(gcode.New(480, "用户名重复", nil)) |
|||
} |
|||
if len(req.Pass) < 6 { |
|||
return gerror.NewCode(gcode.New(481, "密码过短,至少6位", nil)) |
|||
} |
|||
password, err := bcrypt.GenerateFromPassword([]byte(u.Pass), 10) |
|||
if err != nil { |
|||
return err |
|||
} |
|||
u.Pass = string(password) |
|||
return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error { |
|||
_, err = tx.Model("user").Insert(u) |
|||
return err |
|||
}) |
|||
} |
|||
|
|||
func (*sUser) UpdateUser(ctx context.Context, req *user.EditUserReq) error { |
|||
u := entity.User{ |
|||
Id: req.Id, |
|||
Name: req.Name, |
|||
Pass: req.Pass, |
|||
Property: req.Property, |
|||
} |
|||
one, _ := g.Model("user").Where("id", req.Id).One() |
|||
if one == nil { |
|||
return gerror.NewCode(gcode.New(483, "用户不存在!", nil)) |
|||
} |
|||
one, _ = g.Model("user").Where("name", req.Name).WhereNot("id", u.Id).One() |
|||
if one != nil { |
|||
return gerror.NewCode(gcode.New(480, "用户名重复", nil)) |
|||
} |
|||
if len(req.Pass) < 6 && req.Pass != "" { |
|||
return gerror.NewCode(gcode.New(481, "密码过短,至少6位", nil)) |
|||
} |
|||
if req.Pass != "" { |
|||
password, err := bcrypt.GenerateFromPassword([]byte(u.Pass), 10) |
|||
if err != nil { |
|||
return err |
|||
} |
|||
u.Pass = string(password) |
|||
} |
|||
return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error { |
|||
model := tx.Model("user").OmitEmptyData() |
|||
result, err := model.Where("id", u.Id).Update(u) |
|||
if err != nil { |
|||
return err |
|||
} |
|||
if affected, err := result.RowsAffected(); affected < 1 || err != nil { |
|||
return gerror.NewCode(gcode.New(500, "服务器错误", nil)) |
|||
} |
|||
return nil |
|||
}) |
|||
} |
|||
|
|||
func (*sUser) DeleteUser(ctx context.Context, req *user.DeleteUserReq) error { |
|||
one, _ := g.DB().Model("user").Where("id", req.Id).One() |
|||
if one == nil { |
|||
return gerror.NewCode(gcode.New(483, "用户不存在!", nil)) |
|||
} |
|||
tokenStr := g.RequestFromCtx(ctx).GetCtxVar("Authorization").String() |
|||
tokenStr = strings.TrimSpace(tokenStr) |
|||
tokenStr = strings.TrimPrefix(tokenStr, "Bearer ") |
|||
return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error { |
|||
_, err := tx.Model("user").Where("id", req.Id).Delete() |
|||
return err |
|||
}) |
|||
} |
|||
|
|||
func (*sUser) SearchUser(ctx context.Context, keyword string) ([]entity.User, error) { |
|||
all, err := g.Model("user").WhereLike("name", "%"+keyword+"%").All() |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
users := make([]entity.User, 0) |
|||
err = all.Structs(&users) |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
return users, nil |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
package model |
|||
|
|||
import "github.com/golang-jwt/jwt/v5" |
|||
|
|||
type UserClaim struct { |
|||
UserId uint |
|||
UserName string |
|||
jwt.RegisteredClaims |
|||
} |
|||
@ -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" |
|||
) |
|||
|
|||
// Course is the golang structure of table course for DAO operations like Where/Data.
|
|||
type Course struct { |
|||
g.Meta `orm:"table:course, do:true"` |
|||
Id interface{} //
|
|||
Name interface{} //
|
|||
Day interface{} //
|
|||
CreateAt *gtime.Time //
|
|||
UpdateAt *gtime.Time //
|
|||
DeleteAt *gtime.Time //
|
|||
} |
|||
@ -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" |
|||
) |
|||
|
|||
// Stock is the golang structure of table stock for DAO operations like Where/Data.
|
|||
type Stock struct { |
|||
g.Meta `orm:"table:stock, do:true"` |
|||
Id interface{} //
|
|||
Name interface{} //
|
|||
Num interface{} //
|
|||
CreateAt *gtime.Time //
|
|||
UpdateAt *gtime.Time //
|
|||
DeleteAt *gtime.Time //
|
|||
} |
|||
@ -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" |
|||
) |
|||
|
|||
// User is the golang structure of table user for DAO operations like Where/Data.
|
|||
type User struct { |
|||
g.Meta `orm:"table:user, do:true"` |
|||
Id interface{} //
|
|||
Name interface{} //
|
|||
Pass interface{} //
|
|||
Property interface{} //
|
|||
CreateAt *gtime.Time //
|
|||
DeleteAt *gtime.Time //
|
|||
UpdateAt *gtime.Time //
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
// =================================================================================
|
|||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
|||
// =================================================================================
|
|||
|
|||
package do |
|||
|
|||
import ( |
|||
"github.com/gogf/gf/v2/frame/g" |
|||
) |
|||
|
|||
// UserCourse is the golang structure of table user_course for DAO operations like Where/Data.
|
|||
type UserCourse struct { |
|||
g.Meta `orm:"table:user_course, do:true"` |
|||
Uid interface{} //
|
|||
Cid interface{} //
|
|||
} |
|||
@ -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" |
|||
) |
|||
|
|||
// Course is the golang structure for table course.
|
|||
type Course struct { |
|||
Id uint `json:"id" orm:"id" ` //
|
|||
Name string `json:"name" orm:"name" ` //
|
|||
Day string `json:"day" orm:"day" ` //
|
|||
CreateAt *gtime.Time `json:"createAt" orm:"create_at" ` //
|
|||
UpdateAt *gtime.Time `json:"updateAt" orm:"update_at" ` //
|
|||
DeleteAt *gtime.Time `json:"deleteAt" orm:"delete_at" ` //
|
|||
} |
|||
@ -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" |
|||
) |
|||
|
|||
// Stock is the golang structure for table stock.
|
|||
type Stock struct { |
|||
Id uint `json:"id" orm:"id" ` //
|
|||
Name string `json:"name" orm:"name" ` //
|
|||
Num uint `json:"num" orm:"num" ` //
|
|||
CreateAt *gtime.Time `json:"createAt" orm:"create_at" ` //
|
|||
UpdateAt *gtime.Time `json:"updateAt" orm:"update_at" ` //
|
|||
DeleteAt *gtime.Time `json:"deleteAt" orm:"delete_at" ` //
|
|||
} |
|||
@ -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" |
|||
) |
|||
|
|||
// User is the golang structure for table user.
|
|||
type User struct { |
|||
Id uint `json:"id" orm:"id" ` //
|
|||
Name string `json:"name" orm:"name" ` //
|
|||
Pass string `json:"pass" orm:"pass" ` //
|
|||
Property uint `json:"property" orm:"property" ` //
|
|||
CreateAt *gtime.Time `json:"createAt" orm:"create_at" ` //
|
|||
DeleteAt *gtime.Time `json:"deleteAt" orm:"delete_at" ` //
|
|||
UpdateAt *gtime.Time `json:"updateAt" orm:"update_at" ` //
|
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
// =================================================================================
|
|||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
|||
// =================================================================================
|
|||
|
|||
package entity |
|||
|
|||
// UserCourse is the golang structure for table user_course.
|
|||
type UserCourse struct { |
|||
Uid uint `json:"uid" orm:"uid" ` //
|
|||
Cid uint `json:"cid" orm:"cid" ` //
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
package model |
|||
|
|||
import ( |
|||
"gf_demo_02/internal/model/entity" |
|||
"github.com/gogf/gf/v2/os/gtime" |
|||
) |
|||
|
|||
type CourseWithUsers struct { |
|||
Id uint `json:"id" orm:"id" ` //
|
|||
Name string `json:"name" orm:"name" ` //
|
|||
Day string `json:"day" orm:"day" ` //
|
|||
CreateAt *gtime.Time `json:"createAt" orm:"create_at" ` //
|
|||
UpdateAt *gtime.Time `json:"updateAt" orm:"update_at" ` //
|
|||
DeleteAt *gtime.Time `json:"deleteAt" orm:"delete_at" ` |
|||
Users []entity.User `json:"users"` |
|||
} |
|||
@ -0,0 +1 @@ |
|||
package packed |
|||
@ -0,0 +1,65 @@ |
|||
package service |
|||
|
|||
import ( |
|||
"fmt" |
|||
"gf_demo_02/internal/consts" |
|||
"gf_demo_02/internal/model" |
|||
"strings" |
|||
|
|||
"github.com/gogf/gf/v2/frame/g" |
|||
"github.com/gogf/gf/v2/net/ghttp" |
|||
"github.com/golang-jwt/jwt/v5" |
|||
) |
|||
|
|||
func JWTMiddleware(r *ghttp.Request) { |
|||
url := r.GetUrl() |
|||
if strings.HasSuffix(url, "/login") || strings.HasSuffix(url, "/loginPage") { |
|||
r.Middleware.Next() |
|||
return |
|||
} |
|||
tokenStr := r.Header.Get("Authorization") |
|||
tokenStr = strings.TrimSpace(tokenStr) |
|||
tokenStr = strings.TrimPrefix(tokenStr, "Bearer ") |
|||
if g.IsEmpty(tokenStr) { |
|||
r.Response.WriteStatus(401, "no token") |
|||
return |
|||
} |
|||
token, err := jwt.ParseWithClaims(tokenStr, &model.UserClaim{}, func(token *jwt.Token) (interface{}, error) { |
|||
_, ok := token.Method.(*jwt.SigningMethodHMAC) |
|||
if !ok { |
|||
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) |
|||
} |
|||
return []byte(consts.TOKEN_KEY), nil |
|||
}) |
|||
if err != nil { |
|||
r.Response.WriteStatus(401, "token invalid") |
|||
return |
|||
} |
|||
claim, ok := token.Claims.(*model.UserClaim) |
|||
if !ok || !token.Valid { |
|||
r.Response.WriteStatus(401, "token invalid") |
|||
return |
|||
} |
|||
id := claim.UserId |
|||
name := claim.UserName |
|||
cond := g.Map{ |
|||
"id": id, |
|||
"name": name, |
|||
} |
|||
user, err := User().GetUser(cond) |
|||
if err != nil || user == nil { |
|||
r.Response.WriteStatus(401, "token invalid") |
|||
return |
|||
} |
|||
if user.Id != id || user.Name != name { |
|||
r.Response.WriteStatus(401, "token invalid") |
|||
return |
|||
} |
|||
r.SetCtxVar("user", user) |
|||
r.Middleware.Next() |
|||
} |
|||
|
|||
func CorsMiddleware(r *ghttp.Request) { |
|||
r.Response.CORSDefault() |
|||
r.Middleware.Next() |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
package service |
|||
|
|||
import ( |
|||
"fmt" |
|||
|
|||
"golang.org/x/crypto/bcrypt" |
|||
) |
|||
|
|||
// bcrypt加密
|
|||
func encode() { |
|||
password, err := bcrypt.GenerateFromPassword([]byte("123"), 10) |
|||
if err != nil { |
|||
panic(err) |
|||
} |
|||
fmt.Println(string(password)) |
|||
err = bcrypt.CompareHashAndPassword(password, []byte("123")) |
|||
if err != nil { |
|||
panic(err) |
|||
} |
|||
fmt.Println("correct") |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
package service |
|||
|
|||
import "testing" |
|||
|
|||
func TestEncode(T *testing.T) { |
|||
encode() |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
// ================================================================================
|
|||
// 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" |
|||
"gf_demo_02/api/user/v1" |
|||
"gf_demo_02/internal/model/entity" |
|||
|
|||
"github.com/gogf/gf/v2/frame/g" |
|||
) |
|||
|
|||
type ( |
|||
IUser interface { |
|||
GetUser(cond g.Map) (user *entity.User, err error) |
|||
GetUserList(ctx context.Context) (users []entity.User, err error) |
|||
AddUser(ctx context.Context, req *user.EditUserReq) error |
|||
UpdateUser(ctx context.Context, req *user.EditUserReq) error |
|||
DeleteUser(ctx context.Context, req *user.DeleteUserReq) error |
|||
SearchUser(ctx context.Context, keyword string) ([]entity.User, error) |
|||
} |
|||
) |
|||
|
|||
var ( |
|||
localUser IUser |
|||
) |
|||
|
|||
func User() IUser { |
|||
if localUser == nil { |
|||
panic("implement not found for interface IUser, forgot register?") |
|||
} |
|||
return localUser |
|||
} |
|||
|
|||
func RegisterUser(i IUser) { |
|||
localUser = i |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
package main |
|||
|
|||
import ( |
|||
_ "gf_demo_02/internal/packed" |
|||
|
|||
_ "gf_demo_02/internal/logic" |
|||
|
|||
"github.com/gogf/gf/v2/os/gctx" |
|||
|
|||
"gf_demo_02/internal/cmd" |
|||
|
|||
_ "github.com/gogf/gf/contrib/drivers/mysql/v2" |
|||
) |
|||
|
|||
func main() { |
|||
cmd.Main.Run(gctx.GetInitCtx()) |
|||
} |
|||
@ -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 |
|||
|
|||
@ -0,0 +1,8 @@ |
|||
apiVersion: kustomize.config.k8s.io/v1beta1 |
|||
kind: Kustomization |
|||
resources: |
|||
- deployment.yaml |
|||
- 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 |
|||
|
|||
@ -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 |
|||
@ -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 |
|||
|
|||
|
|||
|
|||
@ -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 |
|||
@ -0,0 +1,8 @@ |
|||
#!/bin/bash |
|||
|
|||
# This shell is executed before docker build. |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
@ -0,0 +1,8 @@ |
|||
[*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue,css,scss,sass,less,styl}] |
|||
charset = utf-8 |
|||
indent_size = 2 |
|||
indent_style = space |
|||
insert_final_newline = true |
|||
trim_trailing_whitespace = true |
|||
end_of_line = lf |
|||
max_line_length = 100 |
|||
@ -0,0 +1 @@ |
|||
* text=auto eol=lf |
|||
@ -0,0 +1,42 @@ |
|||
# Logs |
|||
logs |
|||
*.log |
|||
npm-debug.log* |
|||
yarn-debug.log* |
|||
yarn-error.log* |
|||
pnpm-debug.log* |
|||
lerna-debug.log* |
|||
|
|||
node_modules |
|||
.DS_Store |
|||
dist |
|||
dist-ssr |
|||
coverage |
|||
*.local |
|||
|
|||
# Editor directories and files |
|||
.vscode/* |
|||
!.vscode/extensions.json |
|||
.idea |
|||
*.suo |
|||
*.ntvs* |
|||
*.njsproj |
|||
*.sln |
|||
*.sw? |
|||
|
|||
*.tsbuildinfo |
|||
|
|||
.eslintcache |
|||
|
|||
# Cypress |
|||
/cypress/videos/ |
|||
/cypress/screenshots/ |
|||
|
|||
# Vitest |
|||
__screenshots__/ |
|||
|
|||
# Vite |
|||
*.timestamp-*-*.mjs |
|||
|
|||
test-results/ |
|||
playwright-report/ |
|||
@ -0,0 +1,10 @@ |
|||
{ |
|||
"$schema": "./node_modules/oxlint/configuration_schema.json", |
|||
"plugins": ["eslint", "typescript", "unicorn", "oxc", "vue", "vitest"], |
|||
"env": { |
|||
"browser": true |
|||
}, |
|||
"categories": { |
|||
"correctness": "error" |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
{ |
|||
"$schema": "https://json.schemastore.org/prettierrc", |
|||
"semi": false, |
|||
"singleQuote": true, |
|||
"printWidth": 100 |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
{ |
|||
"recommendations": [ |
|||
"Vue.volar", |
|||
"vitest.explorer", |
|||
"ms-playwright.playwright", |
|||
"dbaeumer.vscode-eslint", |
|||
"EditorConfig.EditorConfig", |
|||
"oxc.oxc-vscode", |
|||
"esbenp.prettier-vscode" |
|||
] |
|||
} |
|||