This tutorial is intended for people with some experience writing Go who want to learn more about HTTP servers in Go. Some Go concepts are explained in detail and some, like how functions and variables are declared and used, are skipped.
- Handle incoming requests.
- Route requests to different handlers.
- Add logging middleware—a layer between the OS and your software application that can process data.
✔️ How to serve static assets.
✔️ How to create an HTTP handler.
✔️ How to route requests dynamically.
✔️ How to create middleware.
- Go (version 1.11 or higher). You can download the latest version from the Go site.
- Knowledge of Go syntax and basic concepts.
- Access to the terminal window on your computer. The commands assume you're using Bash or an equivalent.
- A code editor.
To start, download the starting code
git clone https://github.com/StyvenSoft/webserver-go.git
Go to project directory:
cd webserver-go
Use the auto setup script:
bash server-setup.sh
The web server is now running at localhost:8080
func ListenAndServe
func FileServer
type ServeMux
func StripPrefix