1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-23 12:30:56 +00:00

rename key world 'governor' to 'admin'

This commit is contained in:
Ming Deng 2020-12-13 19:09:58 +08:00
parent 728296a7ae
commit 198b9cce5f
12 changed files with 39 additions and 39 deletions

View File

@ -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

View File

@ -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"
)

View File

@ -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
}

View File

@ -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)
}

View File

@ -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"

View File

@ -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

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package governor
package admin
import (
"fmt"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package governor
package admin
import (
"os"

View File

@ -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",

View File

@ -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 {

View File

@ -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>

View File

@ -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{})
}