Last active
May 25, 2020 17:26
-
-
Save ukautz/d521d0143dff859f4d67d5ba5b9fe39d to your computer and use it in GitHub Desktop.
Medium > Intro to Go > Full HTTP server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// returns a `200 OK` response with the body `Hello World` to any incoming request | |
package main | |
import ( | |
"fmt" | |
"net/http" | |
) | |
func helloWorld(writer http.ResponseWriter, request *http.Request) { | |
writer.Write([]byte("Hello World")) | |
} | |
func main() { | |
fmt.Println("Starting HTTP server") | |
http.HandleFunc("/", helloWorld) | |
err := http.ListenAndServe(":12345", nil) | |
if err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment