Created
April 17, 2020 03:27
-
-
Save monkrus/cfb9f29fa0d36cb907a59a9ed25562bf to your computer and use it in GitHub Desktop.
Write web server in 5 lines of code
This file contains 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
package main | |
import ( | |
"log" | |
"net/http" | |
) | |
func main() { | |
//root path handles EVERY request received | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
//input/outputs work with slices of bytes | |
w.Write([]byte("sos")) | |
}) | |
err := http.ListenAndServe(":3000", nil) | |
if err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment