bot 类型 添加 删除 校验
This commit is contained in:
parent
a509d108d4
commit
e53ca6a47f
@ -1,48 +1,42 @@
|
|||||||
# 工作目录
|
|
||||||
# 使用 . 或绝对路径,请注意 `tmp_dir` 目录必须在 `root` 目录下
|
|
||||||
root = "."
|
root = "."
|
||||||
|
testdata_dir = "testdata"
|
||||||
tmp_dir = "tmp"
|
tmp_dir = "tmp"
|
||||||
|
|
||||||
[build]
|
[build]
|
||||||
# 只需要写你平常编译使用的shell命令。你也可以使用 `make`
|
args_bin = []
|
||||||
# Windows平台示例: cmd = "go build -o tmp\main.exe ."
|
bin = "tmp\\main.exe"
|
||||||
cmd = "go build -o ./tmp/main ."
|
cmd = "go build -o ./tmp/main.exe ."
|
||||||
|
delay = 1500
|
||||||
# 由`cmd`命令得到的二进制文件名
|
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
|
||||||
# Windows平台示例:bin = "tmp\main.exe"
|
exclude_file = []
|
||||||
bin = "tmp/main"
|
exclude_regex = ["_test.go"]
|
||||||
|
exclude_unchanged = false
|
||||||
# 自定义执行程序的命令,可以添加额外的编译标识例如添加 GIN_MODE=release
|
follow_symlink = false
|
||||||
# Windows平台示例:full_bin = "tmp\main.exe"
|
full_bin = ""
|
||||||
#full_bin = "APP_ENV=dev APP_USER=air ./tmp/main"
|
include_dir = []
|
||||||
full_bin = "tmp/main
|
include_ext = ["go", "tpl", "tmpl", "html"]
|
||||||
|
include_file = []
|
||||||
# 监听以下文件扩展名的文件.
|
kill_delay = "0s"
|
||||||
include_ext = ["go", "tpl", "tmpl", "html"]
|
log = "build-errors.log"
|
||||||
# 忽略这些文件扩展名或目录
|
rerun = false
|
||||||
exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules"]
|
rerun_delay = 500
|
||||||
# 监听以下指定目录的文件
|
send_interrupt = true
|
||||||
include_dir = []
|
stop_on_error = false
|
||||||
# 排除以下文件
|
|
||||||
exclude_file = []
|
|
||||||
# 如果文件更改过于频繁,则没有必要在每次更改时都触发构建。可以设置触发构建的延迟时间
|
|
||||||
delay = 1000 # ms
|
|
||||||
# 发生构建错误时,停止运行旧的二进制文件。
|
|
||||||
stop_on_error = true
|
|
||||||
# air的日志文件名,该日志文件放置在你的`tmp_dir`中
|
|
||||||
log = "air_errors.log"
|
|
||||||
|
|
||||||
[log]
|
|
||||||
# 显示日志时间
|
|
||||||
time = true
|
|
||||||
|
|
||||||
[color]
|
[color]
|
||||||
# 自定义每个部分显示的颜色。如果找不到颜色,使用原始的应用程序日志。
|
app = ""
|
||||||
main = "magenta"
|
build = "yellow"
|
||||||
watcher = "cyan"
|
main = "magenta"
|
||||||
build = "yellow"
|
runner = "green"
|
||||||
runner = "green"
|
watcher = "cyan"
|
||||||
|
|
||||||
|
[log]
|
||||||
|
main_only = false
|
||||||
|
time = false
|
||||||
|
|
||||||
[misc]
|
[misc]
|
||||||
# 退出时删除tmp目录
|
clean_on_exit = false
|
||||||
clean_on_exit = true
|
|
||||||
|
[screen]
|
||||||
|
clear_on_rebuild = false
|
||||||
|
keep_scroll = true
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="CodeStream">
|
<component name="CodeStream">
|
||||||
<option name="webViewContext" value="{"chatProviderAccess":"strict","currentTeamId":"","currentStreamId":"","pullRequestCheckoutBranch":false,"isRepositioning":false,"onboardStep":0,"panelStack":["landing-redirect"],"hasFocus":false,"channelFilter":"all","channelsMuteAll":false,"codemarkFileFilter":"all","codemarkTypeFilter":"all","codemarkTagFilter":"all","codemarkBranchFilter":"all","codemarkAuthorFilter":"all","codemarksFileViewStyle":"inline","codemarksShowArchived":false,"codemarksShowResolved":false,"codemarksWrapComments":false,"showFeedbackSmiley":true,"route":{"name":"newUserEntry","params":{}},"spatialViewShowPRComments":false,"currentPullRequestNeedsRefresh":{"needsRefresh":false,"providerId":"","pullRequestId":""},"__teamless__":{"selectedRegion":"us"},"sessionStart":1677477984122}" />
|
<option name="webViewContext" value="{"chatProviderAccess":"strict","currentTeamId":"","currentStreamId":"","pullRequestCheckoutBranch":false,"isRepositioning":false,"onboardStep":0,"panelStack":["landing-redirect"],"hasFocus":false,"channelFilter":"all","channelsMuteAll":false,"codemarkFileFilter":"all","codemarkTypeFilter":"all","codemarkTagFilter":"all","codemarkBranchFilter":"all","codemarkAuthorFilter":"all","codemarksFileViewStyle":"inline","codemarksShowArchived":false,"codemarksShowResolved":false,"codemarksWrapComments":false,"showFeedbackSmiley":true,"route":{"name":"newUserEntry","params":{}},"spatialViewShowPRComments":false,"currentPullRequestNeedsRefresh":{"needsRefresh":false,"providerId":"","pullRequestId":""},"__teamless__":{"selectedRegion":"us"},"sessionStart":1677493609591}" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -23,6 +23,108 @@ const docTemplate = `{
|
|||||||
"host": "{{.Host}}",
|
"host": "{{.Host}}",
|
||||||
"basePath": "{{.BasePath}}",
|
"basePath": "{{.BasePath}}",
|
||||||
"paths": {
|
"paths": {
|
||||||
|
"/bot/type/add": {
|
||||||
|
"post": {
|
||||||
|
"description": "添加 bot 类型",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"BotType"
|
||||||
|
],
|
||||||
|
"summary": "添加 bot 类型",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "bot 类型",
|
||||||
|
"name": "vo",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/bottype.AddBotTypeDto"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/resp.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"type": "boolean"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"description": "",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/errorx.CodeErrorResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/bot/type/del": {
|
||||||
|
"delete": {
|
||||||
|
"description": "根据 id 删除 bot 类型",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"BotType"
|
||||||
|
],
|
||||||
|
"summary": "删除 bot 类型",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "bot 类型id",
|
||||||
|
"name": "id",
|
||||||
|
"in": "query",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/resp.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"type": "boolean"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"description": "",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/errorx.CodeErrorResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/bot/type/list": {
|
"/bot/type/list": {
|
||||||
"get": {
|
"get": {
|
||||||
"description": "获取 bot 类型列表",
|
"description": "获取 bot 类型列表",
|
||||||
@ -69,15 +171,36 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"definitions": {
|
"definitions": {
|
||||||
|
"bottype.AddBotTypeDto": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"active",
|
||||||
|
"name"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"active": {
|
||||||
|
"description": "是否启用",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"description": "名称",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"errorx.CodeErrorResponse": {
|
"errorx.CodeErrorResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"code": {
|
"code": {
|
||||||
|
"description": "状态码",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"example": 200
|
"example": 200
|
||||||
},
|
},
|
||||||
"data": {},
|
"data": {
|
||||||
|
"description": "数据"
|
||||||
|
},
|
||||||
"msg": {
|
"msg": {
|
||||||
|
"description": "信息",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "OK"
|
"example": "OK"
|
||||||
}
|
}
|
||||||
@ -104,11 +227,15 @@ const docTemplate = `{
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"code": {
|
"code": {
|
||||||
|
"description": "状态码",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"example": 200
|
"example": 200
|
||||||
},
|
},
|
||||||
"data": {},
|
"data": {
|
||||||
|
"description": "数据"
|
||||||
|
},
|
||||||
"msg": {
|
"msg": {
|
||||||
|
"description": "信息",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "OK"
|
"example": "OK"
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,108 @@
|
|||||||
},
|
},
|
||||||
"basePath": "/",
|
"basePath": "/",
|
||||||
"paths": {
|
"paths": {
|
||||||
|
"/bot/type/add": {
|
||||||
|
"post": {
|
||||||
|
"description": "添加 bot 类型",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"BotType"
|
||||||
|
],
|
||||||
|
"summary": "添加 bot 类型",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "bot 类型",
|
||||||
|
"name": "vo",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/bottype.AddBotTypeDto"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/resp.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"type": "boolean"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"description": "",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/errorx.CodeErrorResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/bot/type/del": {
|
||||||
|
"delete": {
|
||||||
|
"description": "根据 id 删除 bot 类型",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"BotType"
|
||||||
|
],
|
||||||
|
"summary": "删除 bot 类型",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "bot 类型id",
|
||||||
|
"name": "id",
|
||||||
|
"in": "query",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/resp.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"type": "boolean"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"description": "",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/errorx.CodeErrorResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/bot/type/list": {
|
"/bot/type/list": {
|
||||||
"get": {
|
"get": {
|
||||||
"description": "获取 bot 类型列表",
|
"description": "获取 bot 类型列表",
|
||||||
@ -62,15 +164,36 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"definitions": {
|
"definitions": {
|
||||||
|
"bottype.AddBotTypeDto": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"active",
|
||||||
|
"name"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"active": {
|
||||||
|
"description": "是否启用",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"description": "名称",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"errorx.CodeErrorResponse": {
|
"errorx.CodeErrorResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"code": {
|
"code": {
|
||||||
|
"description": "状态码",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"example": 200
|
"example": 200
|
||||||
},
|
},
|
||||||
"data": {},
|
"data": {
|
||||||
|
"description": "数据"
|
||||||
|
},
|
||||||
"msg": {
|
"msg": {
|
||||||
|
"description": "信息",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "OK"
|
"example": "OK"
|
||||||
}
|
}
|
||||||
@ -97,11 +220,15 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"code": {
|
"code": {
|
||||||
|
"description": "状态码",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"example": 200
|
"example": 200
|
||||||
},
|
},
|
||||||
"data": {},
|
"data": {
|
||||||
|
"description": "数据"
|
||||||
|
},
|
||||||
"msg": {
|
"msg": {
|
||||||
|
"description": "信息",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "OK"
|
"example": "OK"
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,27 @@
|
|||||||
basePath: /
|
basePath: /
|
||||||
definitions:
|
definitions:
|
||||||
|
bottype.AddBotTypeDto:
|
||||||
|
properties:
|
||||||
|
active:
|
||||||
|
description: 是否启用
|
||||||
|
type: boolean
|
||||||
|
name:
|
||||||
|
description: 名称
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- active
|
||||||
|
- name
|
||||||
|
type: object
|
||||||
errorx.CodeErrorResponse:
|
errorx.CodeErrorResponse:
|
||||||
properties:
|
properties:
|
||||||
code:
|
code:
|
||||||
|
description: 状态码
|
||||||
example: 200
|
example: 200
|
||||||
type: integer
|
type: integer
|
||||||
data: {}
|
data:
|
||||||
|
description: 数据
|
||||||
msg:
|
msg:
|
||||||
|
description: 信息
|
||||||
example: OK
|
example: OK
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
@ -25,10 +40,13 @@ definitions:
|
|||||||
resp.Response:
|
resp.Response:
|
||||||
properties:
|
properties:
|
||||||
code:
|
code:
|
||||||
|
description: 状态码
|
||||||
example: 200
|
example: 200
|
||||||
type: integer
|
type: integer
|
||||||
data: {}
|
data:
|
||||||
|
description: 数据
|
||||||
msg:
|
msg:
|
||||||
|
description: 信息
|
||||||
example: OK
|
example: OK
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
@ -44,6 +62,67 @@ info:
|
|||||||
title: matrix-middle-service API
|
title: matrix-middle-service API
|
||||||
version: "1.0"
|
version: "1.0"
|
||||||
paths:
|
paths:
|
||||||
|
/bot/type/add:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: 添加 bot 类型
|
||||||
|
parameters:
|
||||||
|
- description: bot 类型
|
||||||
|
in: body
|
||||||
|
name: vo
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/bottype.AddBotTypeDto'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/definitions/resp.Response'
|
||||||
|
- properties:
|
||||||
|
data:
|
||||||
|
type: boolean
|
||||||
|
type: object
|
||||||
|
default:
|
||||||
|
description: ""
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/errorx.CodeErrorResponse'
|
||||||
|
summary: 添加 bot 类型
|
||||||
|
tags:
|
||||||
|
- BotType
|
||||||
|
/bot/type/del:
|
||||||
|
delete:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: 根据 id 删除 bot 类型
|
||||||
|
parameters:
|
||||||
|
- description: bot 类型id
|
||||||
|
in: query
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/definitions/resp.Response'
|
||||||
|
- properties:
|
||||||
|
data:
|
||||||
|
type: boolean
|
||||||
|
type: object
|
||||||
|
default:
|
||||||
|
description: ""
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/errorx.CodeErrorResponse'
|
||||||
|
summary: 删除 bot 类型
|
||||||
|
tags:
|
||||||
|
- BotType
|
||||||
/bot/type/list:
|
/bot/type/list:
|
||||||
get:
|
get:
|
||||||
consumes:
|
consumes:
|
||||||
|
@ -34,6 +34,7 @@ require (
|
|||||||
github.com/goccy/go-json v0.8.1 // indirect
|
github.com/goccy/go-json v0.8.1 // indirect
|
||||||
github.com/golang/snappy v0.0.4 // indirect
|
github.com/golang/snappy v0.0.4 // indirect
|
||||||
github.com/google/uuid v1.3.0 // indirect
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
|
github.com/gookit/goutil v0.6.6 // indirect
|
||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
github.com/josharian/intern v1.0.0 // indirect
|
github.com/josharian/intern v1.0.0 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
@ -64,6 +65,7 @@ require (
|
|||||||
go.uber.org/multierr v1.8.0 // indirect
|
go.uber.org/multierr v1.8.0 // indirect
|
||||||
golang.org/x/crypto v0.5.0 // indirect
|
golang.org/x/crypto v0.5.0 // indirect
|
||||||
golang.org/x/net v0.5.0 // indirect
|
golang.org/x/net v0.5.0 // indirect
|
||||||
|
golang.org/x/sync v0.1.0 // indirect
|
||||||
golang.org/x/sys v0.5.0 // indirect
|
golang.org/x/sys v0.5.0 // indirect
|
||||||
golang.org/x/text v0.7.0 // indirect
|
golang.org/x/text v0.7.0 // indirect
|
||||||
golang.org/x/tools v0.1.12 // indirect
|
golang.org/x/tools v0.1.12 // indirect
|
||||||
|
@ -234,6 +234,8 @@ github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
|
|||||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||||
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
|
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
|
||||||
|
github.com/gookit/goutil v0.6.6 h1:XdvnPocHpKDXA+eykfc/F846Y1V2Vyo3+cV8rfliG90=
|
||||||
|
github.com/gookit/goutil v0.6.6/go.mod h1:D++7kbQd/6vECyYTxB5tq6AKDIG9ZYwZNhubWJvN9dw=
|
||||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||||
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
|
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
|
||||||
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||||
@ -715,6 +717,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
|
|||||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
||||||
|
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
package controller
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/gofiber/fiber/v2"
|
|
||||||
"matrix-middle-service/pkg/database"
|
|
||||||
response "matrix-middle-service/pkg/resp"
|
|
||||||
"matrix-middle-service/pkg/resp/errorx"
|
|
||||||
)
|
|
||||||
|
|
||||||
func SetupBotController(r fiber.Router) {
|
|
||||||
api := r.Group("/bot")
|
|
||||||
api.Get("/type/list", GetBotTypeList)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetBotTypeList
|
|
||||||
// @Summary 获取 bot 类型列表
|
|
||||||
// @Description 获取 bot 类型列表
|
|
||||||
// @Tags BotType
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Success 200 {object} response.Response{data=[]model.BotType}
|
|
||||||
// @Failure default {object} errorx.CodeErrorResponse
|
|
||||||
// @Router /bot/type/list [get]
|
|
||||||
func GetBotTypeList(ctx *fiber.Ctx) error {
|
|
||||||
return database.Exec(func(db database.DataBase) error {
|
|
||||||
list, err := db.GetAllBotTypes()
|
|
||||||
if err = errorx.ParseError(err); err != nil {
|
|
||||||
return ctx.JSON(err)
|
|
||||||
}
|
|
||||||
return ctx.JSON(response.NewResponse(list))
|
|
||||||
})
|
|
||||||
}
|
|
@ -0,0 +1,11 @@
|
|||||||
|
package bot
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"matrix-middle-service/internel/controller/bot/bottype"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SetupBotController(r fiber.Router) {
|
||||||
|
api := r.Group("/bot")
|
||||||
|
bottype.SetupBotType(api)
|
||||||
|
}
|
@ -0,0 +1,108 @@
|
|||||||
|
package bottype
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"matrix-middle-service/pkg/database"
|
||||||
|
"matrix-middle-service/pkg/database/model"
|
||||||
|
response "matrix-middle-service/pkg/resp"
|
||||||
|
"matrix-middle-service/pkg/resp/errorx"
|
||||||
|
"matrix-middle-service/pkg/utils/sonyflake"
|
||||||
|
"matrix-middle-service/pkg/utils/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SetupBotType(r fiber.Router) {
|
||||||
|
api := r.Group("/type")
|
||||||
|
getBotTypeList(api)
|
||||||
|
addBotType(api)
|
||||||
|
DeleteBotTypeById(api)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetBotTypeList
|
||||||
|
// @Summary 获取 bot 类型列表
|
||||||
|
// @Description 获取 bot 类型列表
|
||||||
|
// @Tags BotType
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Success 200 {object} response.Response{data=[]model.BotType}
|
||||||
|
// @Failure default {object} errorx.CodeErrorResponse
|
||||||
|
// @Router /bot/type/list [get]
|
||||||
|
func getBotTypeList(api fiber.Router) {
|
||||||
|
api.Get("/list", func(ctx *fiber.Ctx) error {
|
||||||
|
return database.Exec(func(db database.DataBase) error {
|
||||||
|
list, err := db.GetAllBotTypes()
|
||||||
|
if err = errorx.ParseError(err); err != nil {
|
||||||
|
return ctx.JSON(err)
|
||||||
|
}
|
||||||
|
return ctx.JSON(response.NewResponse(list))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type AddBotTypeDto struct {
|
||||||
|
// 名称
|
||||||
|
Name string `json:"name" validate:"required"`
|
||||||
|
// 是否启用
|
||||||
|
Active bool `json:"active" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddBotType
|
||||||
|
// @Summary 添加 bot 类型
|
||||||
|
// @Description 添加 bot 类型
|
||||||
|
// @Tags BotType
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param vo body AddBotTypeDto true "bot 类型"
|
||||||
|
// @Success 200 {object} response.Response{data=bool}
|
||||||
|
// @Failure default {object} errorx.CodeErrorResponse
|
||||||
|
// @Router /bot/type/add [post]
|
||||||
|
func addBotType(api fiber.Router) {
|
||||||
|
api.Post("/add", func(ctx *fiber.Ctx) error {
|
||||||
|
dto := &AddBotTypeDto{}
|
||||||
|
err := ctx.BodyParser(dto)
|
||||||
|
if err = errorx.ParseError(err); err != nil {
|
||||||
|
return ctx.JSON(err)
|
||||||
|
}
|
||||||
|
err = validator.ValidateStruct(dto)
|
||||||
|
if err = errorx.ParseError(err); err != nil {
|
||||||
|
return ctx.JSON(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return database.Exec(func(db database.DataBase) error {
|
||||||
|
bt := &model.BotType{
|
||||||
|
Id: sonyflake.NextStrId(),
|
||||||
|
Name: dto.Name,
|
||||||
|
Active: dto.Active,
|
||||||
|
}
|
||||||
|
|
||||||
|
err = db.AddBotType(bt)
|
||||||
|
if err = errorx.ParseError(err); err != nil {
|
||||||
|
return ctx.JSON(err)
|
||||||
|
}
|
||||||
|
return ctx.JSON(response.NewResponse(true))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteBotTypeById
|
||||||
|
// @Summary 删除 bot 类型
|
||||||
|
// @Description 根据 id 删除 bot 类型
|
||||||
|
// @Tags BotType
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param id query string true "bot 类型id"
|
||||||
|
// @Success 200 {object} response.Response{data=bool}
|
||||||
|
// @Failure default {object} errorx.CodeErrorResponse
|
||||||
|
// @Router /bot/type/del [delete]
|
||||||
|
func DeleteBotTypeById(api fiber.Router) {
|
||||||
|
api.Delete("/del", func(ctx *fiber.Ctx) error {
|
||||||
|
id := ctx.Query("id")
|
||||||
|
|
||||||
|
return database.Exec(func(db database.DataBase) error {
|
||||||
|
err := db.DeleteBotTypeById(id)
|
||||||
|
if err = errorx.ParseError(err); err != nil {
|
||||||
|
return ctx.JSON(err)
|
||||||
|
}
|
||||||
|
return ctx.JSON(response.NewResponse(true))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
@ -2,7 +2,7 @@ package route
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"matrix-middle-service/internel/controller"
|
"matrix-middle-service/internel/controller/bot"
|
||||||
"matrix-middle-service/pkg/config"
|
"matrix-middle-service/pkg/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,5 +11,5 @@ func SetupRoute(app *fiber.App, conf *config.Conf) {
|
|||||||
SwaggerHandler(app)
|
SwaggerHandler(app)
|
||||||
}
|
}
|
||||||
|
|
||||||
controller.SetupBotController(app)
|
bot.SetupBotController(app)
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@ type DataBase interface {
|
|||||||
Close() error
|
Close() error
|
||||||
|
|
||||||
GetAllBotTypes() ([]*model.BotType, error)
|
GetAllBotTypes() ([]*model.BotType, error)
|
||||||
|
AddBotType(bt *model.BotType) error
|
||||||
|
DeleteBotTypeById(id string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init(conf []interface{}) {
|
func Init(conf []interface{}) {
|
||||||
|
@ -2,8 +2,10 @@ package mysql
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/gookit/goutil/strutil"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
database2 "matrix-middle-service/pkg/config/database"
|
database2 "matrix-middle-service/pkg/config/database"
|
||||||
"matrix-middle-service/pkg/database"
|
"matrix-middle-service/pkg/database"
|
||||||
@ -53,6 +55,44 @@ type db struct {
|
|||||||
config *conf.Config
|
config *conf.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *db) DeleteBotTypeById(id string) error {
|
||||||
|
if strutil.IsBlank(id) {
|
||||||
|
return errors.New(fmt.Sprintf("id 不能为空"))
|
||||||
|
}
|
||||||
|
|
||||||
|
exist, err := d.db.Exist(&model.BotType{Id: id})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !exist {
|
||||||
|
return errors.New(fmt.Sprintf("类型id %s 不存在", id))
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = d.db.Limit(1).Delete(&model.BotType{Id: id})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *db) AddBotType(bt *model.BotType) error {
|
||||||
|
if strutil.IsBlank(bt.Id) {
|
||||||
|
return errors.New(fmt.Sprintf("id 不能为空"))
|
||||||
|
}
|
||||||
|
|
||||||
|
if strutil.IsBlank(bt.Name) {
|
||||||
|
return errors.New(fmt.Sprintf("类型名称 不能为空"))
|
||||||
|
}
|
||||||
|
|
||||||
|
exist, err := d.db.Exist(&model.BotType{Name: bt.Name})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if exist {
|
||||||
|
return errors.New(fmt.Sprintf("类型 %s 已存在", bt.Name))
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = d.db.UseBool("active").Insert(bt)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (d *db) GetAllBotTypes() ([]*model.BotType, error) {
|
func (d *db) GetAllBotTypes() ([]*model.BotType, error) {
|
||||||
list := make([]*model.BotType, 0)
|
list := make([]*model.BotType, 0)
|
||||||
err := d.db.Find(&list)
|
err := d.db.Find(&list)
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package resp
|
package resp
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
Code Code `json:"code" example:"200"`
|
// 状态码
|
||||||
|
Code Code `json:"code" example:"200"`
|
||||||
|
// 数据
|
||||||
Data interface{} `json:"data"`
|
Data interface{} `json:"data"`
|
||||||
Msg string `json:"msg" example:"OK"`
|
// 信息
|
||||||
|
Msg string `json:"msg" example:"OK"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Code = int
|
type Code = int
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package sonyflake
|
package sonyflake
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/sony/sonyflake"
|
"github.com/sony/sonyflake"
|
||||||
sf "matrix-middle-service/pkg/config/sonyflake"
|
sf "matrix-middle-service/pkg/config/sonyflake"
|
||||||
"matrix-middle-service/pkg/logger"
|
"matrix-middle-service/pkg/logger"
|
||||||
@ -19,3 +20,12 @@ func Init(config *sf.Config) {
|
|||||||
func SonyFlake() *sonyflake.Sonyflake {
|
func SonyFlake() *sonyflake.Sonyflake {
|
||||||
return generator
|
return generator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NextId() uint64 {
|
||||||
|
id, _ := generator.NextID()
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
func NextStrId() string {
|
||||||
|
return fmt.Sprintf("%d", NextId())
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user