? go pwd
/Users/daixuan/qbox/go
? go bee new beeblog
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v1.10.0
2018/07/29 17:20:41 WARN ? 0001 You current workdir is not inside $GOPATH/src.
2018/07/29 17:20:41 INFO ? 0002 Creating application...
create /Users/daixuan/qbox/go/src/beeblog/
create /Users/daixuan/qbox/go/src/beeblog/conf/
create /Users/daixuan/qbox/go/src/beeblog/controllers/
create /Users/daixuan/qbox/go/src/beeblog/models/
create /Users/daixuan/qbox/go/src/beeblog/routers/
create /Users/daixuan/qbox/go/src/beeblog/tests/
create /Users/daixuan/qbox/go/src/beeblog/static/
create /Users/daixuan/qbox/go/src/beeblog/static/js/
create /Users/daixuan/qbox/go/src/beeblog/static/css/
create /Users/daixuan/qbox/go/src/beeblog/static/img/
create /Users/daixuan/qbox/go/src/beeblog/views/
create /Users/daixuan/qbox/go/src/beeblog/conf/app.conf
create /Users/daixuan/qbox/go/src/beeblog/controllers/default.go
create /Users/daixuan/qbox/go/src/beeblog/views/index.tpl
create /Users/daixuan/qbox/go/src/beeblog/routers/router.go
create /Users/daixuan/qbox/go/src/beeblog/tests/default_test.go
create /Users/daixuan/qbox/go/src/beeblog/main.go
2018/07/29 17:20:41 SUCCESS ? 0003 New application successfully created!
? go ll /Users/daixuan/qbox/go/src
total 0
drwxr-xr-x 10 daixuan staff 320 Jul 29 17:20 beeblog
? beeblog vim /Users/daixuan/qbox/go/src/beeblog/controllers/default.go
package controllers
import (
"github.com/astaxie/beego"
)
type MainController struct {
beego.Controller
}
func (c *MainController) Get() {
c.Data["Website"] = "beego.me"
c.Data["Email"] = "astaxie@gmail.com"
c.TplName = "index.tpl"
c.Data["TrueCond"] = true
c.Data["FalseCond"] = false
//添加一個(gè)結(jié)構(gòu)
type u struct{
Name string
Age int
Sex string
}
user := &u{
Name: "Joe",
Age: 20,
Sex: "Male",
}
c.Data["User"] = user
}
? beeblog vim /Users/daixuan/qbox/go/src/beeblog/views/index.tpl
Welcome to Beego
Beego is a simple & powerful Go web framework which is inspired by tornado and sinatra.
{{if .TrueCond}}
true condition
{{end}}
{{if .FalseCond}}
{{else}}
false condition.
{{end}}
{{.User.Name}}; {{.User.Age}}; {{.User.Sex}}
注意:為了解決循環(huán)嵌套的問題,可以使用with end的方式
10年積累的成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè)經(jīng)驗(yàn),可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先網(wǎng)站設(shè)計(jì)制作后付款的網(wǎng)站建設(shè)流程,更有白沙黎族免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
{{.User.Name}}; {{.User.Age}}; {{.User.Sex}}
這段代碼可以修改為如下,效果相同:
{{with .User}}
{{.Name}}; {{.Age}}; {{.Sex}}
{{end}}
? beeblog bee run beeblog
訪問:http://localhost:8080/
default.go 添加:
nums := []int{1,2,3,4,5,6,7,8,9,0}
c.Data["Nums"] = nums
index.tpl中添加:
{{.Nums}}
{{range .Nums}}
{{.}}
{{end}}
訪問:http://localhost:8080/
default.go 添加:
c.Data["TplVar"] = "hey guys"
index.tpl中添加:
{{$tplVar := .TplVar}}
{{$tplVar}}
訪問:http://localhost:8080/
beego中寫的任意html的代碼,它都會自動編碼
default.go 添加:
c.Data.["Html"]="hello beego"
index.tpl中添加:
{{.Html}}
訪問:http://localhost:8080/ 返回:
index.tpl中:
{{.Html}}
修改為如下即可:
{{str2html .Html}}
再訪問:http://localhost:8080/ 結(jié)果:
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。