All Projects → josephspurrier → Gowebapp

josephspurrier / Gowebapp

Licence: mit
Basic MVC Web Application in Go

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Gowebapp

Web Monitoring
前端监控,性能监控平台。The front end monitoring platform focuses on Web end experience data monitoring. Three aspects of the health of Web pages are monitored: page opening speed (speed measurement), page stability (JS Error), and external service call success rate (API).
Stars: ✭ 592 (-38.59%)
Mutual labels:  web-application
Atscan
Advanced dork Search & Mass Exploit Scanner
Stars: ✭ 817 (-15.25%)
Mutual labels:  web-application
Go Boilerplate
golang or go boilerplate code to get you stated within minutes , make full fledged applications and websites using this setup.
Stars: ✭ 13 (-98.65%)
Mutual labels:  web-application
Mango
Mango is a self-hosted manga server and web reader
Stars: ✭ 610 (-36.72%)
Mutual labels:  web-application
Jspaint
🎨 Classic MS Paint, REVIVED + ✨Extras
Stars: ✭ 5,972 (+519.5%)
Mutual labels:  web-application
Vue Pokedex
A Pokédex made with Vue.js 📕
Stars: ✭ 22 (-97.72%)
Mutual labels:  web-application
Payloadsallthethings
A list of useful payloads and bypass for Web Application Security and Pentest/CTF
Stars: ✭ 32,909 (+3313.8%)
Mutual labels:  web-application
Map Tools Template
Configurable application template that enables you to display an ArcGIS web map using a variety of tools.
Stars: ✭ 21 (-97.82%)
Mutual labels:  web-application
Crm Application
OroCRM - an open-source Customer Relationship Management application.
Stars: ✭ 785 (-18.57%)
Mutual labels:  web-application
Litecloud
User management system for the server (Home Cloud).
Stars: ✭ 26 (-97.3%)
Mutual labels:  web-application
Consulo
Platform repository of Consulo. Plugins implementation hold in their repositories
Stars: ✭ 632 (-34.44%)
Mutual labels:  web-application
Hanami
The web, with simplicity.
Stars: ✭ 5,584 (+479.25%)
Mutual labels:  web-application
Diamond
System V-style runlevels for your Go daemons
Stars: ✭ 24 (-97.51%)
Mutual labels:  web-application
Budget
Get a grip on your finances.
Stars: ✭ 609 (-36.83%)
Mutual labels:  web-application
Jodel Web
[PHP] JodelBlue is a Web-App and Browser-Client for the Jodel App. No registration required! Browse Jodels all over the world.
Stars: ✭ 15 (-98.44%)
Mutual labels:  web-application
Easy hack
Hack the World using Termux
Stars: ✭ 549 (-43.05%)
Mutual labels:  web-application
Drab
Remote controlled frontend framework for Phoenix.
Stars: ✭ 833 (-13.59%)
Mutual labels:  web-application
Alumna
[Alpha release of v3] Development platform for humans / Plataforma de desenvolvimento para humanos
Stars: ✭ 32 (-96.68%)
Mutual labels:  web-application
Ulib
C++ application development framework, to help developers create and deploy applications quickly and simply
Stars: ✭ 912 (-5.39%)
Mutual labels:  web-application
Mylearningspace
Implementing my knowledge on Selenium WebDriver, Java and TestNG
Stars: ✭ 26 (-97.3%)
Mutual labels:  web-application

GoWebApp

Go Report Card GoDoc

Basic MVC Web Application in Go

I recommend you use Blue Jay which is the latest version of this project: https://github.com/blue-jay/blueprint.

2021-02-17: There is also a branch using Go modules available here: https://github.com/josephspurrier/gowebapp/tree/modules.

This project demonstrates how to structure and build a website using the Go language without a framework. There is a blog article you can read at http://www.josephspurrier.com/go-web-app-example/. There is a full application I built with an earlier version of the project at https://github.com/verifiedninja/webapp. There is an API version of this project at https://github.com/josephspurrier/gowebapi.

To download, run the following command:

go get github.com/josephspurrier/gowebapp

If you are on Go 1.5, you need to set GOVENDOREXPERIMENT to 1. If you are on Go 1.4 or earlier, the code will not work because it uses the vendor folder.

Quick Start with Bolt

The gowebapp.db file will be created once you start the application.

Build and run from the root directory. Open your web browser to: http://localhost. You should see the welcome page.

Navigate to the login page, and then to the register page. Create a new user and you should be able to login. That's it.

Quick Start with MongoDB

Start MongoDB.

Open config/config.json and edit the Database section so the connection information matches your MongoDB instance. Also, change Type from Bolt to MongoDB.

Build and run from the root directory. Open your web browser to: http://localhost. You should see the welcome page.

Navigate to the login page, and then to the register page. Create a new user and you should be able to login. That's it.

Quick Start with MySQL

Start MySQL and import config/mysql.sql to create the database and tables.

Open config/config.json and edit the Database section so the connection information matches your MySQL instance. Also, change Type from Bolt to MySQL.

Build and run from the root directory. Open your web browser to: http://localhost. You should see the welcome page.

Navigate to the login page, and then to the register page. Create a new user and you should be able to login. That's it.

Overview

The web app has a public home page, authenticated home page, login page, register page, about page, and a simple notepad to demonstrate the CRUD operations.

The entrypoint for the web app is gowebapp.go. The file loads the application settings, starts the session, connects to the database, sets up the templates, loads the routes, attaches the middleware, and starts the web server.

The front end is built using Bootstrap with a few small changes to fonts and spacing. The flash messages are customized so they show up at the bottom right of the screen.

All of the error and warning messages should be either displayed either to the user or in the console. Informational messages are displayed to the user via flash messages that disappear after 4 seconds. The flash messages are controlled by JavaScript in the static folder.

Structure

Recently, the folder structure changed. After looking at all the forks and reusing my project in different places, I decided to move the Go code to the app folder inside the vendor folder so the github path is not littered throughout the many imports. I did not want to use relative paths so the vendor folder seemed like the best option.

The project is organized into the following folders:

config		- application settings and database schema
static		- location of statically served files like CSS and JS
template	- HTML templates

vendor/app/controller	- page logic organized by HTTP methods (GET, POST)
vendor/app/shared		- packages for templates, MySQL, cryptography, sessions, and json
vendor/app/model		- database queries
vendor/app/route		- route information and middleware

There are a few external packages:

github.com/gorilla/context				- registry for global request variables
github.com/gorilla/sessions				- cookie and filesystem sessions
github.com/go-sql-driver/mysql 			- MySQL driver
github.com/haisum/recaptcha				- Google reCAPTCHA support
github.com/jmoiron/sqlx 				- MySQL general purpose extensions
github.com/josephspurrier/csrfbanana 	- CSRF protection for gorilla sessions
github.com/julienschmidt/httprouter 	- high performance HTTP request router
github.com/justinas/alice				- middleware chaining
github.com/mattn/go-sqlite3				- SQLite driver
golang.org/x/crypto/bcrypt 				- password hashing algorithm

The templates are organized into folders under the template folder:

about/about.tmpl       - quick info about the app
index/anon.tmpl	       - public home page
index/auth.tmpl	       - home page once you login
login/login.tmpl	   - login page
notepad/create.tmpl    - create note
notepad/read.tmpl      - read a note
notepad/update.tmpl    - update a note
partial/footer.tmpl	   - footer
partial/menu.tmpl	   - menu at the top of all the pages
register/register.tmpl - register page
base.tmpl		       - base template for all the pages

Templates

There are a few template funcs that are available to make working with the templates and static files easier:

<!-- CSS files with timestamps -->
{{CSS "static/css/normalize3.0.0.min.css"}}
parses to
<link rel="stylesheet" type="text/css" href="/static/css/normalize3.0.0.min.css?1435528339" />

<!-- JS files with timestamps -->
{{JS "static/js/jquery1.11.0.min.js"}}
parses to
<script type="text/javascript" src="/static/js/jquery1.11.0.min.js?1435528404"></script>

<!-- Hyperlinks -->
{{LINK "register" "Create a new account."}}
parses to
<a href="/register">Create a new account.</a>

<!-- Output an unescaped variable (not a safe idea, but I find it useful when troubleshooting) -->
{{.SomeVariable | NOESCAPE}}

<!-- Time format -->
{{.SomeTime | PRETTYTIME}}
parses to format
3:04 PM 01/02/2006

There are a few variables you can use in templates as well:

<!-- Use AuthLevel=auth to determine if a user is logged in (if session.Values["id"] != nil) -->
{{if eq .AuthLevel "auth"}}
You are logged in.
{{else}}
You are not logged in.
{{end}}

<!-- Use BaseURI to print the base URL of the web app -->
<li><a href="{{.BaseURI}}about">About</a></li>

<!-- Use token to output the CSRF token in a form -->
<input type="hidden" name="token" value="{{.token}}">

It's also easy to add template-specific code before the closing and

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].