Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Eolink
goku-api-gateway
提交
dc5082a8
G
goku-api-gateway
项目概览
Eolink
/
goku-api-gateway
上一次同步 1 年多
通知
133
Star
2992
Fork
611
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
goku-api-gateway
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dc5082a8
编写于
9月 17, 2019
作者:
Y
Your Name
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#console 修复告警部分文件读取后未关闭的问题
上级
e679a098
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
15 addition
and
123 deletion
+15
-123
.gitignore
.gitignore
+1
-0
utils/alert.go
utils/alert.go
+14
-39
utils/function.go
utils/function.go
+0
-76
utils/mail.go
utils/mail.go
+0
-8
未找到文件。
.gitignore
0 → 100644
浏览文件 @
dc5082a8
/.idea/
utils/alert.go
浏览文件 @
dc5082a8
...
...
@@ -9,17 +9,22 @@ import (
"time"
)
func
SendAlertMail
(
sender
,
senderPassword
,
smtpAddress
,
smtpPort
,
smtpProtocol
,
receiverMail
,
requestURL
,
alertLogPath
,
alertPeriod
,
alertCount
,
apiName
,
apiID
,
targetServer
,
proxyURL
string
)
(
bool
,
error
)
{
alertTime
:=
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
)
f
,
err
:=
os
.
Open
(
"html/currentAlert.html"
)
if
err
!=
nil
{
log
.
Warn
(
err
)
}
body
,
err
:=
ioutil
.
ReadAll
(
f
)
var
(
currentAlertBody
string
)
func
init
()
{
body
,
err
:=
ioutil
.
ReadFile
(
"html/currentAlert.html"
)
if
err
!=
nil
{
log
.
Warn
(
err
)
log
.
Panic
(
err
)
}
bodyStr
:=
string
(
body
)
currentAlertBody
=
string
(
body
)
}
func
SendAlertMail
(
sender
,
senderPassword
,
smtpAddress
,
smtpPort
,
smtpProtocol
,
receiverMail
,
requestURL
,
alertLogPath
,
alertPeriod
,
alertCount
,
apiName
,
apiID
,
targetServer
,
proxyURL
string
)
(
bool
,
error
)
{
alertTime
:=
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
)
bodyStr
:=
currentAlertBody
bodyStr
=
strings
.
Replace
(
bodyStr
,
"$requestURL"
,
requestURL
,
-
1
)
bodyStr
=
strings
.
Replace
(
bodyStr
,
"$alertTime"
,
alertTime
,
-
1
)
bodyStr
=
strings
.
Replace
(
bodyStr
,
"$alertLogPath"
,
alertLogPath
,
-
1
)
...
...
@@ -38,33 +43,3 @@ func SendAlertMail(sender, senderPassword, smtpAddress, smtpPort, smtpProtocol,
return
true
,
nil
}
func
SendMonitorAlertMail
(
sender
,
senderPassword
,
smtpAddress
,
smtpPort
,
smtpProtocol
,
receiverMail
,
bodyStr
string
)
(
bool
,
error
)
{
host
:=
net
.
JoinHostPort
(
smtpAddress
,
smtpPort
)
subject
:=
"EOLINKER AGW节点自动重启失败告警"
err
:=
SendToMail
(
sender
,
senderPassword
,
host
,
receiverMail
,
subject
,
bodyStr
,
"html"
,
smtpProtocol
)
if
err
!=
nil
{
log
.
Warn
(
"SendMonitorAlertMail:"
,
err
)
}
return
true
,
nil
}
func
ReplaceMonitorBody
(
nodeList
[]
map
[
string
]
string
)
(
bool
,
string
,
error
)
{
f
,
err
:=
os
.
Open
(
"html/monitorAlert.html"
)
if
err
!=
nil
{
log
.
Warn
(
err
)
}
body
,
err
:=
ioutil
.
ReadAll
(
f
)
if
err
!=
nil
{
log
.
Warn
(
err
)
}
bodyStr
:=
string
(
body
)
nodeStr
:=
""
for
_
,
nodeInfo
:=
range
nodeList
{
nodeStr
+=
"<p>节点名称:"
+
nodeInfo
[
"nodeName"
]
+
"</p>"
nodeStr
+=
"<p>节点IP:"
+
nodeInfo
[
"nodeIP"
]
+
":"
+
nodeInfo
[
"nodePort"
]
+
"</p>"
nodeStr
+=
"<p></p>"
}
bodyStr
=
strings
.
Replace
(
bodyStr
,
"$alertTime"
,
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
),
-
1
)
bodyStr
=
strings
.
Replace
(
bodyStr
,
"$nodeList"
,
nodeStr
,
-
1
)
return
true
,
bodyStr
,
nil
}
utils/function.go
浏览文件 @
dc5082a8
...
...
@@ -2,9 +2,7 @@ package utils
import
(
"crypto/md5"
"crypto/sha1"
"encoding/hex"
"errors"
"fmt"
"math/rand"
"net"
...
...
@@ -14,8 +12,6 @@ import (
"strconv"
"strings"
"time"
"golang.org/x/crypto/bcrypt"
)
// 将string转为int类型
...
...
@@ -48,17 +44,6 @@ func InterceptIP(str, substr string) string {
return
rs
}
func
GetHashKey
(
first_sail
string
,
args
...
string
)
string
{
hashKey
:=
""
hashKey
=
hashKey
+
strconv
.
Itoa
(
int
(
time
.
Now
()
.
Unix
()))
+
first_sail
for
i
:=
0
;
i
<
len
(
args
);
i
++
{
hashKey
+=
args
[
i
]
}
h
:=
sha1
.
New
()
h
.
Write
([]
byte
(
hashKey
))
return
hex
.
EncodeToString
(
h
.
Sum
(
nil
))
}
func
Md5
(
encodeString
string
)
string
{
h
:=
md5
.
New
()
h
.
Write
([]
byte
(
encodeString
))
...
...
@@ -99,29 +84,6 @@ func Stop() bool {
}
}
// 启动网关服务
func
StartGateway
()
bool
{
cmd
:=
exec
.
Command
(
"/bin/bash"
,
"-c"
,
"go run gateway.go"
)
if
_
,
err
:=
cmd
.
Output
();
err
!=
nil
{
return
false
}
else
{
return
true
}
}
// 将[]string转为[]int
func
ConvertArray
(
arr
[]
string
)
(
bool
,
[]
int
)
{
result
:=
make
([]
int
,
0
)
for
_
,
i
:=
range
arr
{
res
,
err
:=
strconv
.
Atoi
(
i
)
if
err
!=
nil
{
return
false
,
result
}
result
=
append
(
result
,
res
)
}
return
true
,
result
}
// 获取MAC地址
func
GetMac
()
(
bool
,
string
)
{
interfaces
,
err
:=
net
.
Interfaces
()
...
...
@@ -141,41 +103,3 @@ func GetMac() (bool, string) {
}
return
false
,
""
}
// 匹配机器码和授权码是否一致
func
MatchVerifyCode
(
verifyCode
,
mac
string
)
bool
{
err
:=
bcrypt
.
CompareHashAndPassword
([]
byte
(
verifyCode
),
[]
byte
(
mac
))
if
err
!=
nil
{
return
false
}
else
{
return
true
}
}
// 将机器码加密
func
BcryptMAC
()
string
{
_
,
mac
:=
GetMac
()
verifyCode
,
err
:=
bcrypt
.
GenerateFromPassword
([]
byte
(
Md5
(
mac
)),
bcrypt
.
DefaultCost
)
if
err
!=
nil
{
return
""
}
return
string
(
verifyCode
)
}
// 将数组的值赋给每一个变量
func
ConvertArrayToVariable
(
arr
[]
interface
{},
variable
...
interface
{})
error
{
if
len
(
arr
)
!=
len
(
variable
)
{
return
errors
.
New
(
"[ERROR]Fail to convert"
)
}
for
i
,
v
:=
range
arr
{
tmp
,
_
:=
variable
[
i
]
.
(
*
int
)
tmpvstr
,
_
:=
arr
[
i
]
.
(
string
)
tmpv
,
_
:=
strconv
.
Atoi
(
tmpvstr
)
if
v
!=
nil
{
*
tmp
=
tmpv
}
else
{
*
tmp
=
0
}
}
return
nil
}
utils/mail.go
浏览文件 @
dc5082a8
...
...
@@ -16,14 +16,6 @@ var period map[string]string = map[string]string{
"4"
:
"60"
,
}
func
SendMail
(
sender
,
subject
,
senderPassword
,
smtpAddress
,
smtpPort
,
smtpProtocol
,
receiverMail
,
content
string
)
{
host
:=
net
.
JoinHostPort
(
smtpAddress
,
smtpPort
)
err
:=
SendToMail
(
sender
,
senderPassword
,
host
,
receiverMail
,
subject
,
content
,
"html"
,
smtpProtocol
)
if
err
!=
nil
{
log
.
Warn
(
"SendMail:"
,
err
)
}
}
func
SendToMail
(
user
,
password
,
host
,
to
,
subject
,
body
,
mailtype
,
smtpProtocol
string
)
error
{
hp
:=
strings
.
Split
(
host
,
":"
)
auth
:=
smtp
.
PlainAuth
(
""
,
user
,
password
,
hp
[
0
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录