package main import ( "encoding/json" "net/http" ) func HandleJsonRequest(writer http.ResponseWriter, request *http.Request) { writer.Header().Set("Content-Type", "application/json") err := json.NewEncoder(writer).Encode(ProductList) if err != nil { Printfln("Error: %v", err.Error()) return } } func init() { http.HandleFunc("/json", HandleJsonRequest) }