模板函数
This commit is contained in:
parent
f5f61cf440
commit
628f9269ca
BIN
beego_demo1/beego_demo1.exe
Normal file
BIN
beego_demo1/beego_demo1.exe
Normal file
Binary file not shown.
@ -9,15 +9,15 @@ type RouterController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (r *RouterController) Get() {
|
||||
id :=r.Ctx.Input.Param(":id")
|
||||
func (r *RouterController) Get() {
|
||||
id := r.Ctx.Input.Param(":id")
|
||||
fmt.Println(id)
|
||||
r.Data["id"] = id
|
||||
if r.Ctx.Request.Method == "POST" {
|
||||
//终止业务逻辑
|
||||
r.StopRun()
|
||||
r.TplName = "test_router_post.html"
|
||||
} else if r.Ctx.Request.Method == "GET" {
|
||||
} else if r.Ctx.Request.Method == "GET" {
|
||||
r.TplName = "test_router.html"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
18
beego_demo1/controllers/templateController.go
Normal file
18
beego_demo1/controllers/templateController.go
Normal file
@ -0,0 +1,18 @@
|
||||
package controllers
|
||||
|
||||
import "github.com/astaxie/beego"
|
||||
|
||||
type Template2Controller struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (t *Template2Controller) Get() {
|
||||
t.Data["name"] = "逝水无痕"
|
||||
t.Data["a"] = 1
|
||||
t.Data["b"] = "xxx"
|
||||
t.Data["c"] = []int{}
|
||||
t.Data["d"] = 2
|
||||
t.TplName = "template2.html"
|
||||
}
|
||||
|
||||
|
@ -13,17 +13,17 @@ type UploadController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (u *UploadController) Prepare() {
|
||||
func (u *UploadController) Prepare() {
|
||||
u.EnableXSRF = false
|
||||
}
|
||||
|
||||
func (u *UploadController) Get() {
|
||||
func (u *UploadController) Get() {
|
||||
u.TplName = "upload.html"
|
||||
}
|
||||
|
||||
func (u *UploadController) Post() {
|
||||
func (u *UploadController) Post() {
|
||||
//获取上传的文件
|
||||
file,header,err := u.GetFile("uploadFile")
|
||||
file, header, err := u.GetFile("uploadFile")
|
||||
defer func() {
|
||||
file.Close()
|
||||
}()
|
||||
@ -38,8 +38,8 @@ func (u *UploadController) Post() {
|
||||
filenameOnly := strings.TrimSuffix(fileName, fileSuffix)
|
||||
//生成时间戳
|
||||
timeUnixInt := time.Now().Unix()
|
||||
timeUnixStr := strconv.FormatInt(timeUnixInt,10)
|
||||
u.SaveToFile("uploadFile","static/upload/"+filenameOnly+timeUnixStr+fileSuffix)
|
||||
timeUnixStr := strconv.FormatInt(timeUnixInt, 10)
|
||||
u.SaveToFile("uploadFile", "static/upload/"+filenameOnly+timeUnixStr+fileSuffix)
|
||||
//保存上传的文件
|
||||
//u.TplName = "success.html"
|
||||
result := make(map[string]interface{})
|
||||
|
@ -3,14 +3,21 @@ package controllers
|
||||
import "github.com/astaxie/beego"
|
||||
|
||||
type TemplateController struct {
|
||||
beego.Controller
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (v *TemplateController) Get() {
|
||||
type Test1 struct {
|
||||
Id int
|
||||
Name string
|
||||
Age int
|
||||
}
|
||||
|
||||
func (v *TemplateController) Get() {
|
||||
v.Data["name"] = "逝水无痕"
|
||||
v.Data["arrs"] = []int{1,2,3,4,5}
|
||||
v.Data["arrs"] = []int{1, 2, 3, 4, 5}
|
||||
v.Data["arrs1"] = []int{}
|
||||
v.Data["is_enable"] = true
|
||||
v.Data["age"] = 22
|
||||
v.Data["struct_data"] = Test1{Id: 1, Name: "朱毅骏", Age: 18}
|
||||
v.TplName = "template1.html"
|
||||
}
|
||||
|
@ -9,11 +9,11 @@ type XsrfController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (x *XsrfController) Prepare() {
|
||||
func (x *XsrfController) Prepare() {
|
||||
//controller级别关闭xsrf
|
||||
x.EnableXSRF = false
|
||||
}
|
||||
func (x *XsrfController) Get() {
|
||||
func (x *XsrfController) Get() {
|
||||
x.Data["xsrf"] = template.HTML(x.XSRFFormHTML())
|
||||
x.TplName = "xsrf.html"
|
||||
}
|
||||
|
@ -5,7 +5,9 @@ go 1.16
|
||||
require github.com/astaxie/beego v1.12.1
|
||||
|
||||
require (
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
|
||||
github.com/smartystreets/goconvey v1.6.4
|
||||
mvdan.cc/gofumpt v0.1.1 // indirect
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
||||
)
|
||||
|
@ -1,133 +1,72 @@
|
||||
github.com/Knetic/govaluate v3.0.0+incompatible h1:7o6+MAPhYTCF0+fdvoz1xDedhRb4f6s9Tn1Tt7/WTEg=
|
||||
github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
|
||||
github.com/OwnLocal/goes v1.0.0 h1:81QQ3z6dvLhgXlkNpLkaYhk8jiKS7saFG01xy039KaU=
|
||||
github.com/OwnLocal/goes v1.0.0/go.mod h1:8rIFjBGTue3lCU0wplczcUgt9Gxgrkkrw7etMIcn8TM=
|
||||
github.com/astaxie/beego v1.12.1 h1:dfpuoxpzLVgclveAXe4PyNKqkzgm5zF4tgF2B3kkM2I=
|
||||
github.com/astaxie/beego v1.12.1/go.mod h1:kPBWpSANNbSdIqOc8SUL9h+1oyBMZhROeYsXQDbidWQ=
|
||||
github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd h1:jZtX5jh5IOMu0fpOTC3ayh6QGSPJ/KWOv1lgPvbRw1M=
|
||||
github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd/go.mod h1:1b+Y/CofkYwXMUU0OhQqGvsY2Bvgr4j6jfT699wyZKQ=
|
||||
github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542 h1:nYXb+3jF6Oq/j8R/y90XrKpreCxIalBWfeyeKymgOPk=
|
||||
github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542/go.mod h1:kSeGC/p1AbBiEp5kat81+DSQrZenVBZXklMLaELspWU=
|
||||
github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737 h1:rRISKWyXfVxvoa702s91Zl5oREZTrR3yv+tXrrX7G/g=
|
||||
github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60=
|
||||
github.com/casbin/casbin v1.7.0 h1:PuzlE8w0JBg/DhIqnkF1Dewf3z+qmUZMVN07PonvVUQ=
|
||||
github.com/casbin/casbin v1.7.0/go.mod h1:c67qKN6Oum3UF5Q1+BByfFxkwKvhwW57ITjqwtzR1KE=
|
||||
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 h1:F1EaeKL/ta07PY/k9Os/UFtwERei2/XzGemhpGnBKNg=
|
||||
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
|
||||
github.com/couchbase/go-couchbase v0.0.0-20181122212707-3e9b6e1258bb h1:w3RapLhkA5+km9Z8vUkC6VCaskduJXvXwJg5neKnfDU=
|
||||
github.com/couchbase/go-couchbase v0.0.0-20181122212707-3e9b6e1258bb/go.mod h1:TWI8EKQMs5u5jLKW/tsb9VwauIrMIxQG1r5fMsswK5U=
|
||||
github.com/couchbase/gomemcached v0.0.0-20181122193126-5125a94a666c h1:K4FIibkr4//ziZKOKmt4RL0YImuTjLLBtwElf+F2lSQ=
|
||||
github.com/couchbase/gomemcached v0.0.0-20181122193126-5125a94a666c/go.mod h1:srVSlQLB8iXBVXHgnqemxUXqN6FCvClgCMPCsjBDR7c=
|
||||
github.com/couchbase/goutils v0.0.0-20180530154633-e865a1461c8a h1:Y5XsLCEhtEI8qbD9RP3Qlv5FXdTDHxZM9UPUnMRgBp8=
|
||||
github.com/couchbase/goutils v0.0.0-20180530154633-e865a1461c8a/go.mod h1:BQwMFlJzDjFDG3DJUdU0KORxn88UlsOULuxLExMh3Hs=
|
||||
github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76 h1:Lgdd/Qp96Qj8jqLpq2cI1I1X7BJnu06efS+XkhRoLUQ=
|
||||
github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76/go.mod h1:vYwsqCOLxGiisLwp9rITslkFNpZD5rz43tf41QFkTWY=
|
||||
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712 h1:aaQcKT9WumO6JEJcRyTqFVq4XUZiUcKR2/GI31TOcz8=
|
||||
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
|
||||
github.com/go-redis/redis v6.14.2+incompatible h1:UE9pLhzmWf+xHNmZsoccjXosPicuiNaInPgym8nzfg0=
|
||||
github.com/go-redis/redis v6.14.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
|
||||
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
|
||||
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
|
||||
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
|
||||
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
|
||||
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
|
||||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o=
|
||||
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/rogpeppe/go-internal v1.6.2 h1:aIihoIOHCiLZHxyoNQ+ABL4NKhFTgKLBdMLyEAh98m0=
|
||||
github.com/rogpeppe/go-internal v1.6.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 h1:DAYUYH5869yV94zvCES9F51oYtN5oGlwjxJJz7ZCnik=
|
||||
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
|
||||
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726 h1:xT+JlYxNGqyT+XcU8iUrN18JYed2TvG9yN5ULG2jATM=
|
||||
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw=
|
||||
github.com/siddontang/ledisdb v0.0.0-20181029004158-becf5f38d373 h1:p6IxqQMjab30l4lb9mmkIkkcE1yv6o0SKbPhW5pxqHI=
|
||||
github.com/siddontang/ledisdb v0.0.0-20181029004158-becf5f38d373/go.mod h1:mF1DpOSOUiJRMR+FDqaqu3EBqrybQtrDDszLUZ6oxPg=
|
||||
github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d h1:NVwnfyR3rENtlz62bcrkXME3INVUa4lcdGt+opvxExs=
|
||||
github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z92TR1JKMkLLoaOQk++LVnOKL3ScbJ8GNGA=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
|
||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/ssdb/gossdb v0.0.0-20180723034631-88f6b59b84ec h1:q6XVwXmKvCRHRqesF3cSv6lNqqHi0QWOvgDlSohg8UA=
|
||||
github.com/ssdb/gossdb v0.0.0-20180723034631-88f6b59b84ec/go.mod h1:QBvMkMya+gXctz3kmljlUCu/yB3GZ6oee+dUozsezQE=
|
||||
github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c h1:3eGShk3EQf5gJCYW+WzA0TEJQd37HLOmlYF7N0YJwv0=
|
||||
github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
|
||||
github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b h1:0Ve0/CCjiAiyKddUMUn3RwIGlq2iTW4GuVzyoKBYO/8=
|
||||
github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b/go.mod h1:Q12BUT7DqIlHRmgv3RskH+UCM/4eqVMgI0EMmlSpAXc=
|
||||
github.com/yuin/goldmark v1.2.1 h1:ruQGxdhGHe7FWOJPT0mKs5+pD2Xs1Bm/kdGlHO04FmM=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.4.0 h1:8pl+sMODzuvGJkmj2W4kZihvVb5mKm8pB/X44PIQHv8=
|
||||
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200117065230-39095c1d176c h1:FodBYPZKH5tAN2O60HlglMwXGAeV/4k+NKbli79M/2c=
|
||||
golang.org/x/tools v0.0.0-20200117065230-39095c1d176c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20210101214203-2dba1e4ea05c h1:dS09fXwOFF9cXBnIzZexIuUBj95U1NyQjkEhkgidDow=
|
||||
golang.org/x/tools v0.0.0-20210101214203-2dba1e4ea05c/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
mvdan.cc/gofumpt v0.1.1 h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA=
|
||||
mvdan.cc/gofumpt v0.1.1/go.mod h1:yXG1r1WqZVKWbVRtBWKWX9+CxGYfA51nSomhM0woR48=
|
||||
|
@ -9,16 +9,15 @@ import (
|
||||
func main() {
|
||||
//设置views路径
|
||||
//beego.SetViewsPath("front")
|
||||
port ,_ :=beego.AppConfig.Int("httpport")
|
||||
fmt.Printf("%d %T \n",port,port)
|
||||
port, _ := beego.AppConfig.Int("httpport")
|
||||
fmt.Printf("%d %T \n", port, port)
|
||||
username := beego.AppConfig.String("username")
|
||||
fmt.Printf("%s %T \n",username,username)
|
||||
fmt.Printf("%s %T \n", username, username)
|
||||
root := beego.AppConfig.String("root")
|
||||
fmt.Printf("%s %T \n",root,root)
|
||||
fmt.Printf("%s %T \n", root, root)
|
||||
//xsrf防护 对post请求起作用
|
||||
beego.BConfig.WebConfig.EnableXSRF =true
|
||||
beego.BConfig.WebConfig.EnableXSRF = true
|
||||
beego.BConfig.WebConfig.XSRFKey = "9029zyjlpydzxzyq9029"
|
||||
beego.BConfig.WebConfig.XSRFExpire = 3600
|
||||
beego.Run()
|
||||
}
|
||||
|
||||
|
@ -6,28 +6,30 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
beego.Router("/", &controllers.MainController{})
|
||||
beego.Router("/user",&controllers.UserController{})
|
||||
beego.Router("/params",&controllers.ParamsController{})
|
||||
//?代表 可以带可不带参数 :int 代表参数限制为int类型
|
||||
//beego.Router("/params/?:name:int",&controllers.Params2Controller{})
|
||||
beego.Router("/params/?:name([0-9+])",&controllers.Params2Controller{})
|
||||
//beego.Router("/params/login/?:name([0-9+])",&controllers.Params2Controller{},"get,post:Get") //请求方式:方法 get:Get *:Get
|
||||
//beego.Router("/params/login/?:name([0-9+])",&controllers.Params2Controller{},"get:Get;post:Post")
|
||||
beego.Router("/login",&controllers.LoginController{})
|
||||
beego.Router("/login2",&controllers.Login2Controller{})
|
||||
beego.Router("/other",&controllers.OtherTypeDataController{})
|
||||
beego.Router("/flashData",&controllers.FlashController{})
|
||||
beego.Router("/", &controllers.MainController{})
|
||||
beego.Router("/user", &controllers.UserController{})
|
||||
beego.Router("/params", &controllers.ParamsController{})
|
||||
//?代表 可以带可不带参数 :int 代表参数限制为int类型
|
||||
//beego.Router("/params/?:name:int",&controllers.Params2Controller{})
|
||||
beego.Router("/params/?:name([0-9+])", &controllers.Params2Controller{})
|
||||
//beego.Router("/params/login/?:name([0-9+])",&controllers.Params2Controller{},"get,post:Get") //请求方式:方法 get:Get *:Get
|
||||
//beego.Router("/params/login/?:name([0-9+])",&controllers.Params2Controller{},"get:Get;post:Post")
|
||||
beego.Router("/login", &controllers.LoginController{})
|
||||
beego.Router("/login2", &controllers.Login2Controller{})
|
||||
beego.Router("/other", &controllers.OtherTypeDataController{})
|
||||
beego.Router("/flashData", &controllers.FlashController{})
|
||||
|
||||
//正则路由
|
||||
beego.Router("/router/?:id:int",&controllers.RouterController{})
|
||||
//自动路由 http://localhost:8080/router/get 名字/请求方式
|
||||
beego.AutoRouter(&controllers.RouterController{})
|
||||
//自定义路由
|
||||
beego.Router("/router/custom/?:id:int",&controllers.RouterController{},"get,post:Get")
|
||||
//正则路由
|
||||
beego.Router("/router/?:id:int", &controllers.RouterController{})
|
||||
//自动路由 http://localhost:8080/router/get 名字/请求方式
|
||||
beego.AutoRouter(&controllers.RouterController{})
|
||||
//自定义路由
|
||||
beego.Router("/router/custom/?:id:int", &controllers.RouterController{}, "get,post:Get")
|
||||
|
||||
beego.Router("/xsrf",&controllers.XsrfController{})
|
||||
beego.Router("/upload",&controllers.UploadController{})
|
||||
|
||||
beego.Router("/template1",&controllers.TemplateController{})
|
||||
beego.Router("/xsrf", &controllers.XsrfController{})
|
||||
beego.Router("/upload", &controllers.UploadController{})
|
||||
//模板语法
|
||||
beego.Router("/template1", &controllers.TemplateController{})
|
||||
//模板函数
|
||||
beego.Router("/template2", &controllers.Template2Controller{})
|
||||
}
|
||||
|
@ -1,44 +0,0 @@
|
||||
### docker换源
|
||||
|
||||
1、换ustc源
|
||||
|
||||
```bash
|
||||
sudo vim /etc/docker/daemon.json
|
||||
```
|
||||
|
||||
添加
|
||||
|
||||
```json
|
||||
{
|
||||
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
|
||||
}
|
||||
```
|
||||
|
||||
2、换阿里源
|
||||
|
||||
[阿里云镜像加速](https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors)
|
||||
|
||||
sudo mkdir -p /etc/docker #创建目录
|
||||
|
||||
#在指定目录下添加如下文件内容
|
||||
|
||||
```bash
|
||||
sudo tee /etc/docker/daemon.json <<-'EOF'
|
||||
{
|
||||
"registry-mirrors": ["https://c4wq72kn.mirror.aliyuncs.com"]
|
||||
}
|
||||
EOF
|
||||
|
||||
sudo systemctl daemon-reload #重启加速器
|
||||
|
||||
sudo systemctl restart docker #重启docker
|
||||
```
|
||||
|
||||
3、163(网易)
|
||||
|
||||
```bash
|
||||
{
|
||||
"registry-mirrors": ["http://hub-mirror.c.163.com"]
|
||||
}
|
||||
```
|
||||
|
@ -1,12 +1,12 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
_ "beego_demo1/routers"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"runtime"
|
||||
"path/filepath"
|
||||
_ "beego_demo1/routers"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
@ -14,11 +14,10 @@ import (
|
||||
|
||||
func init() {
|
||||
_, file, _, _ := runtime.Caller(0)
|
||||
apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".." + string(filepath.Separator))))
|
||||
apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator))))
|
||||
beego.TestBeegoInit(apppath)
|
||||
}
|
||||
|
||||
|
||||
// TestBeego is a sample to run an endpoint test
|
||||
func TestBeego(t *testing.T) {
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
@ -28,12 +27,11 @@ func TestBeego(t *testing.T) {
|
||||
beego.Trace("testing", "TestBeego", "Code[%d]\n%s", w.Code, w.Body.String())
|
||||
|
||||
Convey("Subject: Test Station Endpoint\n", t, func() {
|
||||
Convey("Status Code Should Be 200", func() {
|
||||
So(w.Code, ShouldEqual, 200)
|
||||
})
|
||||
Convey("The Result Should Not Be Empty", func() {
|
||||
So(w.Body.Len(), ShouldBeGreaterThan, 0)
|
||||
})
|
||||
Convey("Status Code Should Be 200", func() {
|
||||
So(w.Code, ShouldEqual, 200)
|
||||
})
|
||||
Convey("The Result Should Not Be Empty", func() {
|
||||
So(w.Body.Len(), ShouldBeGreaterThan, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
18
beego_demo1/tests/test_format/test_format.go
Normal file
18
beego_demo1/tests/test_format/test_format.go
Normal file
@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
name := "逝水无痕"
|
||||
fmt.Println("逝水无痕")
|
||||
fmt.Print("逝水无痕2\n")
|
||||
fmt.Printf("你好,%s \n",name)
|
||||
fmt.Printf("%c \n",97)
|
||||
fmt.Printf("%c \n",'a')
|
||||
fmt.Printf("%t \n",true)
|
||||
fmt.Printf("%T \n",true)
|
||||
|
||||
//sprint 将格式化内容返回给xx
|
||||
xx := fmt.Sprintf("xxxxxx")
|
||||
fmt.Printf(xx)
|
||||
}
|
@ -47,5 +47,48 @@
|
||||
{{else}}
|
||||
空数组
|
||||
{{end}}
|
||||
<br>
|
||||
{{.struct_data.Id }}
|
||||
{{.struct_data.Name }}
|
||||
{{.struct_data.Age }}
|
||||
|
||||
<br>
|
||||
<!--with 伴随 用于重定向pipeline
|
||||
with 也支持else
|
||||
-->
|
||||
{{with .struct_data}}
|
||||
{{.Id}}
|
||||
{{.Name}}
|
||||
{{.Age}}
|
||||
{{end}}
|
||||
<br>
|
||||
<!--有name则显示,没有则输出else后内容 with支持else-->
|
||||
{{with .name1}}
|
||||
{{.}}
|
||||
{{else}}
|
||||
没有这个属性值
|
||||
{{end}}
|
||||
|
||||
<!--引入模板文件-->
|
||||
<!--
|
||||
template 后有两个参数
|
||||
1、模板文件
|
||||
2、`.` 当前上下文
|
||||
-->
|
||||
{{template "template11.html" .}}
|
||||
|
||||
<!--define模板-->
|
||||
{{define "my_define"}}
|
||||
<hr>
|
||||
<ul>
|
||||
<li>{{.name}}</li>
|
||||
<li>{{.name}}</li>
|
||||
<li>{{.name}}</li>
|
||||
</ul>
|
||||
<hr>
|
||||
{{end}}
|
||||
|
||||
|
||||
{{template "my_define" .}}
|
||||
</body>
|
||||
</html>
|
12
beego_demo1/views/template11.html
Normal file
12
beego_demo1/views/template11.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h4>这是模板文件,需要在template中引入</h4>
|
||||
|
||||
{{.name}}
|
||||
</body>
|
||||
</html>
|
30
beego_demo1/views/template2.html
Normal file
30
beego_demo1/views/template2.html
Normal file
@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>模板函数</h1>
|
||||
<!--print 相当于后端的Sprint-->
|
||||
{{print "逝水无痕"}}
|
||||
<br>
|
||||
{{"逝水无痕"}}
|
||||
<br>
|
||||
{{.name | printf "%s"}}
|
||||
<br>
|
||||
{{printf "%s = %d" (printf "%d+%d" 2 4) 6}}
|
||||
<br>
|
||||
{{.a}}
|
||||
{{.b}}
|
||||
{{.c}}
|
||||
<br>
|
||||
<!--只要一个为空则返回第一个为空的参数,若都不为空则返回最后一个非空阐述-->
|
||||
{{and .a .b .c}}
|
||||
<br>
|
||||
{{and .a .b .d}}
|
||||
<br>
|
||||
<!--只要有一个不为空,则返回最后一个不为空的-->
|
||||
{{or .a .b .c}}
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user