jjzjj

template-engine

全部标签

google-app-engine - 如何使用 github.com/golang/appengine 访问 Datastore?

我正在使用github.com/golang/appengine及其关联的“数据存储”。我希望这个包能让我在普通的Go网站中使用Datastore。不幸的是,我的c:=appengine.NewContext(rq)一直给我一个“NewContextpassedanunknownhttp.Request”错误。我的app.yaml包含application:sdklessdatastoremusicversion:1runtime:goapi_version:go1handlers:-url:/.*script:_go_appvm:truemanual_scaling:instance

转到错误 : undefined: "html/template". ParseFile

关闭。这个问题需要debuggingdetails.它目前不接受答案。编辑问题以包含desiredbehavior,aspecificproblemorerror,andtheshortestcodenecessarytoreproducetheproblem.这将有助于其他人回答问题。关闭7年前。Improvethisquestion编译代码时出现如下错误"html/模板未定义:"html/模板".ParseFile"在源代码的字符串处"t,_:=template.ParseFile("edit.html",nil)"packagemainimport("net/http""io/i

go - 如何使 template.Execute() 写入文件而不是 response.Writer?

我有下面的代码来解析模板文件并将解析后的html写入ResponseWriter:-packagemainimport("net/http""html/template")funchandler(whttp.ResponseWriter,r*http.Request){t,_:=template.ParseFiles("view.html")t.Execute(w,"HelloWorld!")}funcmain(){server:=http.Server{Addr:"127.0.0.1:8080",}http.HandleFunc("/view",handler)server.List

performance - 我应该在每个 http 请求上调用 template.ParseFiles(...) 还是只从主函数调用一次?

我正在使用html/template包使用go编程语言进行一些Web开发。在代码的某些位置,我需要调用函数template.ParseFiles(...)以便我可以从这些文件创建一个模板,然后使用temp.Execute(w,数据)。我想知道是在每个请求上创建模板还是在main中创建一次模板并声明一个全局变量更好。像大多数教程一样,现在我会根据处理函数的每个请求执行此操作。但是,我不知道如果我在每个请求上都这样做而不是将它们作为全局变量来浪费资源。这是它在每个请求上的样子funcViewStats(whttp.ResponseWriter,r*http.Request){//Getst

templates - 样式表不适用于使用 chi 路由器的 go html 模板

我正在开发具有以下项目结构的GoWeb应用程序:用户界面模板登录.tmpl静态的CSS主题.cssmain.go我的main.go代码(为简洁起见只显示相关部分)。我正在使用chirouter.funcmain(){r:=chi.NewRouter()vartemplates*template.Templatetemplates=template.Must(template.ParseGlob("ui/templates/*.tmpl"))fileServer:=http.FileServer(http.Dir("./ui/static/"))r.Handle("/static/",h

google-app-engine - 如何将结构数据放入go-lang的数据存储中

很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visitthehelpcenter.关闭9年前。如何在go-lang中将结构数据放入数据存储区://结构已创建。typeUserLoginstruct{userNamestringpassWordstring}//valuesassignedp1:=UserLogin{"poonam","mumbai123"}p2:=UserLogin{密码:"mumbai321",用户名:"abcd"}现在如何存储/放置/保存以上p1、p2到datastor

其他包中未定义 html/template 类型的 Golang 全局变量

我已经按照这个问题IsitnecessarytoputtemplatesintoamapforreusinginGo?中的建议声明了一个全局变量我在funcmain()之前在我的主包中声明了全局变量,但它仍然没有在另一个包中声明。packagemainimport{"html/template".....)vartmpl=template.New("master")funcmain(){funcinit(){_,err:=tmpl.ParseGlob("templates/*.html")iferr!=nil{log.Fatalln("Errorloadingtemplates:",e

google-app-engine - 将 reflect.Value 传递给 Google App Engine 中的 datastore.GetMulti

我有一个围绕datastore.GetMulti的包装函数mypkg.GetStart.包装函数的参数必须与appengine.GetMulti相同。为了这个例子,我想获得dst的前两个实体。我的代码目前如下所示,但不起作用。datastore.GetMulti产生错误datastore:dsthasinvalidtype。typemyEntitystruct{ValInt}keys:=[]*datastore.Key{keyOne,keyTwo,keyThree}entities:=make([]myEntity,3)mypkg.GetStart(c,keys,enities)我的m

google-app-engine - martini & appengine/golang,返回 memcached JSON 数据

我现在正在使用Martini和AppEngine/Go进行编码。我想使用内存缓存来提供JSON数据。但是返回的是无效的JSON格式,为什么返回的是“null”?null{"results":[{"Title":"Nikkei225","PriceTime":"2014-04-2506:28:00UTC","Price":"14,429.26","Diff":"+24.27(0.1%)"},{"Title":"USD/JPY","PriceTime":"2014-04-2520:49:00UTC","Price":"102.12-102.16","Diff":"-0.15(-0.1%)"

google-app-engine - 如何解决应用程序引擎/aetest 上下文因信息/警告调用而崩溃

在我的代码中,我希望能够记录,所以我已经在我的库周围传递了应用引擎上下文。然后,如果出现故障,我可以像这样登录到应用引擎:context.Warningf("这是不正确的!")我正在尝试编写一个单元测试来专门解决错误情况。我正在使用这样的appengine/aetest包:上下文,createErr:=aetest.NewContext(nil)当测试遇到上面的context.Warningf时,它失败了,因为aetest.Context没有实现那个功能。是否有推荐的解决方法?例如,我想我可以将一些变量设置为“liv”、“test”,然后在测试中不记录,但这看起来很老套。还是我在这里明