在Go模板中显示可变图像

I'm using a template in a Go web application which should show an image depending on which country the visitor is from.

For the images I use the FileServer

http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir("images"))))

In the template the variable country is passed so the application knows which flag to show.

<img id='flag' src='images/{{ .Country}}.png'>

However, for some reason the string I pass adds %0a which causes the src of the img to be wrong.

<img id='flag' src='images/BE%0A.png'>

The expected output should be

<img id='flag' src='images/BE.png'>

The following code is used to grab the country string

resp3, err := http.Get("https://ipinfo.io/country")
if err != nil {
    fmt.Println(err)
}
bytes3, _ := ioutil.ReadAll(resp3.Body)
country := string(bytes3)

Could anyone help me resolve this issue?

the string I pass adds %0a which causes the src of the img to be wrong.

<img id='flag' src='images/BE%0A.png'>

The expected output should be

<img id='flag' src='images/BE.png'>

Trim the newline (0x0A or " "). For example,

package main

import (
    "bytes"
    "fmt"
    "io/ioutil"
    "net/http"
)

func main() {
    resp3, err := http.Get("https://ipinfo.io/country")
    if err != nil {
        fmt.Println(err)
    }
    bytes3, err := ioutil.ReadAll(resp3.Body)
    if err != nil {
        fmt.Println(err)
    }
    fmt.Printf("%q
", bytes3)
    country := string(bytes.TrimRight(bytes3, "
"))
    fmt.Printf("%q
", country)
}

Output:

"US
"
"US"