'How can I parse quotes in golang template such that it doesn't get converted to ascii values on rendering of template?

I have following variable which I want to be rendered in my template:

str := "'~qas\\d{1,2}.abc.com' '~qas\\d{1,2}business.abc.com'"

In a template like this:

const tpl = `
server {
    listen 80;
    server_name {{ .Hosts }};

    #error_page  404              /404.html;

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
`

When this template is getting rendered its converting single quotes into ascii value

server {
    listen 80;
    server_name '~qas\d{1,2}.abc.com'
'~qas\d{1,2}business.abc.com';
 
 
 #error_page  404              /404.html;
 
     error_page   500 502 503 504  /50x.html;
     location = /50x.html {

The expected output is:

server {
    listen 80;
    server_name '~qas\d{1,2}.abc.com'
'~qas\d{1,2}business.abc.com';
 
 
 #error_page  404              /404.html;
 
     error_page   500 502 503 504  /50x.html;
     location = /50x.html {

here's sample code for reproducing the issue and testing it out. https://go.dev/play/p/h9vj-u--BUz

EDIT1: I am using sprint "github.com/Masterminds/sprig" which is incompatible with text/template hence I cannot use text/template instead of html/template



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source