github.com/tobgu/qframe@v0.4.0/internal/icolumn/generator.go (about) 1 package icolumn 2 3 import ( 4 "bytes" 5 6 "github.com/tobgu/qframe/filter" 7 "github.com/tobgu/qframe/internal/maps" 8 "github.com/tobgu/qframe/internal/template" 9 ) 10 11 //go:generate qfgenerate -source=ifilter -dst-file=filters_gen.go 12 //go:generate qfgenerate -source=idoc -dst-file=doc_gen.go 13 14 func spec(name, operator, templateStr string) template.Spec { 15 return template.Spec{ 16 Name: name, 17 Template: templateStr, 18 Values: map[string]interface{}{"name": name, "dataType": "int", "operator": operator}} 19 } 20 21 func colConstComparison(name, operator string) template.Spec { 22 return spec(name, operator, template.BasicColConstComparison) 23 } 24 25 func colColComparison(name, operator string) template.Spec { 26 return spec(name, operator, template.BasicColColComparison) 27 } 28 29 func GenerateFilters() (*bytes.Buffer, error) { 30 // If adding more filters here make sure to also add a reference to them 31 // in the corresponding filter map so that they can be looked up. 32 return template.GenerateFilters("icolumn", []template.Spec{ 33 colConstComparison("lt", filter.Lt), 34 colConstComparison("lte", filter.Lte), 35 colConstComparison("gt", filter.Gt), 36 colConstComparison("gte", filter.Gte), 37 colConstComparison("eq", "=="), // Go eq ("==") differs from qframe eq ("=") 38 colConstComparison("neq", filter.Neq), 39 colColComparison("lt2", filter.Lt), 40 colColComparison("lte2", filter.Lte), 41 colColComparison("gt2", filter.Gt), 42 colColComparison("gte2", filter.Gte), 43 colColComparison("eq2", "=="), // Go eq ("==") differs from qframe eq ("=") 44 colColComparison("neq2", filter.Neq), 45 }) 46 } 47 48 func GenerateDoc() (*bytes.Buffer, error) { 49 return template.GenerateDocs( 50 "icolumn", 51 maps.StringKeys(filterFuncs, filterFuncs2, multiInputFilterFuncs), 52 maps.StringKeys(aggregations)) 53 }