草庐IT

Archive_Template

全部标签

go - 使用 archive/zip 处理嵌套的 zip 文件

我正在努力处理Go中嵌套的zip文件(其中一个zip文件包含另一个zip文件)。我正在尝试递归一个zip文件并列出它包含的所有文件。archive/zip为您提供了两种处理zip文件的方法:zip.NewReaderzip.OpenReaderOpenReader打开磁盘上的文件。NewReader接受一个io.ReaderAt和一个文件大小。当您使用其中任何一个遍历压缩文件时,您会为zip中的每个文件得到一个zip.File。要获取文件f的文件内容,您可以调用f.Open,它会为您提供一个zip.ReadCloser。要打开嵌套的zip文件,我需要使用NewReader,但是zip.

html - 无法从 html/template Golang 访问数据

我有三个串联的模板。base.html、menu.html、users.html。但是当我执行这些模板时,我只能从base.html访问上下文数据。这是我的处理程序:funcHandlerUser(reshttp.ResponseWriter,req*http.Request){ifreq.Method=="GET"{context:=Context{Title:"Users"}users,err:=GetUser(0)context.Data=map[string]interface{}{"users":users,}fmt.Println(context.Data)t,err:=t

ubuntu - dpkg : error processing archive/var/cache/apt/archives/golang-1. 6-go_1.6.2-0ubuntu5~16.04.2_amd64.deb (--unpack):

当我运行sudoapt-get-finstall时,它显示dpkg:错误处理。请在下面找到完整的日志并建议如何解决这个问题。我在Ubuntu16.04上运行VB5.0.10,并且已经安装了go1.8并且运行良好sudoapt-get-finstallReadingpackagelists...DoneBuildingdependencytreeReadingstateinformation...DoneCorrectingdependencies...DoneThefollowingpackageswereautomaticallyinstalledandarenolongerrequ

templates - template.ParseGlob() 可以解析子目录中的模板吗?

要清理模板文件夹,我想将常用模板保存在子文件夹中。目前我有以下文件结构:main.gotemplates/index.tpl#Maintemplateforthemainpagetemplates/includes/head.tpltemplates/includes/footer.tplhead.tpl和footer.tpl将在index.tpl中调用,如下所示:{{template"head".}}Mycontent{{template"footer".}}此外,文件使用template.ParseGlob()进行解析。以下是main.go的摘录:varviews=template

templates - 如何在 Go html/template 中获取 map 元素的结构字段?

我有一个结构任务:typeTaskstruct{cmdstringargs[]stringdescstring}然后我初始化了一个映射,它将上面的Task结构作为一个值,一个string作为键(任务名称)vartaskMap=map[string]Task{"find":Task{cmd:"find",args:[]string{"/tmp/"},desc:"findfilesin/tmpdir",},"grep":Task{cmd:"grep",args:[]string{"foo","/tmp/*","-R"},desc:"grepfilesmatchhavingfoo",},}我

go - Go语言如何指定 `template.ParseFiles`的文件位置?

看完thisvideo,我自己试试。但是,我收到panic错误panic:opentemplates/index.html:Thesystemcannotfindthepathspecified.Completeerroemessageislikethefollowing.Hello,GoWebDevelopment1.3panic:opentemplates/index.html:Thesystemcannotfindthepathspecified.goroutine1[running]:panic(0x789260,0xc082054e40)F:/Go/src/runtime/p

go - html/template 中 ParseFiles 函数的不同行为

我不明白为什么func(t*Template)Parsefiles(...与funcParseFiles(...的行为不同。这两个函数都来自“html/模板”包。packageexampleimport("html/template""io/ioutil""testing")funcMakeTemplate1(pathstring)*template.Template{returntemplate.Must(template.ParseFiles(path))}funcMakeTemplate2(pathstring)*template.Template{returntemplate.

go - 将 template.HTML 直接渲染到模板中

我最近更换了数据存储,作为副作用,我不得不将结构字段从template.HTML更改为string以与marshaller/兼容数据库驱动程序。此字段RenderedDesc包含通过russross/blackfriday传递的呈现的HTML.以前我可以将整个结构“按原样”传递到模板中,然后在模板中调用{{.RenderedDesc}}。因为它现在是一个字符串,所以我添加了一个过滤器以在模板渲染时将其转换回:templates.gofuncRenderUnsafe(sstring)template.HTML{returntemplate.HTML(s)}template.FuncMap

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

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