Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
search_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
abab2f4d
authored
Jun 08, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
更新readme
parent
a072b588
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
39 deletions
pkg/message/dingding.go
pkg/message/sms.go
readme.md
pkg/message/dingding.go
View file @
abab2f4d
package
message
import
(
"encoding/json"
"fmt"
"github.com/imroc/req"
"github.com/prometheus/common/log"
"net/http"
"net/url"
"search_server/pkg/common"
"search_server/pkg/config"
"strconv"
"time"
)
//发送钉钉消息的包
...
...
@@ -20,31 +12,6 @@ type DingDingRequest struct {
IsAtAll
bool
`json:"isAtAll"`
}
//普通发短信
func
SendMessage
(
mobile
int64
,
keyWord
string
,
content
map
[
string
]
interface
{})
{
//es连接告警的keyword是 es_connect_monitor
if
mobile
!=
0
{
timeNow
:=
time
.
Now
()
.
Unix
()
requestContent
,
_
:=
json
.
Marshal
(
content
)
requestTel
,
_
:=
json
.
Marshal
([]
int64
{
mobile
})
apiDomain
:=
config
.
Get
(
"message.api_domain"
)
.
String
()
apiMd5Str
:=
config
.
Get
(
"message.api_md5_str"
)
.
String
()
resp
,
err
:=
http
.
PostForm
(
apiDomain
,
url
.
Values
{
"data"
:
{
string
(
requestContent
)},
"touser"
:
{
string
(
requestTel
)},
"keyword"
:
{
keyWord
},
"k1"
:
{
strconv
.
FormatInt
(
timeNow
,
10
)},
"k2"
:
{
common
.
Md5
(
common
.
Md5
(
strconv
.
FormatInt
(
timeNow
,
10
))
+
apiMd5Str
)},
"is_ignore"
:
{},
})
if
err
!=
nil
{
fmt
.
Print
(
err
)
}
defer
resp
.
Body
.
Close
()
}
}
func
SendDingdingMessage
(
content
string
)
{
var
(
requestData
DingDingRequest
...
...
pkg/message/sms.go
0 → 100644
View file @
abab2f4d
package
message
import
(
"encoding/json"
"fmt"
"net/http"
"net/url"
"search_server/pkg/common"
"search_server/pkg/config"
"strconv"
"time"
)
//普通发短信
func
SendMessage
(
mobile
int64
,
keyWord
string
,
content
map
[
string
]
interface
{})
{
//es连接告警的keyword是 es_connect_monitor
if
mobile
!=
0
{
timeNow
:=
time
.
Now
()
.
Unix
()
requestContent
,
_
:=
json
.
Marshal
(
content
)
requestTel
,
_
:=
json
.
Marshal
([]
int64
{
mobile
})
apiDomain
:=
config
.
Get
(
"message.api_domain"
)
.
String
()
apiMd5Str
:=
config
.
Get
(
"message.api_md5_str"
)
.
String
()
resp
,
err
:=
http
.
PostForm
(
apiDomain
,
url
.
Values
{
"data"
:
{
string
(
requestContent
)},
"touser"
:
{
string
(
requestTel
)},
"keyword"
:
{
keyWord
},
"k1"
:
{
strconv
.
FormatInt
(
timeNow
,
10
)},
"k2"
:
{
common
.
Md5
(
common
.
Md5
(
strconv
.
FormatInt
(
timeNow
,
10
))
+
apiMd5Str
)},
"is_ignore"
:
{},
})
if
err
!=
nil
{
fmt
.
Print
(
err
)
}
defer
resp
.
Body
.
Close
()
}
}
readme.md
View file @
abab2f4d
...
...
@@ -17,14 +17,20 @@
### 已经封装的模块以及用法
#### 1.配置读取
接在conf/config.ini文件添加自己的配置项
然后使用config.Get("xxx.xxx")即可
接在
```conf/config.ini```
文件添加自己的配置项
然后使用
```config.Get("xxx.xxx")```
即可
#### 2.mysql连接实例
使用
mysql.GetDB()
即可获取对应的实例,不同数据库的连接可以自己定义不同的GetDB方法
使用
```mysql.GetDB()```
即可获取对应的实例,不同数据库的连接可以自己定义不同的GetDB方法
#### 3.redis使用
可以直接调用
gredis.Hset(),gredis.Hget()
等方法,具体使用请参考代码,其中返回的结果是一个redis对象,需要自己转成自己需要的类型
可以直接调用
```gredis.Hset(),gredis.Hget()```
等方法,具体使用请参考代码,其中返回的结果是一个redis对象,需要自己转成自己需要的类型
#### 4.mgo连接实例
使用
mongo.GetDB()
即可,不同数据库的连接可以自己定义不同的GetDB方法
使用
```mongo.GetDB()```
即可,不同数据库的连接可以自己定义不同的GetDB方法
然后用C方法指定集合进行操作即可:
mongo.GetDB().C("xxx").Find(bson.M{}).Count()
```mongo.GetDB().C("xxx").Find(bson.M{}).Count()```
#### 5.钉钉群消息以及短信
直接在pkg/message包调用对应的函数即可:
钉钉的为
```message.SendDingdingMessage```
短信为
```message.SendMessage```
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment