Answers for "https golang server"

Go
0

golang http server

type ApiResponse struct {
	Code    uint32
	Message string
}

func main() {
	router := http.NewServeMux()

	router.HandleFunc("/", (func(w http.ResponseWriter, r *http.Request) {
		json.NewEncoder(w).Encode(&ApiResponse{Code: http.StatusOK, Message: "Hello Wordl"})
	}))

	err := http.ListenAndServe(":3000", router)
	if err != nil {
		log.Fatal(err)
	}
}
Posted by: Guest on April-11-2022

Browse Popular Code Answers by Language