-
-
Save Ebazhanov/8ddd295a60bf4db6ac47a4e21376e096 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