V
V
Vadim Rublev2020-12-02 13:02:36
go
Vadim Rublev, 2020-12-02 13:02:36

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)


Or like this:
var myLink = "https://site.com/Link?"
var tokenString = string(hashLink)
var dataRespon = fmt.Sprintf("Данные сохранены. Нажмите <a href=\"%d%d\">ссылку</a>.", myLink, tokenString)


As a result, I want to get a web link like: link
it's the same: https://site.com/Link?$2a$10$Xj10hPlP0n9bWfql3P/oz

Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Mamonov, 2020-12-02
@Vadim Rublev

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 question

Ask a Question

731 491 924 answers to any question