mirror of
https://github.com/astaxie/beego.git
synced 2024-11-23 18:00:54 +00:00
rename key world 'governor' to 'admin'
This commit is contained in:
parent
728296a7ae
commit
198b9cce5f
@ -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/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:
|
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:
|
|||||||
|
|
||||||
### Web Application
|
### 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
|
#### Create `hello` directory, cd `hello` directory
|
||||||
|
|
||||||
|
@ -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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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() {
|
|||||||
|
|
||||||
// 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)
|
||||||
}
|
}
|
||||||
|
@ -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"
|
@ -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 @@
|
|||||||
// 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
|
@ -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"
|
@ -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"
|
@ -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() {
|
|||||||
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() {
|
|||||||
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() {
|
|||||||
|
|
||||||
// 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) {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
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",
|
||||||
|
@ -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) {
|
|||||||
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) {
|
|||||||
|
|
||||||
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 {
|
||||||
|
@ -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>
|
||||||
|
@ -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 {
|
|||||||
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 {
|
|||||||
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 {
|
|||||||
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 {
|
|||||||
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 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func registerCommands() {
|
func registerCommands() {
|
||||||
governor.RegisterCommand("task", "list", &listTaskCommand{})
|
admin.RegisterCommand("task", "list", &listTaskCommand{})
|
||||||
governor.RegisterCommand("task", "run", &runTaskCommand{})
|
admin.RegisterCommand("task", "run", &runTaskCommand{})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user