Note this is just example code. It probably has some bad practices and mistakes.
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.
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.
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.
The Http server maps requests to the handlers Package. All of the exported functions from the handlers package are meant process HTTP requests.
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.
The static folder is used to host standard static assets for a web application:
The http server is configured to look in that directory when it starts.
I store all of the html/templates in this folder. The function
sendResponse looks in this folder when processing a request for a
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