Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: record message log with sqlite #11

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

conf.yaml
messenger
*.db
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,49 @@ func main() {
}
```

### 查询消息历史

请求方式:GET

请求地址:http://127.0.0.1:8888/v1/histories

参数说明:

| 参数 | 是否必须 | 类型 | 说明 |
| :--------- | :------- | :----- | :----------------- |
| page_index | 是 | int | 分页序号,从1开始 |
| page_size | 是 | int | 分页每页数量 |
| start | 否 | int64 | 起始时间unix时间戳 |
| end | 否 | int64 | 结束时间unix时间戳 |
| sender | 否 | string | 发送方式名称 |
| content | 否 | string | 消息内容 |

返回结果:
```json
// 正常 httpStatusCode==200
{
"count": 1,
"list": [
{
"CreatedAt": 1705911411,
"Err": "",
"Id": 1,
"Message": "json string of message",
"ReceivedAt": 1705911410,
"Req": "curl command of request",
"Resp": "json string of response body and http code",
"Status": true
}
],
"msg": "ok"
}

// 异常 httpStatusCode!=200
{
"msg": "xxxx"
}
```

### 鉴权

当配置文件中开启auths鉴权配置后,请求需要加入鉴权信息,目前支持三种鉴权方式.
Expand Down
63 changes: 63 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,69 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/v1/history": {
"get": {
"description": "query message history",
"tags": [
"send"
],
"parameters": [
{
"type": "integer",
"description": "page_index",
"name": "page_index",
"in": "query",
"required": true
},
{
"type": "integer",
"description": "page_size",
"name": "page_size",
"in": "query",
"required": true
},
{
"type": "integer",
"description": "start time",
"name": "start",
"in": "query"
},
{
"type": "integer",
"description": "end time",
"name": "end",
"in": "query"
},
{
"type": "string",
"description": "false failed, true sent successfully",
"name": "status",
"in": "query"
},
{
"type": "string",
"description": "sender name",
"name": "sender",
"in": "query"
},
{
"type": "string",
"description": "content",
"name": "content",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object",
"additionalProperties": true
}
}
}
}
},
"/v1/message": {
"post": {
"description": "send a new message\nhttps://github.com/veops/messenger?tab=readme-ov-file#发送消息",
Expand Down
63 changes: 63 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,69 @@
"contact": {}
},
"paths": {
"/v1/history": {
"get": {
"description": "query message history",
"tags": [
"send"
],
"parameters": [
{
"type": "integer",
"description": "page_index",
"name": "page_index",
"in": "query",
"required": true
},
{
"type": "integer",
"description": "page_size",
"name": "page_size",
"in": "query",
"required": true
},
{
"type": "integer",
"description": "start time",
"name": "start",
"in": "query"
},
{
"type": "integer",
"description": "end time",
"name": "end",
"in": "query"
},
{
"type": "string",
"description": "false failed, true sent successfully",
"name": "status",
"in": "query"
},
{
"type": "string",
"description": "sender name",
"name": "sender",
"in": "query"
},
{
"type": "string",
"description": "content",
"name": "content",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object",
"additionalProperties": true
}
}
}
}
},
"/v1/message": {
"post": {
"description": "send a new message\nhttps://github.com/veops/messenger?tab=readme-ov-file#发送消息",
Expand Down
42 changes: 42 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,48 @@ externalDocs:
info:
contact: {}
paths:
/v1/history:
get:
description: query message history
parameters:
- description: page_index
in: query
name: page_index
required: true
type: integer
- description: page_size
in: query
name: page_size
required: true
type: integer
- description: start time
in: query
name: start
type: integer
- description: end time
in: query
name: end
type: integer
- description: false failed, true sent successfully
in: query
name: status
type: string
- description: sender name
in: query
name: sender
type: string
- description: content
in: query
name: content
type: string
responses:
"200":
description: OK
schema:
additionalProperties: true
type: object
tags:
- send
/v1/message:
post:
consumes:
Expand Down
32 changes: 17 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,46 @@ require (
github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.2
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
gorm.io/gorm v1.25.5
)

require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/spec v0.20.4 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/jsonreference v0.20.4 // indirect
github.com/go-openapi/spec v0.20.14 // indirect
github.com/go-openapi/swag v0.22.7 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-sqlite3 v1.14.17 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/smartystreets/goconvey v1.8.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/tools v0.7.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/tools v0.17.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

require (
Expand All @@ -57,9 +59,9 @@ require (
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/samber/lo v1.38.1
github.com/spf13/cast v1.5.1
golang.org/x/sync v0.3.0
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/sync v0.6.0
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
moul.io/http2curl v1.0.0
gorm.io/driver/sqlite v1.5.4
)
Loading
Loading