Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
二次元的罪恶王冠
beego
提交
093f9763
B
beego
项目概览
二次元的罪恶王冠
/
beego
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
beego
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
093f9763
编写于
12月 13, 2020
作者:
M
Ming Deng
提交者:
GitHub
12月 13, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4355 from flycash/develop
rename key world 'governor' to 'admin'
上级
1452a75d
198b9cce
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
39 addition
and
39 deletion
+39
-39
README.md
README.md
+2
-2
adapter/admin.go
adapter/admin.go
+1
-1
adapter/toolbox/healthcheck.go
adapter/toolbox/healthcheck.go
+4
-4
adapter/toolbox/profile.go
adapter/toolbox/profile.go
+5
-5
core/admin/command.go
core/admin/command.go
+1
-1
core/admin/healthcheck.go
core/admin/healthcheck.go
+2
-2
core/admin/profile.go
core/admin/profile.go
+1
-1
core/admin/profile_test.go
core/admin/profile_test.go
+1
-1
server/web/admin_controller.go
server/web/admin_controller.go
+5
-5
server/web/admin_test.go
server/web/admin_test.go
+5
-5
server/web/adminui.go
server/web/adminui.go
+1
-1
task/govenor_command.go
task/govenor_command.go
+11
-11
未找到文件。
README.md
浏览文件 @
093f9763
...
@@ -6,7 +6,7 @@ services.
...
@@ -6,7 +6,7 @@ services.
It is inspired by Tornado, Sinatra and Flask. beego has some Go-specific features such as interfaces and struct
It is inspired by Tornado, Sinatra and Flask. beego has some Go-specific features such as interfaces and struct
embedding.
embedding.
![
architecture
](
https://cdn.nlark.com/yuque/0/2020/png/755700/16078
49779965-e243f61d-607f-4357-b292-e2c69aab1c11
.png
)
![
architecture
](
https://cdn.nlark.com/yuque/0/2020/png/755700/16078
57489109-1e267fce-d65f-4c5e-b915-5c475df33c58
.png
)
Beego is compos of four parts:
Beego is compos of four parts:
1.
Base modules: including log module, config module, governor module;
1.
Base modules: including log module, config module, governor module;
...
@@ -25,7 +25,7 @@ Beego is compos of four parts:
...
@@ -25,7 +25,7 @@ Beego is compos of four parts:
### Web Application
### Web Application
![
Http Request
](
https://cdn.nlark.com/yuque/0/2020/png/755700/160785
4896328-6db5ca04-281d-453e-9843-4777ed932874
.png
)
![
Http Request
](
https://cdn.nlark.com/yuque/0/2020/png/755700/160785
7462507-855ec543-7ce3-402d-a0cb-b2524d5a4b60
.png
)
#### Create `hello` directory, cd `hello` directory
#### Create `hello` directory, cd `hello` directory
...
...
adapter/admin.go
浏览文件 @
093f9763
...
@@ -17,7 +17,7 @@ package adapter
...
@@ -17,7 +17,7 @@ package adapter
import
(
import
(
"time"
"time"
_
"github.com/astaxie/beego/core/
governor
"
_
"github.com/astaxie/beego/core/
admin
"
"github.com/astaxie/beego/server/web"
"github.com/astaxie/beego/server/web"
)
)
...
...
adapter/toolbox/healthcheck.go
浏览文件 @
093f9763
...
@@ -31,19 +31,19 @@
...
@@ -31,19 +31,19 @@
package
toolbox
package
toolbox
import
(
import
(
"github.com/astaxie/beego/core/
governor
"
"github.com/astaxie/beego/core/
admin
"
)
)
// AdminCheckList holds health checker map
// AdminCheckList holds health checker map
// Deprecated using
governor
.AdminCheckList
// Deprecated using
admin
.AdminCheckList
var
AdminCheckList
map
[
string
]
HealthChecker
var
AdminCheckList
map
[
string
]
HealthChecker
// HealthChecker health checker interface
// HealthChecker health checker interface
type
HealthChecker
governor
.
HealthChecker
type
HealthChecker
admin
.
HealthChecker
// AddHealthCheck add health checker with name string
// AddHealthCheck add health checker with name string
func
AddHealthCheck
(
name
string
,
hc
HealthChecker
)
{
func
AddHealthCheck
(
name
string
,
hc
HealthChecker
)
{
governor
.
AddHealthCheck
(
name
,
hc
)
admin
.
AddHealthCheck
(
name
,
hc
)
AdminCheckList
[
name
]
=
hc
AdminCheckList
[
name
]
=
hc
}
}
...
...
adapter/toolbox/profile.go
浏览文件 @
093f9763
...
@@ -19,7 +19,7 @@ import (
...
@@ -19,7 +19,7 @@ import (
"os"
"os"
"time"
"time"
"github.com/astaxie/beego/core/
governor
"
"github.com/astaxie/beego/core/
admin
"
)
)
var
startTime
=
time
.
Now
()
var
startTime
=
time
.
Now
()
...
@@ -31,20 +31,20 @@ func init() {
...
@@ -31,20 +31,20 @@ func init() {
// ProcessInput parse input command string
// ProcessInput parse input command string
func
ProcessInput
(
input
string
,
w
io
.
Writer
)
{
func
ProcessInput
(
input
string
,
w
io
.
Writer
)
{
governor
.
ProcessInput
(
input
,
w
)
admin
.
ProcessInput
(
input
,
w
)
}
}
// MemProf record memory profile in pprof
// MemProf record memory profile in pprof
func
MemProf
(
w
io
.
Writer
)
{
func
MemProf
(
w
io
.
Writer
)
{
governor
.
MemProf
(
w
)
admin
.
MemProf
(
w
)
}
}
// GetCPUProfile start cpu profile monitor
// GetCPUProfile start cpu profile monitor
func
GetCPUProfile
(
w
io
.
Writer
)
{
func
GetCPUProfile
(
w
io
.
Writer
)
{
governor
.
GetCPUProfile
(
w
)
admin
.
GetCPUProfile
(
w
)
}
}
// PrintGCSummary print gc information to io.Writer
// PrintGCSummary print gc information to io.Writer
func
PrintGCSummary
(
w
io
.
Writer
)
{
func
PrintGCSummary
(
w
io
.
Writer
)
{
governor
.
PrintGCSummary
(
w
)
admin
.
PrintGCSummary
(
w
)
}
}
core/
governor
/command.go
→
core/
admin
/command.go
浏览文件 @
093f9763
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// See the License for the specific language governing permissions and
// limitations under the License.
// limitations under the License.
package
governor
package
admin
import
(
import
(
"github.com/pkg/errors"
"github.com/pkg/errors"
...
...
core/
governor
/healthcheck.go
→
core/
admin
/healthcheck.go
浏览文件 @
093f9763
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// See the License for the specific language governing permissions and
// limitations under the License.
// limitations under the License.
// Package
governor
healthcheck
// Package
admin
healthcheck
//
//
// type DatabaseCheck struct {
// type DatabaseCheck struct {
// }
// }
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
// AddHealthCheck("database",&DatabaseCheck{})
// AddHealthCheck("database",&DatabaseCheck{})
//
//
// more docs: http://beego.me/docs/module/toolbox.md
// more docs: http://beego.me/docs/module/toolbox.md
package
governor
package
admin
// AdminCheckList holds health checker map
// AdminCheckList holds health checker map
var
AdminCheckList
map
[
string
]
HealthChecker
var
AdminCheckList
map
[
string
]
HealthChecker
...
...
core/
governor
/profile.go
→
core/
admin
/profile.go
浏览文件 @
093f9763
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// See the License for the specific language governing permissions and
// limitations under the License.
// limitations under the License.
package
governor
package
admin
import
(
import
(
"fmt"
"fmt"
...
...
core/
governor
/profile_test.go
→
core/
admin
/profile_test.go
浏览文件 @
093f9763
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// See the License for the specific language governing permissions and
// limitations under the License.
// limitations under the License.
package
governor
package
admin
import
(
import
(
"os"
"os"
...
...
server/web/admin_controller.go
浏览文件 @
093f9763
...
@@ -24,7 +24,7 @@ import (
...
@@ -24,7 +24,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/astaxie/beego/core/
governor
"
"github.com/astaxie/beego/core/
admin
"
)
)
type
adminController
struct
{
type
adminController
struct
{
...
@@ -51,7 +51,7 @@ func (a *adminController) ProfIndex() {
...
@@ -51,7 +51,7 @@ func (a *adminController) ProfIndex() {
data
=
make
(
map
[
interface
{}]
interface
{})
data
=
make
(
map
[
interface
{}]
interface
{})
result
bytes
.
Buffer
result
bytes
.
Buffer
)
)
governor
.
ProcessInput
(
command
,
&
result
)
admin
.
ProcessInput
(
command
,
&
result
)
data
[
"Content"
]
=
template
.
HTMLEscapeString
(
result
.
String
())
data
[
"Content"
]
=
template
.
HTMLEscapeString
(
result
.
String
())
if
format
==
"json"
&&
command
==
"gc summary"
{
if
format
==
"json"
&&
command
==
"gc summary"
{
...
@@ -88,7 +88,7 @@ func (a *adminController) TaskStatus() {
...
@@ -88,7 +88,7 @@ func (a *adminController) TaskStatus() {
req
.
ParseForm
()
req
.
ParseForm
()
taskname
:=
req
.
Form
.
Get
(
"taskname"
)
taskname
:=
req
.
Form
.
Get
(
"taskname"
)
if
taskname
!=
""
{
if
taskname
!=
""
{
cmd
:=
governor
.
GetCommand
(
"task"
,
"run"
)
cmd
:=
admin
.
GetCommand
(
"task"
,
"run"
)
res
:=
cmd
.
Execute
(
taskname
)
res
:=
cmd
.
Execute
(
taskname
)
if
res
.
IsSuccess
()
{
if
res
.
IsSuccess
()
{
...
@@ -103,7 +103,7 @@ func (a *adminController) TaskStatus() {
...
@@ -103,7 +103,7 @@ func (a *adminController) TaskStatus() {
// List Tasks
// List Tasks
content
:=
make
(
M
)
content
:=
make
(
M
)
resultList
:=
governor
.
GetCommand
(
"task"
,
"list"
)
.
Execute
()
.
Content
.
([][]
string
)
resultList
:=
admin
.
GetCommand
(
"task"
,
"list"
)
.
Execute
()
.
Content
.
([][]
string
)
var
fields
=
[]
string
{
var
fields
=
[]
string
{
"Task Name"
,
"Task Name"
,
"Task Spec"
,
"Task Spec"
,
...
@@ -141,7 +141,7 @@ func heathCheck(rw http.ResponseWriter, r *http.Request) {
...
@@ -141,7 +141,7 @@ func heathCheck(rw http.ResponseWriter, r *http.Request) {
}
}
)
)
for
name
,
h
:=
range
governor
.
AdminCheckList
{
for
name
,
h
:=
range
admin
.
AdminCheckList
{
if
err
:=
h
.
Check
();
err
!=
nil
{
if
err
:=
h
.
Check
();
err
!=
nil
{
result
=
[]
string
{
result
=
[]
string
{
"error"
,
"error"
,
...
...
server/web/admin_test.go
浏览文件 @
093f9763
...
@@ -11,7 +11,7 @@ import (
...
@@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"github.com/astaxie/beego/core/
governor
"
"github.com/astaxie/beego/core/
admin
"
)
)
type
SampleDatabaseCheck
struct
{
type
SampleDatabaseCheck
struct
{
...
@@ -126,8 +126,8 @@ func TestWriteJSON(t *testing.T) {
...
@@ -126,8 +126,8 @@ func TestWriteJSON(t *testing.T) {
func
TestHealthCheckHandlerDefault
(
t
*
testing
.
T
)
{
func
TestHealthCheckHandlerDefault
(
t
*
testing
.
T
)
{
endpointPath
:=
"/healthcheck"
endpointPath
:=
"/healthcheck"
governor
.
AddHealthCheck
(
"database"
,
&
SampleDatabaseCheck
{})
admin
.
AddHealthCheck
(
"database"
,
&
SampleDatabaseCheck
{})
governor
.
AddHealthCheck
(
"cache"
,
&
SampleCacheCheck
{})
admin
.
AddHealthCheck
(
"cache"
,
&
SampleCacheCheck
{})
req
,
err
:=
http
.
NewRequest
(
"GET"
,
endpointPath
,
nil
)
req
,
err
:=
http
.
NewRequest
(
"GET"
,
endpointPath
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -187,8 +187,8 @@ func TestBuildHealthCheckResponseList(t *testing.T) {
...
@@ -187,8 +187,8 @@ func TestBuildHealthCheckResponseList(t *testing.T) {
func
TestHealthCheckHandlerReturnsJSON
(
t
*
testing
.
T
)
{
func
TestHealthCheckHandlerReturnsJSON
(
t
*
testing
.
T
)
{
governor
.
AddHealthCheck
(
"database"
,
&
SampleDatabaseCheck
{})
admin
.
AddHealthCheck
(
"database"
,
&
SampleDatabaseCheck
{})
governor
.
AddHealthCheck
(
"cache"
,
&
SampleCacheCheck
{})
admin
.
AddHealthCheck
(
"cache"
,
&
SampleCacheCheck
{})
req
,
err
:=
http
.
NewRequest
(
"GET"
,
"/healthcheck?json=true"
,
nil
)
req
,
err
:=
http
.
NewRequest
(
"GET"
,
"/healthcheck?json=true"
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
server/web/adminui.go
浏览文件 @
093f9763
...
@@ -21,7 +21,7 @@ var indexTpl = `
...
@@ -21,7 +21,7 @@ var indexTpl = `
For detail usage please check our document:
For detail usage please check our document:
</p>
</p>
<p>
<p>
<a target="_blank" href="http://beego.me/docs/module/
governor
.md">Toolbox</a>
<a target="_blank" href="http://beego.me/docs/module/
admin
.md">Toolbox</a>
</p>
</p>
<p>
<p>
<a target="_blank" href="http://beego.me/docs/advantage/monitor.md">Live Monitor</a>
<a target="_blank" href="http://beego.me/docs/advantage/monitor.md">Live Monitor</a>
...
...
task/govenor_command.go
浏览文件 @
093f9763
...
@@ -21,13 +21,13 @@ import (
...
@@ -21,13 +21,13 @@ import (
"github.com/pkg/errors"
"github.com/pkg/errors"
"github.com/astaxie/beego/core/
governor
"
"github.com/astaxie/beego/core/
admin
"
)
)
type
listTaskCommand
struct
{
type
listTaskCommand
struct
{
}
}
func
(
l
*
listTaskCommand
)
Execute
(
params
...
interface
{})
*
governor
.
Result
{
func
(
l
*
listTaskCommand
)
Execute
(
params
...
interface
{})
*
admin
.
Result
{
resultList
:=
make
([][]
string
,
0
,
len
(
globalTaskManager
.
adminTaskList
))
resultList
:=
make
([][]
string
,
0
,
len
(
globalTaskManager
.
adminTaskList
))
for
tname
,
tk
:=
range
globalTaskManager
.
adminTaskList
{
for
tname
,
tk
:=
range
globalTaskManager
.
adminTaskList
{
result
:=
[]
string
{
result
:=
[]
string
{
...
@@ -39,7 +39,7 @@ func (l *listTaskCommand) Execute(params ...interface{}) *governor.Result {
...
@@ -39,7 +39,7 @@ func (l *listTaskCommand) Execute(params ...interface{}) *governor.Result {
resultList
=
append
(
resultList
,
result
)
resultList
=
append
(
resultList
,
result
)
}
}
return
&
governor
.
Result
{
return
&
admin
.
Result
{
Status
:
200
,
Status
:
200
,
Content
:
resultList
,
Content
:
resultList
,
}
}
...
@@ -48,9 +48,9 @@ func (l *listTaskCommand) Execute(params ...interface{}) *governor.Result {
...
@@ -48,9 +48,9 @@ func (l *listTaskCommand) Execute(params ...interface{}) *governor.Result {
type
runTaskCommand
struct
{
type
runTaskCommand
struct
{
}
}
func
(
r
*
runTaskCommand
)
Execute
(
params
...
interface
{})
*
governor
.
Result
{
func
(
r
*
runTaskCommand
)
Execute
(
params
...
interface
{})
*
admin
.
Result
{
if
len
(
params
)
==
0
{
if
len
(
params
)
==
0
{
return
&
governor
.
Result
{
return
&
admin
.
Result
{
Status
:
400
,
Status
:
400
,
Error
:
errors
.
New
(
"task name not passed"
),
Error
:
errors
.
New
(
"task name not passed"
),
}
}
...
@@ -59,7 +59,7 @@ func (r *runTaskCommand) Execute(params ...interface{}) *governor.Result {
...
@@ -59,7 +59,7 @@ func (r *runTaskCommand) Execute(params ...interface{}) *governor.Result {
tn
,
ok
:=
params
[
0
]
.
(
string
)
tn
,
ok
:=
params
[
0
]
.
(
string
)
if
!
ok
{
if
!
ok
{
return
&
governor
.
Result
{
return
&
admin
.
Result
{
Status
:
400
,
Status
:
400
,
Error
:
errors
.
New
(
"parameter is invalid"
),
Error
:
errors
.
New
(
"parameter is invalid"
),
}
}
...
@@ -68,17 +68,17 @@ func (r *runTaskCommand) Execute(params ...interface{}) *governor.Result {
...
@@ -68,17 +68,17 @@ func (r *runTaskCommand) Execute(params ...interface{}) *governor.Result {
if
t
,
ok
:=
globalTaskManager
.
adminTaskList
[
tn
];
ok
{
if
t
,
ok
:=
globalTaskManager
.
adminTaskList
[
tn
];
ok
{
err
:=
t
.
Run
(
context
.
Background
())
err
:=
t
.
Run
(
context
.
Background
())
if
err
!=
nil
{
if
err
!=
nil
{
return
&
governor
.
Result
{
return
&
admin
.
Result
{
Status
:
500
,
Status
:
500
,
Error
:
err
,
Error
:
err
,
}
}
}
}
return
&
governor
.
Result
{
return
&
admin
.
Result
{
Status
:
200
,
Status
:
200
,
Content
:
t
.
GetStatus
(
context
.
Background
()),
Content
:
t
.
GetStatus
(
context
.
Background
()),
}
}
}
else
{
}
else
{
return
&
governor
.
Result
{
return
&
admin
.
Result
{
Status
:
400
,
Status
:
400
,
Error
:
errors
.
New
(
fmt
.
Sprintf
(
"task with name %s not found"
,
tn
)),
Error
:
errors
.
New
(
fmt
.
Sprintf
(
"task with name %s not found"
,
tn
)),
}
}
...
@@ -87,6 +87,6 @@ func (r *runTaskCommand) Execute(params ...interface{}) *governor.Result {
...
@@ -87,6 +87,6 @@ func (r *runTaskCommand) Execute(params ...interface{}) *governor.Result {
}
}
func
registerCommands
()
{
func
registerCommands
()
{
governor
.
RegisterCommand
(
"task"
,
"list"
,
&
listTaskCommand
{})
admin
.
RegisterCommand
(
"task"
,
"list"
,
&
listTaskCommand
{})
governor
.
RegisterCommand
(
"task"
,
"run"
,
&
runTaskCommand
{})
admin
.
RegisterCommand
(
"task"
,
"run"
,
&
runTaskCommand
{})
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录