tags := []string{"z1","z2"}
len := len(tags)-1
sqlStr := `
{{if .Tags}} and ( {{end}}
{{$L := .Lens}}
{{range $k,$v := .Tags}} find_in_set('{{$v}}',t1.block_tags)> 0 {{if ne $L $k}} or {{end}} {{end}}
{{if .Tags}} ) {{end}}
`
// ne 不等于
// sqlStr := `
// {{if .Tags}} and ( {{end}}
// {{range $k,$v := .Tags}} find_in_set('{{$v}}',t1.block_tags)> 0 {{if ne 2 $k}} or {{end}} {{end}}
// {{if .Tags}} ) {{end}}
// {{if ne .Lens 0}} or {{end}}
// `
sqlStr = base.RenderText(sqlStr, struct {
Tags []string
Lens int
}{tags, len})
fmt.Println(sqlStr)
go标准库-text/template
最新推荐文章于 2023-12-30 09:09:19 发布