Answer the question
In order to leave comments, you need to log in
How to dynamically create a hyperlink (in Golang)?
How to programmatically create a link? It doesn't work to stick a GET request to the link text (in href). I try this (I also tried other formatting functions):
// hashLink - некий токен (хеш)
var tokenString = string(hashLink)
var dataRespon = fmt.Sprintf("Данные сохранены. Нажмите <a href=\"https://site.com/Link?%d\">ссылку</a>.", tokenString)
var myLink = "https://site.com/Link?"
var tokenString = string(hashLink)
var dataRespon = fmt.Sprintf("Данные сохранены. Нажмите <a href=\"%d%d\">ссылку</a>.", myLink, tokenString)
Answer the question
In order to leave comments, you need to log in
You need to replace %d with %s, you have a string data type, and %d is a number
Completely working example
package main
import "fmt"
func main() {
var myLink = `https://site.com/Link?`
var tokenString = string(`hash....`)
var dataRespon = fmt.Sprintf(`Данные сохранены. Нажмите <a href="%s%s">ссылку</a>.`, myLink, tokenString)
fmt.Printf(dataRespon)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question