dongtie0929 2018-06-25 15:32
浏览 92
已采纳

生成后的模板标识

I'm generating a makefile using GO text/template The template is generated as expected (with the right content ) but the problem is that it’s not indented with tabs and I got errors while running make command after generation.

This is the output of the template:

all: app app_2

DIR = $(PWD)
.PHONY: app
app:
@echo "run module 1"

.PHONY: app_2
app_2:
@echo "run module 2”

When I run make I got error "makefile:7: *** missing separator. Stop.” (This is the line with the first echo”)

If I change the ideation to tab (after the file was generated) with Goland or vsCode, I was able to run the file successfully and see the expected output..., any idea how to make it work with go text/template ?

This is the template

all: {{- range .Load.Proc}} {{.Name}}{{end}}


{{- range .Load.Proc}}
.PHONY: {{.Name}}
{{.Name}}:
    @echo {{.Text}}
{{end}}

This is the makefile issue: makefile:4: *** missing separator. Stop but for me it's a problem since I want to generate the file without the need to manually change the indentation.

  • 写回答

1条回答 默认 最新

  • dpiuqwwyu187975836 2018-06-25 16:18
    关注

    Use tab characters in the template to produce tabs in the output. To fix the template in the question, replace the spaces before @echo with a tab character.

    https://play.golang.org/p/c7v6eNsI2Fy

    If you cannot put tabs in the template for some reason, then use {{"\t"}} to produce a tab in the output:

    {{"\t"}}echo {{.Text}}
    

    https://play.golang.org/p/3B-oIW-aCb4

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)