Go to file
2021-12-27 17:36:18 -05:00
config Added HTTPS support. 2021-12-20 12:33:14 -05:00
context Moved pager to the controller package. Added additional documentation. 2021-12-18 16:55:35 -05:00
controller Moved navigation to the left-side panel. 2021-12-27 10:09:46 -05:00
ent Moved navigation to the left-side panel. 2021-12-27 10:09:46 -05:00
funcmap Added tests for funcmap. 2021-12-19 16:08:09 -05:00
htmx Added tests or htmx package. 2021-12-24 09:03:10 -05:00
middleware Use nil error response for testing middleware execution. 2021-12-22 14:38:00 -05:00
msg Removed unneeded dependency. 2021-12-25 21:04:19 -05:00
routes Added search example. 2021-12-27 12:54:27 -05:00
services Force user email to lower case. Include action on all forms. 2021-12-25 21:30:22 -05:00
static Added HTMX paging example. 2021-12-24 17:58:53 -05:00
templates Added search example. 2021-12-27 12:54:27 -05:00
tests Removed unneeded dependency. 2021-12-25 21:04:19 -05:00
.gitignore Initial commit. 2021-12-03 06:11:01 -05:00
docker-compose.yml Added database config and docker image. 2021-12-10 08:49:15 -05:00
go.mod Removed unneeded dependency. 2021-12-25 21:04:19 -05:00
go.sum Force user email to lower case. Include action on all forms. 2021-12-25 21:30:22 -05:00
main.go Added HTTPS support. 2021-12-20 12:33:14 -05:00
Makefile Started on the README. 2021-12-27 17:36:18 -05:00
README.md Started on the README. 2021-12-27 17:36:18 -05:00

(NAME) - Rapid, easy full-stack web development starter kit in Go


Table of Contents

Introduction

Overview

(NAME) is not a framework but rather a base starter-kit for rapid, easy full-stack web development in Go, aiming to provide much of the functionality you would expect from a complete web framework as well as establishing patterns, procedures and structure for your web application.

todo

Motivation

It started with this post on Hacker News, asking the community what the simplest stack to build web apps in 2021 is. After leaving PHP for Go over a year ago, I didn't have an answer for what I would use if I were to start building a web app tomorrow. If I was still using PHP, Laravel would most likely be the easy answer, but there's nothing quite like that available for Go, especially in terms of adoption and maturity. For good reasons, the community also seems mostly opposed to mega-frameworks.

todo

Foundation

While many great projects were used to build this, all of which are listed in the credits section, the following provide the foundation of the back and frontend. It's important to note that you are not required to use any of these. Swapping any of them out will be relatively easy.

Backend

  • Echo: High performance, extensible, minimalist Go web framework.
  • Ent: Simple, yet powerful ORM for modeling and querying data.

Frontend

Go server-side rendered HTML combined with the projects below enable you to create slick, modern UIs without writing any JavaScript or CSS.

  • HTMX: Access AJAX, CSS Transitions, WebSockets and Server Sent Events directly in HTML, using attributes, so you can build modern user interfaces with the simplicity and power of hypertext.
  • Alpine.js: Rugged, minimal tool for composing behavior directly in your markup. Think of it like jQuery for the modern web. Plop in a script tag and get going.
  • Bulma: Provides ready-to-use frontend components that you can easily combine to build responsive web interfaces. No JavaScript dependencies.

Storage

  • PostgreSQL: The world's most advanced open source relational database.
  • Redis: In-memory data structure store, used as a database, cache, and message broker.

Screenshots

todo

Getting started

Dependencies

Ensure the following are installed on your system:

Start the application

After checking out the repository, from within the root, start the Docker containers for the database and cache by executing make up.

Once that completes, you can start the application by executing make run. By default, you should be able to access the application in your browser at localhost:8000.

If you ever want to quickly drop the Docker containers and restart them in order to wipe all data, execute make reset.

Running tests

To run all tests in the application, execute make test. This ensures that the tests from each package are not run in parallel. This is required since many packages contain tests that connect to the test database which is dropped and recreated automatically for each package.

Clients

The following make commands are available to make it easy to connect to the database and cache.

  • make db: Connects to the primary database
  • make db-test: Connects to the test database
  • make cache: Connects to the cache

Service container

todo

Dependency injection

todo

Test dependencies

todo

Configuration

The config package provides a flexible, extensible way to store all configuration for the application. Configuration is added to the Container as a Service, making it accessible across most of the application.

Be sure to review and adjust all of the default configuration values provided.

Environment overrides

Leveraging the functionality of envdecode, all configuration values can be overridden by environment variables. Here is an example of what a configuration value looks like, each of which is a field on a struct:

Port         uint16        `env:"HTTP_PORT,default=8000"`

The value for this field will be set to 8000, the default, unless the HTTP_PORT environment variable is set, in which case the value of the variable will be used. This allows you to easily override configuration values per-environment.

Environments

The configuration value for the current environment (Config.App.Environment) is an important one as it can influence some behavior significantly (will be explained in later sections).

A helper function (config.SwitchEnvironment) is available to make switching the environment easy, but this must be executed prior to loading the configuration. The common use-case for this is to switch the environment to Test before tests are executed:

func TestMain(m *testing.M) {
	// Set the environment to test
	config.SwitchEnvironment(config.EnvTest)

	// Start a new container
	c = services.NewContainer()
	defer func() {
		if err := c.Shutdown(); err != nil {
			c.Web.Logger.Fatal(err)
		}
	}()

	// Run tests
	exitVal := m.Run()
	os.Exit(exitVal)
}