将包含“%”的字符串传递给http.ResponseWriter会导致变量丢失

w is of type http.ResponseWriter

This is fine:

fmt.Fprintf(w, statusPercentage + " " + mostUpToDateStatusDownloaded + "/"+ mostUpToDateStatusOverallData)

output: 100 488 MB/488 MB

This causes a problem:

fmt.Fprintf(w, statusPercentage + "% " + mostUpToDateStatusDownloaded + "/"+ mostUpToDateStatusOverallData)

output: 100%! (MISSING)MB/488 MB

% is a special placeholder symbol. If you want to put it into a string as a symbol itself - duplicate it. Like:

fmt.Fprintf(w, "Growth %v %%", "50")

Output:

Growth 50%

It is usually not a good practice to use arbitrary application strings as the format specifier to fmt.Fprintf and friends. The application should either using a fixed format string or convert the string to bytes and write the bytes directly to the response.

Here's how to do it with a format string:

// note that '%' is quoted as %%
fmt.Fprintf(w, "%s%% %s/%s", statusPercentage, mostUpToDateStatusDownloaded, mostUpToDateStatusOverallData)

Here's how to skip the formatting and write directly to the response:

io.WriteString(w, statusPercentage + "% " + mostUpToDateStatusDownloaded + "/"+ mostUpToDateStatusOverallData)