草庐IT

gin-templating

全部标签

templates - golang 模板处理和泛型

我有两个golanghtml模板,如下:varmmap[string]stringm=make(map[string]string)m["First"]=`Firsttemplatetype{{.First}}`m["Second"]=`Secondtemplatetype{{.SecondF1}}{{.SecondF2}}`第一个html模板只有一个参数,名为First而第二个模板需要两个参数,名为SecondF1和SecondF2.现在我有一个包含两个字段的结构,一个用于接收模板名称,另一个用于接收模板参数。typetmplReceiverstruct{TmplNamestring

go - 无法使用 Gin 加载 HTML 模板

我在通过r.HTMLRender设置使用Gin框架加载html模板时遇到了一些问题。似乎找不到模板。我曾尝试使用以下助手:GinHTMLRender:https://gist.github.com/madhums/4340cbeb36871e227905EZGin模板:https://github.com/michelloworld/ez-gin-template在设置模板的默认路径时,这些似乎都不起作用(在我的例子中是app/views);为了达到这个目的,我的html模板文件结构如下所示:/workspace|-app|-views|-layouts|-application.ht

go template - 嵌套模板化

我有几个go模板。下面的例子过于简单,但它正确地表达了我的想法。例如,我有{{define"div-block"}}.....{{end}}现在我想在使用div-block时转移任何其他模板,这样我就可以在div中放置任何东西。例如:{{template"div-block".}}{{template"header"}}{{end}}{{template"div-block".}}1{{end}}“标题”是其他模板。使用go模板执行此操作的正确方法是什么?是否可以使用自定义功能来做到这一点?是否可以在go模板中制作自定义actions?(Action可以有end语句,因此也有主体,而函

mongodb - 使用 Gin 和 JobRunner

我正在使用JobRunner用于我的Golang项目的调度程序和Gin-gonic框架。我已经尝试过这个包并且它有效。问题是,当我想连接到我的数据库时,我无法访问调度函数中的gin上下文funcScheduleUrl(){jobrunner.Start()//optional:jobrunner.Start(poolint,concurrentint)(10,1)jobrunner.Schedule("@every20s",CheckExpiredUrl{})}//JobSpecificFunctionstypeCheckExpiredUrlstruct{//filtered}//Re

mongodb - 使用 gin-golang 将数据从 mongodb 显示到 html 页面?

我正在尝试检查MongoDB是否包含具有特定用户名和密码的数据。但是现在我得到的是所有数据而不是指定的数据。下面是我的代码:r.POST("/login",func(c*gin.Context){logedUser:=[]RegisterdUser{}name:=c.PostForm("userName")Password:=c.PostForm("userPassword")fmt.Println("insidecheckingsectionnnn",name,Password)session,err:=mgo.Dial("localhost:27017")iferr!=nil{pa

templates - 使用数据解析多个模板

如何将数据传递到正确的模板?我有以下模板并想解析它们layout.html:......{{template"main"}}list.html:{{define"main"}}{{range$index,$element:=.}}{{$element.Data1}}{{$element.Data2}}{{$element.Data3}}{{end}}{{end}}当我在处理函数中使用它时,只执行“主”模板,我没有得到布局。t,err:=template.ParseFiles(layoutPath,templatePath)t.ExecuteTemplate(w,"main",Data)

go - 在golang中使用gin包为特定路由表达中间件?

我为成功运行的路由制作了一个中间件,但有一个小问题,它会应用于所有路由,包括signup和login。我想社交signup和login路线,所有用户都将访问这两条路线。以下是我正在使用的代码:-路线.go/*SignupRoute*/Route{"SaveUser","POST","/signup",controller.SaveUser},/*LoginRoute*/Route{"LoginUser","POST","/login",controller.Login},/*AllCustomersRoutes*/Route{"SaveCustomers","POST","/custo

http - 我的字符串有特殊字符,http/template 的输出添加了 "(MISSING)"

我正在尝试建立一个小型网站,我使用html/模板来创建动态页面。页面上的一件事是这些URL中的URL列表,有时我需要字符编码。对于像ô(%C3%B4)这样的特殊字符。当我尝试使用html/模板将变量解析到页面中时,我得到以下结果:%!c(MISSING)3%!b(MISSING)4。我不知道这里出了什么问题typeSearch_liststruct{Search_namestringSearch_urlstringSearch_pricefloat64}funcgenerateSearchPage(languageint,qstring)(string,error){/*ommited

windows - 在 Windows 上安装 swaggo (swagger + gin)

我正在尝试在Windows上为gin-gonic设置swagger。swaggo的文档指出我应该运行:goget-ugithub.com/swaggo/swag/cmd/swag安装后我应该能够从我的项目的根目录中运行swaginit我有main.go,但是cmdlet声明如下:swag:Theterm'swag'isnotrecognizedasthenameofacmdlet,function,scriptfile,oroperableprogram.Checkthespellingofthename,orifapathwasincluded,verifythatthepathis

templates - 如何使用结构或变量值的字段作为模板名称?

我们可以通过{{define"home"}}定义模板名称,然后通过{{template"home"}}将其加载到其他(父)模板中>.如何通过变量值{{template.TemplateName}}加载模板。或者这是不可能的? 最佳答案 很遗憾,你不能。{{template}}操作的语法:{{template"name"}}Thetemplatewiththespecifiednameisexecutedwithnildata.{{template"name"pipeline}}Thetemplatewiththespecifiedn