Skip to content

Creating a test web server in Go! Adding static assets and creating multiple routes on the server. Learn what middleware is and how to build it in Go.

Notifications You must be signed in to change notification settings

StyvenSoft/webserver-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Creating a Web Server in Go

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.

build a web server:

  • Handle incoming requests.
  • Route requests to different handlers.
  • Add logging middleware—a layer between the OS and your software application that can process data.

learning

✔️ How to serve static assets.

✔️ How to create an HTTP handler.

✔️ How to route requests dynamically.

✔️ How to create middleware.

Requirements

  • 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.

Run the server

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


Reference docs

HTTP package documentation

func ListenAndServe

func FileServer

type ServeMux

func StripPrefix

About

Creating a test web server in Go! Adding static assets and creating multiple routes on the server. Learn what middleware is and how to build it in Go.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published