Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
nightingale
提交
52e4fa4d
N
nightingale
项目概览
DiDi
/
nightingale
9 个月 前同步成功
通知
46
Star
7053
Fork
1161
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
nightingale
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
52e4fa4d
编写于
7月 17, 2023
作者:
U
Ulric Qin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename obs to dumper
上级
6462c028
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
20 addition
and
20 deletion
+20
-20
dumper/dumper.go
dumper/dumper.go
+1
-1
dumper/sync.go
dumper/sync.go
+19
-19
未找到文件。
dumper/dumper.go
浏览文件 @
52e4fa4d
...
...
@@ -4,5 +4,5 @@ import "github.com/gin-gonic/gin"
// package level functions
func
ConfigRouter
(
r
*
gin
.
Engine
)
{
sync
Obs
.
ConfigRouter
(
r
)
sync
Dumper
.
ConfigRouter
(
r
)
}
dumper/sync.go
浏览文件 @
52e4fa4d
...
...
@@ -35,20 +35,20 @@ type SyncRecords struct {
Last
*
SyncRecord
}
type
Sync
Obs
struct
{
type
Sync
Dumper
struct
{
sync
.
RWMutex
records
map
[
string
]
*
SyncRecords
}
func
NewSync
Obs
()
*
SyncObs
{
return
&
Sync
Obs
{
func
NewSync
Dumper
()
*
SyncDumper
{
return
&
Sync
Dumper
{
records
:
make
(
map
[
string
]
*
SyncRecords
),
}
}
var
sync
Obs
=
NewSyncObs
()
var
sync
Dumper
=
NewSyncDumper
()
func
(
s
o
*
SyncObs
)
Put
(
key
string
,
timestamp
,
mills
int64
,
count
int
,
message
string
)
{
func
(
s
d
*
SyncDumper
)
Put
(
key
string
,
timestamp
,
mills
int64
,
count
int
,
message
string
)
{
sr
:=
&
SyncRecord
{
Timestamp
:
timestamp
,
Mills
:
mills
,
...
...
@@ -56,29 +56,29 @@ func (so *SyncObs) Put(key string, timestamp, mills int64, count int, message st
Message
:
message
,
}
s
o
.
Lock
()
defer
s
o
.
Unlock
()
s
d
.
Lock
()
defer
s
d
.
Unlock
()
if
_
,
ok
:=
s
o
.
records
[
key
];
!
ok
{
s
o
.
records
[
key
]
=
&
SyncRecords
{
Current
:
sr
}
if
_
,
ok
:=
s
d
.
records
[
key
];
!
ok
{
s
d
.
records
[
key
]
=
&
SyncRecords
{
Current
:
sr
}
return
}
s
o
.
records
[
key
]
.
Last
=
so
.
records
[
key
]
.
Current
s
o
.
records
[
key
]
.
Current
=
sr
s
d
.
records
[
key
]
.
Last
=
sd
.
records
[
key
]
.
Current
s
d
.
records
[
key
]
.
Current
=
sr
}
// busi_groups:
// last: timestamp, mills, count
// curr: timestamp, mills, count
func
(
s
o
*
SyncObs
)
Sprint
()
string
{
s
o
.
RLock
()
defer
s
o
.
RUnlock
()
func
(
s
d
*
SyncDumper
)
Sprint
()
string
{
s
d
.
RLock
()
defer
s
d
.
RUnlock
()
var
sb
strings
.
Builder
sb
.
WriteString
(
"
\n
"
)
for
k
,
v
:=
range
s
o
.
records
{
for
k
,
v
:=
range
s
d
.
records
{
sb
.
WriteString
(
k
)
sb
.
WriteString
(
":
\n
"
)
if
v
.
Last
!=
nil
{
...
...
@@ -94,17 +94,17 @@ func (so *SyncObs) Sprint() string {
return
sb
.
String
()
}
func
(
s
o
*
SyncObs
)
ConfigRouter
(
r
*
gin
.
Engine
)
{
r
.
GET
(
"/
obs
/sync"
,
func
(
c
*
gin
.
Context
)
{
func
(
s
d
*
SyncDumper
)
ConfigRouter
(
r
*
gin
.
Engine
)
{
r
.
GET
(
"/
dumper
/sync"
,
func
(
c
*
gin
.
Context
)
{
clientIP
:=
c
.
ClientIP
()
if
clientIP
!=
"127.0.0.1"
&&
clientIP
!=
"::1"
{
c
.
String
(
403
,
"forbidden"
)
return
}
c
.
String
(
200
,
s
o
.
Sprint
())
c
.
String
(
200
,
s
d
.
Sprint
())
})
}
func
PutSyncRecord
(
key
string
,
timestamp
,
mills
int64
,
count
int
,
message
string
)
{
sync
Obs
.
Put
(
key
,
timestamp
,
mills
,
count
,
message
)
sync
Dumper
.
Put
(
key
,
timestamp
,
mills
,
count
,
message
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录