添加模板函数index not len等

This commit is contained in:
zhuyijun 2021-07-12 23:39:58 +08:00
parent 91d24b11c7
commit 876e5389a1
6 changed files with 89 additions and 1 deletions

View File

@ -19,5 +19,9 @@ func (t *Template2Controller) Get() {
t.Data["c"] = []int{}
t.Data["d"] = 2
t.Data["func_test"] = Test
t.Data["data_map"] = map[string]string{"name": "逝水无痕"}
t.Data["arrs"] = []int{9, 7, 5, 3}
t.Data["str_data"] = "abc"
t.Data["is_true"] = true
t.TplName = "template2.html"
}

View File

@ -5,6 +5,7 @@ go 1.16
require github.com/astaxie/beego v1.12.3
require (
github.com/astaxie/bee v1.8.3 // indirect
github.com/beego/bee v1.12.3 // indirect
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
github.com/smartystreets/goconvey v1.6.4

View File

@ -25,6 +25,8 @@ github.com/alicebob/miniredis v2.5.0+incompatible/go.mod h1:8HZjEj4yU0dwhYHky+Dx
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/astaxie/bee v1.8.3 h1:43jkNp5ThS6GRsWwTFXq2D7920UHK2TtMYicwlcL3cw=
github.com/astaxie/bee v1.8.3/go.mod h1:igluqUb7jM5OcnSbOkZ+wLZtS2Kmyu4Y3nV/84JCU78=
github.com/astaxie/beego v1.12.1/go.mod h1:kPBWpSANNbSdIqOc8SUL9h+1oyBMZhROeYsXQDbidWQ=
github.com/astaxie/beego v1.12.3 h1:SAQkdD2ePye+v8Gn1r4X6IKZM1wd28EyUOVQ3PDSOOQ=
github.com/astaxie/beego v1.12.3/go.mod h1:p3qIm0Ryx7zeBHLljmd7omloyca1s4yu1a8kM1FkpIA=
@ -443,6 +445,7 @@ google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@ -0,0 +1,34 @@
package main
import "fmt"
func main() {
/*
1声明chan类型
*/
var ch1 chan int
fmt.Println(ch1)
//只写通道
var ch2 chan<- string
fmt.Println(ch2)
//只读通道
var ch3 <-chan int
fmt.Println(ch3)
chll := make(chan string, 3)
fmt.Println(chll)
//创建一个只读
ch12 := make(<-chan int)
//创建一个只写
ch13 := make(chan<- int)
fmt.Println(ch12)
fmt.Println(ch13)
go func() {
chll <- "你好1"
chll <- "你好2"
chll <- "你好3"
}()
fmt.Println(<-chll)
fmt.Println(<-chll)
fmt.Println(<-chll)
}

View File

@ -0,0 +1,23 @@
package main
import "fmt"
var do = make(chan int)
var close = make(chan int)
func test() {
for i := 0; i < 100; i++ {
<-do
fmt.Println("子携程")
close <- 1
}
}
func main() {
go test()
for i := 0; i < 100; i++ {
do <- 1
fmt.Println("主携程")
<-close
}
}

View File

@ -33,7 +33,30 @@
<br>
<!--call 函数 参数1 参数2 ...-->
{{call .func_test "逝水无痕"}}
<br>
<!--index 读取指定类型对应的下标值-->
{{index .data_map "name"}}
{{index .arrs 1}}
{{index .str_data 2}}
<br>
{{.data_map | len}}
{{.arrs | len}}
{{.str_data | len}}
<br>
<!--not 取反-->
{{not .is_true}}
{{not 1}}
{{not 0}}
<br>
<!--urlquery 网址传后端特殊字符转换-->
{{urlquery "http://www.baidu.com"}}
<br>
{{eq 2 3}}
{{ne 2 3}}
{{lt 2 4}}
{{le 3 3}}
{{gt 4 2}}
{{ge 4 4}}
</body>
</html>