SilkyFalcon

Generation

generate functionMon, 05 Dec 2022

Create a webserver function with arguments that are parsed to json format

func main() { http.HandleFunc("/api/", func(res http.ResponseWriter, req *http.Request) { res.Header().Set("Content-Type", "application/json") var item Item item.Name = "John" payload, _ := json.Marshal(item) res.Write(payload) }) fmt.Println("Listening on port 3000...") http.ListenAndServe(":3000", nil) }

Questions about programming?Chat with your personal AI assistant