Basic web server in Golang

package main// package “main” tells the Go compiler that the package should compile as an executable
import ("fmt""log""net/http")//http.ResponseWriter value assembles the HTTP server's response, http.Request represent the client HTTP requestfunc handler(w http.ResponseWriter, r *http.Request) {//r.URL.Path is the path component of the request URLfmt.Fprintf(w, "Hello i'm a huge fan of %s!", r.URL.Path[1:])}func main() {//HandleFunc tells the http package to handle all requests to the root "/" with handlerhttp.HandleFunc("/", handler)//It then calls http.ListenAndServe specifying to listen on port 8080log.Fatal(http.ListenAndServe(":8080", nil))}
go run .\yourfile.go
go run .\server.go

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store