未验证 提交 093f9763 编写于 作者: M Ming Deng 提交者: GitHub

Merge pull request #4355 from flycash/develop

rename key world 'governor' to 'admin'
......@@ -6,7 +6,7 @@ services.
It is inspired by Tornado, Sinatra and Flask. beego has some Go-specific features such as interfaces and struct
embedding.
![architecture](https://cdn.nlark.com/yuque/0/2020/png/755700/1607849779965-e243f61d-607f-4357-b292-e2c69aab1c11.png)
![architecture](https://cdn.nlark.com/yuque/0/2020/png/755700/1607857489109-1e267fce-d65f-4c5e-b915-5c475df33c58.png)
Beego is compos of four parts:
1. Base modules: including log module, config module, governor module;
......@@ -25,7 +25,7 @@ Beego is compos of four parts:
### Web Application
![Http Request](https://cdn.nlark.com/yuque/0/2020/png/755700/1607854896328-6db5ca04-281d-453e-9843-4777ed932874.png)
![Http Request](https://cdn.nlark.com/yuque/0/2020/png/755700/1607857462507-855ec543-7ce3-402d-a0cb-b2524d5a4b60.png)
#### Create `hello` directory, cd `hello` directory
......
......@@ -17,7 +17,7 @@ package adapter
import (
"time"
_ "github.com/astaxie/beego/core/governor"
_ "github.com/astaxie/beego/core/admin"
"github.com/astaxie/beego/server/web"
)
......
......@@ -31,19 +31,19 @@
package toolbox
import (
"github.com/astaxie/beego/core/governor"
"github.com/astaxie/beego/core/admin"
)
// AdminCheckList holds health checker map
// Deprecated using governor.AdminCheckList
// Deprecated using admin.AdminCheckList
var AdminCheckList map[string]HealthChecker
// HealthChecker health checker interface
type HealthChecker governor.HealthChecker
type HealthChecker admin.HealthChecker
// AddHealthCheck add health checker with name string
func AddHealthCheck(name string, hc HealthChecker) {
governor.AddHealthCheck(name, hc)
admin.AddHealthCheck(name, hc)
AdminCheckList[name] = hc
}
......
......@@ -19,7 +19,7 @@ import (
"os"
"time"
"github.com/astaxie/beego/core/governor"
"github.com/astaxie/beego/core/admin"
)
var startTime = time.Now()
......@@ -31,20 +31,20 @@ func init() {
// ProcessInput parse input command string
func ProcessInput(input string, w io.Writer) {
governor.ProcessInput(input, w)
admin.ProcessInput(input, w)
}
// MemProf record memory profile in pprof
func MemProf(w io.Writer) {
governor.MemProf(w)
admin.MemProf(w)
}
// GetCPUProfile start cpu profile monitor
func GetCPUProfile(w io.Writer) {
governor.GetCPUProfile(w)
admin.GetCPUProfile(w)
}
// PrintGCSummary print gc information to io.Writer
func PrintGCSummary(w io.Writer) {
governor.PrintGCSummary(w)
admin.PrintGCSummary(w)
}
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package governor
package admin
import (
"github.com/pkg/errors"
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Package governor healthcheck
// Package admin healthcheck
//
// type DatabaseCheck struct {
// }
......@@ -28,7 +28,7 @@
// AddHealthCheck("database",&DatabaseCheck{})
//
// more docs: http://beego.me/docs/module/toolbox.md
package governor
package admin
// AdminCheckList holds health checker map
var AdminCheckList map[string]HealthChecker
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package governor
package admin
import (
"fmt"
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package governor
package admin
import (
"os"
......
......@@ -24,7 +24,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/astaxie/beego/core/governor"
"github.com/astaxie/beego/core/admin"
)
type adminController struct {
......@@ -51,7 +51,7 @@ func (a *adminController) ProfIndex() {
data = make(map[interface{}]interface{})
result bytes.Buffer
)
governor.ProcessInput(command, &result)
admin.ProcessInput(command, &result)
data["Content"] = template.HTMLEscapeString(result.String())
if format == "json" && command == "gc summary" {
......@@ -88,7 +88,7 @@ func (a *adminController) TaskStatus() {
req.ParseForm()
taskname := req.Form.Get("taskname")
if taskname != "" {
cmd := governor.GetCommand("task", "run")
cmd := admin.GetCommand("task", "run")
res := cmd.Execute(taskname)
if res.IsSuccess() {
......@@ -103,7 +103,7 @@ func (a *adminController) TaskStatus() {
// List Tasks
content := make(M)
resultList := governor.GetCommand("task", "list").Execute().Content.([][]string)
resultList := admin.GetCommand("task", "list").Execute().Content.([][]string)
var fields = []string{
"Task Name",
"Task Spec",
......@@ -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 {
result = []string{
"error",
......
......@@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/astaxie/beego/core/governor"
"github.com/astaxie/beego/core/admin"
)
type SampleDatabaseCheck struct {
......@@ -126,8 +126,8 @@ func TestWriteJSON(t *testing.T) {
func TestHealthCheckHandlerDefault(t *testing.T) {
endpointPath := "/healthcheck"
governor.AddHealthCheck("database", &SampleDatabaseCheck{})
governor.AddHealthCheck("cache", &SampleCacheCheck{})
admin.AddHealthCheck("database", &SampleDatabaseCheck{})
admin.AddHealthCheck("cache", &SampleCacheCheck{})
req, err := http.NewRequest("GET", endpointPath, nil)
if err != nil {
......@@ -187,8 +187,8 @@ func TestBuildHealthCheckResponseList(t *testing.T) {
func TestHealthCheckHandlerReturnsJSON(t *testing.T) {
governor.AddHealthCheck("database", &SampleDatabaseCheck{})
governor.AddHealthCheck("cache", &SampleCacheCheck{})
admin.AddHealthCheck("database", &SampleDatabaseCheck{})
admin.AddHealthCheck("cache", &SampleCacheCheck{})
req, err := http.NewRequest("GET", "/healthcheck?json=true", nil)
if err != nil {
......
......@@ -21,7 +21,7 @@ var indexTpl = `
For detail usage please check our document:
</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>
<a target="_blank" href="http://beego.me/docs/advantage/monitor.md">Live Monitor</a>
......
......@@ -21,13 +21,13 @@ import (
"github.com/pkg/errors"
"github.com/astaxie/beego/core/governor"
"github.com/astaxie/beego/core/admin"
)
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))
for tname, tk := range globalTaskManager.adminTaskList {
result := []string{
......@@ -39,7 +39,7 @@ func (l *listTaskCommand) Execute(params ...interface{}) *governor.Result {
resultList = append(resultList, result)
}
return &governor.Result{
return &admin.Result{
Status: 200,
Content: resultList,
}
......@@ -48,9 +48,9 @@ func (l *listTaskCommand) Execute(params ...interface{}) *governor.Result {
type runTaskCommand struct {
}
func (r *runTaskCommand) Execute(params ...interface{}) *governor.Result {
func (r *runTaskCommand) Execute(params ...interface{}) *admin.Result {
if len(params) == 0 {
return &governor.Result{
return &admin.Result{
Status: 400,
Error: errors.New("task name not passed"),
}
......@@ -59,7 +59,7 @@ func (r *runTaskCommand) Execute(params ...interface{}) *governor.Result {
tn, ok := params[0].(string)
if !ok {
return &governor.Result{
return &admin.Result{
Status: 400,
Error: errors.New("parameter is invalid"),
}
......@@ -68,17 +68,17 @@ func (r *runTaskCommand) Execute(params ...interface{}) *governor.Result {
if t, ok := globalTaskManager.adminTaskList[tn]; ok {
err := t.Run(context.Background())
if err != nil {
return &governor.Result{
return &admin.Result{
Status: 500,
Error: err,
}
}
return &governor.Result{
return &admin.Result{
Status: 200,
Content: t.GetStatus(context.Background()),
}
} else {
return &governor.Result{
return &admin.Result{
Status: 400,
Error: errors.New(fmt.Sprintf("task with name %s not found", tn)),
}
......@@ -87,6 +87,6 @@ func (r *runTaskCommand) Execute(params ...interface{}) *governor.Result {
}
func registerCommands() {
governor.RegisterCommand("task", "list", &listTaskCommand{})
governor.RegisterCommand("task", "run", &runTaskCommand{})
admin.RegisterCommand("task", "list", &listTaskCommand{})
admin.RegisterCommand("task", "run", &runTaskCommand{})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册