Learn Web Programming in Go by Examples

About the Go programming language

Go is an open source programming language designed for building simple, fast, and reliable software. Take a look here which great companies use Go to power their services.

Go Web Examples provides easy to understand code snippets on how to do web development in the Go programming language. It is inspired by Go By Example, which has a great introduction into the fundamentals of this language.

If you are learning web programming in Go or just starting out you can find some good examples and tutorials here. Our goal is it to provide clean examples with great detail, so you can become the next Go web developer! Go Web Examples covers the basics of web programming. From routers and templates to middleware and websockets. Here you can find clean code snippets up to detailed tutorials.

To get things started, check out the first example on how to create a classical "Hello World" web application or go straight to Routing (using the gorilla/mux router).

Hello World

This examples shows how to create an HTTP server using the net/http package from the standard library. It contains all functionalities about the HTTP protocol.

HTTP Server

This example shows how to use the `net/http` package to create a HTTP server with handlers and static files.

Routing (using gorilla/mux)

This example shows how to use the `gorilla/mux` package to create routes with named parameters, GET/POST handlers and domain restrictions.

MySQL Database

This example will show how to query MySQL databases using the sql package in the Go programming language.

Templates

This example shows how to use the `gorilla/mux` package to create routes with named parameters, GET/POST handlers and domain restrictions.

Assets and Files

This example will show how to serve static files like CSS or JS from a specific directory using the http.FileServer in the Go programming language.

Forms

This example will show how to simulate a contact form and parse the message into a struct using the Go programming language.

Middleware (Basic)

This example will show how to create basic logging middleware in the Go programming language.

Middleware (Advanced)

This example will show how to create a more advanced version of middleware in the Go programming language.

Sessions

This example will show how to store data in session cookies using the popular gorilla/sessions package in the Go programming language.

JSON

This example will show how to encode and decode JSON data using the encoding/json package in the Go programming language.

Websockets

This example will show how to work with websockets in Go. We will build a simple server which echoes back everything we send to it.

Password Hashing

This example will show how to hash passwords using bcrypt in the Go programming language.