如何使用golang连接锚标记的href属性中变量的值
How to concatenate values from a variable in href attribute of anchor tag using golang
我创建了一个 API 来发送带有 URL 的电子邮件。
我想在 URL 中添加一个参数,例如 id,我已将值保存在变量 'id' 中。所以 URL 应该看起来像:“somewebsite/empid=(id 的值)”
var id = "11221" // in go
<body>
<a href = "www.somewebsite.com/empid=(value of id)"> Click here </a>
</body>
我怎样才能做到这一点?
我的邮件是这样发送的:
id = "122"
m := gomail.NewMessage()
m.SetHeader("From", "prakashprem.pp2@gmail.com")
m.SetHeader("To", email)
m.SetHeader("Subject", "Paasword Reset for Kibbcom India")
m.SetBody("text/html", "Hi! <br> Please click on <a href = 'https://onboarding.kibbcom.in/forgotpassword?emp=id'>https://onboarding.kibbcom.in/forgotpassword</a>")
这里我给id作为静态值。
您可以使用 +
运算符连接字符串:
id = "122"
m := gomail.NewMessage()
m.SetHeader("From", "example@gmail.com")
m.SetHeader("To", email)
m.SetHeader("Subject", "Paasword Reset for Kibbcom India")
m.SetBody("text/html", "Hi! <br> Please click on <a href = 'https://onboarding.kibbcom.in/forgotpassword?emp="+id+"'>https://onboarding.kibbcom.in/forgotpassword</a>")
您还可以使用 fmt
包来插入字符串:
id = "122"
m := gomail.NewMessage()
m.SetHeader("From", "example@gmail.com")
m.SetHeader("To", email)
m.SetHeader("Subject", "Paasword Reset for Kibbcom India")
m.SetBody("text/html", fmt.Sprintf("Hi! <br> Please click on <a href = 'https://onboarding.kibbcom.in/forgotpassword?emp=%s'>https://onboarding.kibbcom.in/forgotpassword</a>", id))
我创建了一个 API 来发送带有 URL 的电子邮件。
我想在 URL 中添加一个参数,例如 id,我已将值保存在变量 'id' 中。所以 URL 应该看起来像:“somewebsite/empid=(id 的值)”
var id = "11221" // in go
<body>
<a href = "www.somewebsite.com/empid=(value of id)"> Click here </a>
</body>
我怎样才能做到这一点?
我的邮件是这样发送的:
id = "122"
m := gomail.NewMessage()
m.SetHeader("From", "prakashprem.pp2@gmail.com")
m.SetHeader("To", email)
m.SetHeader("Subject", "Paasword Reset for Kibbcom India")
m.SetBody("text/html", "Hi! <br> Please click on <a href = 'https://onboarding.kibbcom.in/forgotpassword?emp=id'>https://onboarding.kibbcom.in/forgotpassword</a>")
这里我给id作为静态值。
您可以使用 +
运算符连接字符串:
id = "122"
m := gomail.NewMessage()
m.SetHeader("From", "example@gmail.com")
m.SetHeader("To", email)
m.SetHeader("Subject", "Paasword Reset for Kibbcom India")
m.SetBody("text/html", "Hi! <br> Please click on <a href = 'https://onboarding.kibbcom.in/forgotpassword?emp="+id+"'>https://onboarding.kibbcom.in/forgotpassword</a>")
您还可以使用 fmt
包来插入字符串:
id = "122"
m := gomail.NewMessage()
m.SetHeader("From", "example@gmail.com")
m.SetHeader("To", email)
m.SetHeader("Subject", "Paasword Reset for Kibbcom India")
m.SetBody("text/html", fmt.Sprintf("Hi! <br> Please click on <a href = 'https://onboarding.kibbcom.in/forgotpassword?emp=%s'>https://onboarding.kibbcom.in/forgotpassword</a>", id))