更换热重载工具为air

This commit is contained in:
2024-10-26 05:54:32 +08:00
parent 61c2840612
commit 925f1f4b3b
5 changed files with 15 additions and 91 deletions

View File

@@ -1,13 +1,12 @@
# 运行本地开发环境(使用SSH隧道代理端口)
dev:
@if ! go list -m github.com/gravityblast/fresh >/dev/null 2>&1; then \
echo "github.com/gravityblast/fresh is not installed. Installing..."; \
go get github.com/gravityblast/fresh; \
@if ! go list -m github.com/air-verse/air@latest >/dev/null 2>&1; then \
echo "github.com/air-verse/air@latest is not installed. Installing..."; \
go get github.com/air-verse/air@latest; \
fi;
@ssh -NCPf main -L 3306:localhost:3306 -L 19530:localhost:19530 & \
sleep 1; \
echo "Starting Go application..."; \
go run github.com/gravityblast/fresh; \
go run github.com/air-verse/air@latest --build.cmd "go build -o ./data/ bin/main.go" --build.bin "./data/main"; \
wait
# 编译项目

View File

@@ -8,12 +8,6 @@
- [ ] 列表翻页
GraphQL 基本规则
- 必须指定要求返回的每个字段, 不指定的字段不会被返回, 用于减少无效查询
- 通过 after before 作为游标翻页, 返回指定id之前或之后的列表, 而不是使用 pageNum, 作用是防止列表变化导致翻页请求结果的部分重复
- 通过 first last 替代 pageSize 决定选择游标前n个还是游标后的n个列表
```javascript
// GET 查询id为1的用户列表, 要求列表中每项只返回 id, 用户名, 头像, 以及符合筛选条件的总数 total
const query = `/api?query={users(id:1){total,list{id,user_name,avatar}}}`
@@ -42,7 +36,6 @@ fetch(query).then(res => res.json()).then(data => {
```
### 流媒体
通过流媒体服务降低视频文件加载消耗及防止恶意刷流量
对视频地址添加有效期, 过期需由服务器重新提供token认证观众身份

View File

@@ -250,6 +250,7 @@ func NewSchema(config Config) (graphql.Schema, error) {
// 筛选条件
var where []string
var order []string
for arg, format := range argToSQLFormat {
if p.Args[arg] != nil {
where = append(where, fmt.Sprintf(format, p.Args[arg]))
@@ -273,7 +274,8 @@ func NewSchema(config Config) (graphql.Schema, error) {
if ids_str == "" {
return map[string]interface{}{"list": []Image{}, "total": 0}, nil
}
where = append(where, fmt.Sprintf("id IN (%s) LIMIT %d", ids_str, len(id_list)))
where = append(where, fmt.Sprintf("id IN (%s)", ids_str))
order = append(order, fmt.Sprintf("ORDER BY FIELD(id,%s)", ids_str))
}
// 特殊处理 text 参数
@@ -310,6 +312,7 @@ func NewSchema(config Config) (graphql.Schema, error) {
}
where_str := strings.Join(where, " AND ")
order_str := strings.Join(order, "")
if where_str != "" {
where_str = "WHERE " + where_str
@@ -332,23 +335,23 @@ func NewSchema(config Config) (graphql.Schema, error) {
offset = len(id_list) - limit
}
where_str += fmt.Sprintf(" LIMIT %d OFFSET %d", limit, offset)
// 执行查询
var query strings.Builder
fields := strings.Join(get_fields(p.Info.FieldASTs[0].SelectionSet.Selections), ",")
query.WriteString(fmt.Sprintf("SELECT %s FROM web_images %s", fields, where_str))
query.WriteString(fmt.Sprintf("SELECT %s FROM web_images %s %s LIMIT %d OFFSET %d", fields, where_str, order_str, limit, offset))
var images ImageList
if err := connection.Select(&images, query.String()); err != nil {
var q = query.String()
fmt.Println(q)
if err := connection.Select(&images, q); err != nil {
fmt.Println("获取图像列表失败", err)
return nil, err
}
// 按照 id_list 的顺序重新排序
if len(id_list) > 0 {
images.SortByIDList(id_list)
}
//if len(id_list) > 0 {
// images.SortByIDList(id_list)
//}
// 获取用户信息(如果图像列表不为空且请求字段中包含user)
if len(images) > 0 && strings.Contains(fields, "user") {

View File

@@ -237,68 +237,6 @@ func main() {
Pretty: false,
})))
http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
http.Error(w, "Not Found", http.StatusNotFound)
})
http.HandleFunc("/api/default", func(w http.ResponseWriter, r *http.Request) {
defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
http.Error(w, "Not Found", http.StatusNotFound)
})
// 获取浏览记录
http.HandleFunc("/history", func(w http.ResponseWriter, r *http.Request) {
defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
// 按会话过滤
// 按用户过滤
// 按时间过滤
// 按类型过滤
// 按数据过滤
// 日志记录器:
// 会话记录, 调取也从SDK本地取数据
// URL变化或新开 [URL, 来源, 时间]
// 针对某些组件挂载的事件 [组件, 事件, 时间]
// 记录用户行为 [用户, 行为, 时间]
// 查看过的[图片, 文章, 精选集, 用户]
// 请求过的API连接
// 展示了的数据
// 展示后被点击的数据(+正反馈)
// 展示后被收藏的数据
// 展示后被分享的数据
// 展示后被评论的数据
// 展示后被点赞的数据
// 展示后被下载的数据
// 展示后被忽略的数据(+负反馈)
// 展示后被屏蔽的数据(+屏蔽功能)
// 获取用户id
userId := stringToInt(r.URL.Query().Get("user_id"), 0)
if userId == 0 {
w.Write([]byte("user_id is required"))
return
}
// 获取图片id列表
var ids []int64
err := json.Unmarshal([]byte(r.URL.Query().Get("ids")), &ids)
if err != nil {
w.Write([]byte("ids is required"))
return
}
// 获取图片信息列表
var images []Image
//mysqlConnection.DB.Where("id in (?)", ids).Find(&images)
// 返回结果
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(images)
})
// 获取图片信息列表(分页)
http.HandleFunc("/api/images", func(w http.ResponseWriter, r *http.Request) {
defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志

View File

@@ -1,9 +0,0 @@
root: ./bin
tmp_path: ./data
build_name: bin/main
build_log: runner-build-errors.log
valid_ext: .go, .tpl, .tmpl, .html
no_rebuild_ext: .tpl, .tmpl, .html
ignored: assets, tmp
build_delay: 600
colors: 1