No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
data
gateways
handlers
objects
static
templates
.gitignore
README.org
moviebrowser.go

README.org

Movie Browser

This is a basic example web application written using Golang. It should be fully functional. The only things needed to make it run would be the movie.db file and a SQLite implementation.

Note this is just example code. It probably has some bad practices and mistakes.

File Structure

The root level folder for this application contains moviebrowser.go. This file contains the main method and is the entry point for the server. That file starts the server and also specifies all of the routes for this application.

This application is basic enough that I didn’t need to define a custom ServeMux.

Data

The data package contains a very simple wrapper around the database connection. It’s nice to have a central way to open SQL connections. In a more complicated application, it might make sense to add more functionality to this package.

Gateways

The gateways are supposed to have packages that allow you to access a particular table. I probably deviated away from that pattern a little bit. Basically all of the SQL queries for the application are in the gateway package.

Handlers

The Http server maps requests to the handlers Package. All of the exported functions from the handlers package are meant process HTTP requests.

Objects

The objects folder contains all the structs that are passed around in this application. Because this is a basic application there are only two: movies and voters.

In a more complicated application, there are a lot of global structs so it’s nice to have they grouped together.

Static

The static folder is used to host standard static assets for a web application:

  • CSS
  • JS
  • Images

The http server is configured to look in that directory when it starts.

Templates

I store all of the html/templates in this folder. The function sendResponse looks in this folder when processing a request for a particular handler.

Front End Frameworks

Building and Running

In order to build the application and run it, I run the following two commands:

go build moviebrowser.go
./moviebrowser