This is the code I'm working with:
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", TestFunc)
http.ListenAndServe(":8080", nil)
}
func TestFunc(w http.ResponseWriter, r *http.Request) {
fmt.Println("test")
// --------------------- headers ------------------------
w.Header().Set("Accept-Charset", "utf-8")
w.Header().Set("Accept-Encoding", "gzip")
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusOK)
}
The code above works and prints two result (test test) every time.
When I remove the headers, code works fine and returns only "test".
What is the issue in this code?