dongqu1783 2014-08-05 12:13 采纳率: 100%
浏览 15
已采纳

Golang模板中的呼叫链接

Suppose you have the following code

router.Get("foo").URL("id", id)

If I want to do something similar in a go template. I believe I have to go the long way and create an intermediary variable.

{{ $urlGenerator := .Router.Get "foo" }}
{{ $urlGenerator.URL "id" .Id }}

Preferably it would look like something like this

{{ (.Router.Get "foo") .Url }}

Or simply

{{ .Router.Get("foo").Url }}

Has anyone found a way that works a little like this? I can not find anything in the documentation regarding this, other than pipes, which works as... pipes.

  • 写回答

1条回答 默认 最新

  • dongre6270 2014-08-05 12:27
    关注

    It's in the very end of the Arguments paragraph of the text/template package doc:

    • A parenthesized instance of one the above, for grouping. The result may be accessed by a field or map key invocation:
      • print (.F1 arg1) (.F2 arg2)
      • (.StructValuedMethod "arg").Field
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)