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 關注
- 286 瀏覽
添加回答
舉報