1 回答
TA贡献1772条经验 获得超5个赞
尝试这个。
func GenerateGodocLinkInReadme(amqpLinks string, httpLinks string) {
path := `README.md`
formattedContent, err := ioutil.ReadFile(path)
if err != nil {
panic(err)
}
amqpRegex := regexp.MustCompile(`<!--AMQP-API-start-->([\s\S]*?)<!--AMQP-API-end-->`)
httpRegex := regexp.MustCompile(`<!--HTTP-API-start-->([\s\S]*?)<!--HTTP-API-end-->`)
prevAmqpLinks := string(amqpRegex.FindSubmatch((formattedContent))[1]) // Second index of returns links between tags
prevHttpLinks := string(httpRegex.FindSubmatch((formattedContent))[1]) // Second index of returns links between tags
httpAPI := prevHttpLinks + httpLinks + "\n"
AmqpAPI := prevAmqpLinks + amqpLinks + "\n"
formattedContent = amqpRegex.ReplaceAll(formattedContent, []byte(`<!--AMQP-API-start-->` + AmqpAPI + `<!--AMQP-API-end-->`))
formattedContent = httpRegex.ReplaceAll(formattedContent, []byte(`<!--HTTP-API-start-->` + httpAPI + `<!--HTTP-API-end-->`))
exitOnFail(ioutil.WriteFile(path, formattedContent, 0644))
}
- 1 回答
- 0 关注
- 314 浏览
添加回答
举报
