草庐IT

swig-template

全部标签

go - 如何使用text/template预定义的 "call"函数?

我试图了解如何在text/template包中使用call函数。这是示例:typeHumanstruct{Namestring}func(h*Human)Say(strstring)string{returnstr}funcmain(){constletter=`{{.Name}}wantstosay{{"blabla"|.Say}}{{.Name}}wantstryagain,{{call.Say"blabla"}}.`varh=&Human{"Tim"}t:=template.Must(template.New("").Parse(letter))err:=t.Execute(os

go - 如何在 Go 和 Swig 中使用 LPCWSTR?

我正在尝试使用Swig将C库与Go结合使用。这是简化的代码,我知道我可以使用cgo,但我需要在Swig中使用带有LPCWSTR参数的函数。我在https://github.com/AllenDang/w32/blob/c92a5d7c8fed59d96a94905c1a4070fdb79478c9/typedef.go上看到了LPCWSTR相当于*uint16所以syscall.UTF16PtrFromString()似乎是我需要的,但是当我运行代码。我想知道我是否应该使用SwigcptrLPCWSTR。libtest.c#include#include#include"libtest

c++ - 通过 SWIG 从 C++ 调用 Go 回调函数

我正在尝试调用C++函数:voidTestFunc(void(*f)(void)){f();}来自Go代码。我真的希望我只是将一个Go函数传递给该函数。我知道我可以将它包装到一个类中,并使用%feature("director")解决它,但这不是我的最佳解决方案。根据我在thispage中看到的内容,Go中指向函数的指针,应该与C++中的相同,所以我尝试了以下.swig文件:%{#include"test.h"%}%typemap(gotype)FUNC*"func()"%typemap(in)FUNC*{$1=(void(*)(void))$input;}%applyFUNC*{vo

templates - text/html 模板包中的 "range"操作和 "pipeline"说明。戈朗

我试图在text/html模板包中获得一些优点。我已经从golang站点阅读了它的文档。很难理解.(点)在一般和一定时间范围内行动。“pipeline”到底是什么意思,可能因为我的英文不是母语,所以比较难理解):{{pipeline}}Thedefaulttextualrepresentationofthevalueofthepipelineiscopiedtotheoutput.让我们考虑一个例子:data:=map[string]interface{}{"struct":&Order{ID:1,CustID:2,Total:3.65,Name:"Something",},"name

templates - Golang 模板和有效字段测试

在Go的database/sql包中,有一堆Null[Type]结构可以帮助将数据库值(及其可能的空值)映射到代码中。我试图弄清楚如何测试结构field是否为null,或者换句话说,当它的Valid属性为false时。打印SQL字段的推荐方法是使用.Value属性,如下所示:{{.MyStruct.MyField.Value}}效果很好。但假设我有一些稍微复杂的东西,我需要根据其他东西来测试值,例如:{{range.SomeSlice}}{{.}}{{end}}碰巧,这也很有效,除非.MyField无效,在这种情况下我会收到错误消息“调用eq时出错:用于比较的类型无效”。该错误是有道理

http - Golang使用 "template"包生成动态网页给客户端耗时太长

使用template包生成动态网页给客户端时太慢了。测试代码如下,golang1.4.1http.Handle("/js/",(http.FileServer(http.Dir(webpath))))http.Handle("/css/",(http.FileServer(http.Dir(webpath))))http.Handle("/img/",(http.FileServer(http.Dir(webpath))))http.HandleFunc("/test",TestHandler)funcTestHandler(whttp.ResponseWriter,r*http.Re

templates - 如何在 Go 模板中解析超出范围的变量?

我有如下两个结构,我需要使用templates在模板上呈现数据盒。我得到这个错误:EmailisnotafieldofstructtypeNotes.问题似乎是范围循环中似乎只有范围结构的字段可用,所以我想知道如何从范围结构外部(例如电子邮件字符串)导入字段。该行为非常出乎意料。typenotesstruct{Notestringsfstring}typeuisstruct{notes[]NoteEmailstring}varuiuisHTML{{range.notes}}{{.Email}}{{.sf}}{{end}}Email{{.Email}}我检查了godocs,但它们似乎毫无

templates - 戈朗。如何使用 html/template 包创建循环函数

我正在尝试将循环实现为自定义函数。它需要迭代次数和大括号之间的内容,然后它应该迭代括号之间的内容n次。请看例子:ma​​in.gotemplate.Must(template.ParseFiles("palette.html")).Funcs(template.FuncMap{"loop":func(nint,contentstring)string{varrstringfori:=0;iindex.html{{define"index"}}{{loop16}}{{end}}{{end}}输出...16times是否可以实现?其动机是text/template的标准功能不允许仅在大括号

html - 为什么 html/template 不显示所有 html 条件注释?

我有一个简单的GoHTML模板,其中包含HTML条件注释:packagemainimport("html/template""os")varbody=``funcmain(){tmp:=template.Must(template.New("tmp").Parse(body))tmp.Execute(os.Stdout,nil)}Thisproduces:为什么html/template编译后删除那些条件注释? 最佳答案 我的解决方法是重新实现在提交时删除的noescape助手#938597eab997funcMap:=templa

戈朗 : Parse all templates in directory and subdirectories?

这是我的目录结构:app/template/layout/base.tmplindex.tmpltemplate.ParseGlob("*/*.tmpl")解析index.tmpl但不解析中的base.tmpllayout子目录。有没有办法递归解析所有模板? 最佳答案 不是没有实现你自己的功能来做到这一点,我一直在使用这样的东西funcParseTemplates()*template.Template{templ:=template.New("")err:=filepath.Walk("./views",func(pathstri