From 198b9cce5f14cbc30a3f43c4bf048a9374703173 Mon Sep 17 00:00:00 2001
From: Ming Deng
Date: Sun, 13 Dec 2020 19:09:58 +0800
Subject: [PATCH] rename key world 'governor' to 'admin'
---
README.md | 4 ++--
adapter/admin.go | 2 +-
adapter/toolbox/healthcheck.go | 8 ++++----
adapter/toolbox/profile.go | 10 +++++-----
core/{governor => admin}/command.go | 2 +-
core/{governor => admin}/healthcheck.go | 4 ++--
core/{governor => admin}/profile.go | 2 +-
core/{governor => admin}/profile_test.go | 2 +-
server/web/admin_controller.go | 10 +++++-----
server/web/admin_test.go | 10 +++++-----
server/web/adminui.go | 2 +-
task/govenor_command.go | 22 +++++++++++-----------
12 files changed, 39 insertions(+), 39 deletions(-)
rename core/{governor => admin}/command.go (99%)
rename core/{governor => admin}/healthcheck.go (96%)
rename core/{governor => admin}/profile.go (99%)
rename core/{governor => admin}/profile_test.go (98%)
diff --git a/README.md b/README.md
index f3abf505..dc048bba 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/adapter/admin.go b/adapter/admin.go
index e555f59e..828ee399 100644
--- a/adapter/admin.go
+++ b/adapter/admin.go
@@ -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"
)
diff --git a/adapter/toolbox/healthcheck.go b/adapter/toolbox/healthcheck.go
index 7d89c2fb..cb07e6aa 100644
--- a/adapter/toolbox/healthcheck.go
+++ b/adapter/toolbox/healthcheck.go
@@ -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
}
diff --git a/adapter/toolbox/profile.go b/adapter/toolbox/profile.go
index a5434360..09a97542 100644
--- a/adapter/toolbox/profile.go
+++ b/adapter/toolbox/profile.go
@@ -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)
}
diff --git a/core/governor/command.go b/core/admin/command.go
similarity index 99%
rename from core/governor/command.go
rename to core/admin/command.go
index 75df5815..f65d2750 100644
--- a/core/governor/command.go
+++ b/core/admin/command.go
@@ -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"
diff --git a/core/governor/healthcheck.go b/core/admin/healthcheck.go
similarity index 96%
rename from core/governor/healthcheck.go
rename to core/admin/healthcheck.go
index a91f09fa..79738d1d 100644
--- a/core/governor/healthcheck.go
+++ b/core/admin/healthcheck.go
@@ -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
diff --git a/core/governor/profile.go b/core/admin/profile.go
similarity index 99%
rename from core/governor/profile.go
rename to core/admin/profile.go
index 17f1f375..1e4e4953 100644
--- a/core/governor/profile.go
+++ b/core/admin/profile.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package governor
+package admin
import (
"fmt"
diff --git a/core/governor/profile_test.go b/core/admin/profile_test.go
similarity index 98%
rename from core/governor/profile_test.go
rename to core/admin/profile_test.go
index 530b0637..139c4b99 100644
--- a/core/governor/profile_test.go
+++ b/core/admin/profile_test.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package governor
+package admin
import (
"os"
diff --git a/server/web/admin_controller.go b/server/web/admin_controller.go
index 2998c8d4..60296976 100644
--- a/server/web/admin_controller.go
+++ b/server/web/admin_controller.go
@@ -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",
diff --git a/server/web/admin_test.go b/server/web/admin_test.go
index 5ef57323..9ab11ee3 100644
--- a/server/web/admin_test.go
+++ b/server/web/admin_test.go
@@ -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 {
diff --git a/server/web/adminui.go b/server/web/adminui.go
index de8c9455..54d67354 100644
--- a/server/web/adminui.go
+++ b/server/web/adminui.go
@@ -21,7 +21,7 @@ var indexTpl = `
For detail usage please check our document:
-Toolbox
+Toolbox
Live Monitor
diff --git a/task/govenor_command.go b/task/govenor_command.go
index 15e25e43..8dd92b67 100644
--- a/task/govenor_command.go
+++ b/task/govenor_command.go
@@ -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{})
}