bee
go get -u github.com/beego/bee/v2
Bee is a Fast and Flexible tool for managing your Beego Web Application.
Usage:
    bee command [arguments]
The commands are:
    version     show the bee & beego version
    migrate     run database migrations
    api         create an api application base on beego framework
    bale        packs non-Go files to Go source files    
    new         create an application base on beego framework
    run         run the app which can hot compile
    pack        compress an beego project
    fix         Fixes your application by making it compatible with newer versions of Beego
    dlv         Start a debugging session using Delve
    dockerize   Generates a Dockerfile for your Beego application
    generate    Source code generator
    hprose      Creates an RPC application based on Hprose and Beego frameworks
    pack        Compresses a Beego application into a single file
    rs          Run customized scripts
    run         Run the application by starting a local development server
    server      serving static content over HTTP on port
Use bee help [command] for more information about a command.

新建项目

bee new beegodemogo mod init

目录架构如下所示:

quickstart
|-- conf
|   `-- app.conf
|-- controllers
|   `-- default.go
|-- main.go
|-- models
|-- routers
|   `-- router.go
|-- static
|   |-- css
|   |-- img
|   `-- js
|-- tests
|   `-- default_test.go
`-- views
    `-- index.tpl

main.go是入口文件,一个典型的MVC架构

go项目的执行方式
图片

router.goweb.Router
"/"MainController的逻辑

2、web.Run的执行过程

app.confweb.AddAPPStartHook()

Controller运行机制

web.ControllerPostGetDeleteHead

beego是一个RESTful的框架,所以请求默认执行req.Method的方法

this.datathis.TplnameController/<方法名>.tpl
Render
this.Ctx.WriteString
func (this*MainController)Get(){
this.Ctx.WriteString("hello")
}

model层一般用来处理数据库操作,如果应用足够简单,就不需要Model,如果模块增加,需要复用,需要逻辑分离,那么model是必不可少的

view编写

tplhtml
{{.key}}

静态文件处理

static的目录

├──static
│├── css
│├── img
│└── js
beegostatic