🎉 The Create Go App project has grown to v2, but is still easier, better, faster & stronger
Tags: go, news, beginners, showdev
Published: 2021-05-06 14:55:16

## Introduction

Hello, friends! 😉 I'm excited to share great news with you: the [Create Go App CLI](https://github.com/create-go-app/cli) project, _that I've been working on for a long time_, has finally been updated to major version `2`.

In case anyone forgot, I remind you that with this CLI you can create in just a few seconds a new production-ready project with **backend** (Go), **frontend** (JavaScript, TypeScript) and **deploy automation** (Ansible, Docker).

> ☝️ You only need to focus on writing code and thinking of business-logic! The CLI will take care of the rest.

OK. Let's look at the changes together! Fasten your seat belts, we're starting.

<a name="toc"></a>
### 📝 Table of contents

- [New in v2 and beyond](#new-in-v2-and-beyond)
- [Changes in CLI commands](#changes-in-cli-commands)
- [Ansible roles](#ansible-roles)
  - [Web, proxy servers](#web-proxy-servers)
  - [Database](#database)
  - [Cache, key-value storage](#cache-key-value-storage)
- [Project Wiki page](#project-wiki-page)
- [Your assistance to the project](#your-assistance-to-the-project)

<a name="#new-in-v2-and-beyond"></a>
## New in v2 and beyond

There are actually quite a few changes, but I've highlighted a few of the **most important** ones that change the way you work with the Create Go App CLI. For all other changes, please read the release notes in our GitHub repository:

{% github create-go-app/cli no-readme %}

[↑ Table of contents](#toc)

<a name="#changes-in-cli-commands"></a>
## Changes in CLI commands

This release was aimed primarily at speeding up the CLI and reducing the functionality of commands that were too overloaded.

[↑ Table of contents](#toc)

### `init` command

After some analysis of the CLI command feedback, we concluded that the command to create a configuration file is very rarely used. The same comment from the focus group of our users, followed about the configuration file itself.

The most popular comment we got, was something like this: 

— [...] _nobody likes setting up yet another config for yet another CLI!_

So, it was decided to remove `init` command and file-based config `.cgapp.yml` completely, even **without** the possibility of backward compatibility, which we successfully did in `v2.0.0`.

[↑ Table of contents](#toc)

### `create` command

The central CLI command has been redesigned, and its execution time has been **reduced to 2-4 seconds**. This was achieved by switching to generating the frontend part of the project using ready-made templates from the awesome next generation frontend tooling called [Vite.js](https://vitejs.dev/).

![vite js](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zi3suks2f304z2oh389u.png)

Now, you can choose between this frontend frameworks/libraries: 

| Name           | Version | JavaScript template | TypeScript template |
| -------------- | ------- | --------------------------- | --------------------------- |
| Pure (vanilla) | - | [`vanilla`](https://github.com/vitejs/vite/tree/main/packages/create-app/template-vanilla)         | [`vanilla-ts`](https://github.com/vitejs/vite/tree/main/packages/create-app/template-vanilla)            |
| React          | `v17.0.0` | [`react`](https://github.com/vitejs/vite/tree/main/packages/create-app/template-react)             | [`react-ts`](https://github.com/vitejs/vite/tree/main/packages/create-app/template-react-ts)             |
| Preact         | `v10.5.13` | [`preact`](https://github.com/vitejs/vite/tree/main/packages/create-app/template-preact)           | [`preact-ts`](https://github.com/vitejs/vite/tree/main/packages/create-app/template-preact-ts)           |
| Vue.js         | `v3.0.5` | [`vue`](https://github.com/vitejs/vite/tree/main/packages/create-app/template-vue)                 | [`vue-ts`](https://github.com/vitejs/vite/tree/main/packages/create-app/template-vue-ts)                 |
| Svelte         | `v3.37.0` | [`svelte`](https://github.com/vitejs/vite/tree/main/packages/create-app/template-svelte)           | [`svelte-ts`](https://github.com/vitejs/vite/tree/main/packages/create-app/template-svelte-ts)           |
| Lit            | `v2.4.0` | [`lit-element`](https://github.com/vitejs/vite/tree/main/packages/create-app/template-lit-element) | [`lit-element-ts`](https://github.com/vitejs/vite/tree/main/packages/create-app/template-lit-element-ts) |

> ⚠️ Please note! Creating a new project is done only through the console interface (or CUI for short).

Create a new project from the custom backend and frontend templates (_from your git repositories_) is done by using `-t` option with `create` command:

| Option | Description                                              | Type   | Default | Required? |
| ------ | -------------------------------------------------------- | ------ | ------- | --------- |
| `-t`   | Enables to define custom backend and frontend templates. | `bool` | `false` | No        |

The structure of the created project will be as follows:

```bash
.
├── .editorconfig
├── .gitattributes
├── .gitignore
├── hosts.ini     # <-- file with Ansible inventory variables
├── playbook.yml  # <-- file with Ansible playbook
├── Makefile
├── backend       # <-- folder with Go backend
│   └── ...
├── frontend      # <-- folder with JS/TS frontend (if you choose)
│   └── ...
└── roles         # <-- folder with Ansible roles
    ├── backend
    │   └── ...
    ├── docker
    │   └── ...
    ├── postgres
    │   └── ...
    ├── redis
    │   └── ...
    └── traefik   # or nginx (if you choose)
        └── ...
```

Watch a short video presentation: 

<a href="https://recordit.co/OQAwkZBrjN" target="_blank"><img src="https://user-images.githubusercontent.com/11155743/116787503-0d0dbb80-aaad-11eb-9ef1-dce2df6f606c.jpg" alt="cgapp create"/></a>

Direct link: https://recordit.co/OQAwkZBrjN

[↑ Table of contents](#toc)

### `deploy` command

Also, we have seriously reworked the principle of deploying the project on a remote server. The only option left for the `deploy` command is the default password call for the sudo user:

| Option | Description                                                                                            | Type      | Default | Required? |
| ------ | ------------------------------------------------------------------------------------------------------ | --------- | ------- | --------- |
| `-k`   | Prompt you to provide the remote user sudo password (_a standard Ansible `--ask-become-pass` option_). | `bool` | `false` | No        |

Now, everything is built on pre-configured Ansible roles that work perfectly out of the box with our official backend templates for [Fiber](https://github.com/create-go-app/fiber-go-template) and [net/http](https://github.com/create-go-app/net_http-go-template).

Watch a short video presentation:

<a href="https://recordit.co/OQAwkZBrjN" target="_blank"><img src="https://user-images.githubusercontent.com/11155743/116787504-0e3ee880-aaad-11eb-8268-35493e5608c5.jpg" alt="cgapp deploy"/></a>

Direct link: https://recordit.co/ishTf0Au1x

[↑ Table of contents](#toc)

<a name="#ansible-roles"></a>
## Ansible roles

Starting with version `v2.0.0` we will actively add new Ansible roles to make the process of deploying your project to remote servers as comfortable and fast as possible. 

So, now all the configuration for deployment will be in the Ansible inventory `hosts.ini` (in the root of the created project). For example, this is what the inventory looks like for deploying a project with the **Nginx** web server:

```ini
# ./hosts.ini

# Ansible inventory for deploy the Create Go App project.
# Author: Vic Shóstak <vic@shostak.dev> (https://shostak.dev)
# For more information, please visit https://create-go.app/

[cgapp_project]
127.0.0.1 # CHANGE THIS TO YOUR REMOTE SERVER IP!

[cgapp_project:vars]
#
# Ansible default variables to start playbook:
#

# Set remote sudo username
ansible_user=root
# Ask become password for remote sudo user
ansible_become=yes
# Set connection type to remote server (usually, 'ssh')
ansible_connection=ssh
# Set Python 3 default path
ansible_python_interpreter=/usr/bin/python3

#
# Remote server configuration:
#

# Set directory on your remote server 
# for store project files
server_dir=/var/www/cgapp
# Set user (owner of files/folders) name
server_user=root
# Set group name
server_group=docker

#
# Project configuration:
#

# Set your project domain
project_domain=example.com

#
# Docker configuration:
#

# Set Docker network name
docker_network=cgapp_network

#
# Backend configuration:
#

# Set backend port number,
# MUST BE MATCH to the port that is listed 
# in your `./backend/.env` file!
backend_port=5000

#
# PostgreSQL configuration (backend DB):
#

# Set PostgreSQL version (for example, 13.2)
postgres_version=latest
# Set PostgreSQL port number,
# MUST BE MATCH to the port that is listed 
# in your `./backend/.env` file!
postgres_port=5432
# Set PostgreSQL user name,
# MUST BE MATCH to the user name that is listed 
# in your `./backend/.env` file!
postgres_user=postgres
# Set PostgreSQL password,
# MUST BE MATCH to the password that is listed 
# in your `./backend/.env` file!
postgres_password=password
# Set PostgreSQL DB name,
# MUST BE MATCH to the DB name that is listed 
# in your `./backend/.env` file!
postgres_db=postgres
# Set PostgreSQL SSL mode state ('enabled' or 'disabled'),
# MUST BE MATCH to the SSL mode state that is listed 
# in your `./backend/.env` file!
postgres_ssl_mode=disable

#
# Go-Migrate configuration:
#

# Set migration number,
# if you WANT to migrate all of your migrations, 
# just leave it blank,
# for only initial migration set it to '1'
migrate_number=1

#
# Redis configuration (backend cache):
#

# Set Redis version (for example, 6.2)
redis_version=latest
# Set Redis port number,
# MUST BE MATCH to the port that is listed 
# in your `./backend/.env` file!
redis_port=6379

#
# Nginx configuration:
#

# Set Nginx version (for example, 1.20-alpine)
nginx_version=alpine
# Set redirect from HTTP to HTTPS for default server
nginx_use_only_https=yes
# Set redirect from WWW to non-WWW domain for default server
nginx_redirect_to_non_www=yes
```

[↑ Table of contents](#toc)

<a name="#web-proxy-servers"></a>
### Web, proxy servers

We're recommending to use [Traefik Proxy](https://traefik.io/traefik/) as default proxy server for your projects. The main reason: this proxy provides **automatic** SSL certificates from Let's Encrypt with **renew** out of the box.

Also, Traefik was built on the Docker ecosystem and has a really useful Web UI:

![traefik web ui](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/48lxi7mt92k52cdjmbp3.png)

List of roles:

- `traefik` — configured Traefik container with a simple ACME challenge via CA server.
- `traefik-acme-dns` — configured Traefik container with a complex ACME challenge via DNS provider.
- `nginx` — pure Nginx container with "the best practice" configuration.

[↑ Table of contents](#toc)

<a name="#database"></a>
### Database

List of roles:

- `postgres` — configured [PostgreSQL](https://postgresql.org/) container with apply migrations (by [golang-migrate/migrate](https://github.com/golang-migrate/migrate) tool) for backend.

[↑ Table of contents](#toc)

<a name="#cache-key-value-storage"></a>
### Cache, key-value storage

List of roles:

- `redis` — configured [Redis](https://redis.io/) container to store the backend cache.

[↑ Table of contents](#toc)

<a name="#project-wiki-page"></a>
## Project Wiki page

Soon, we plan to move completely to the GitHub Wiki and do away with the separate documentation on our [website](https://create-go.app/) for the project. 

— _Everything should be in one place_, — as focus group users correctly noted.

This is a table of contents for the [Create Go App Wiki](https://github.com/create-go-app/cli/wiki):

- [How the CLI works](https://github.com/create-go-app/cli/wiki/How-the-CLI-works)
- CLI commands
  - [`cgapp create`](https://github.com/create-go-app/cli/wiki/Command-create)
  - [`cgapp deploy`](https://github.com/create-go-app/cli/wiki/Command-deploy)
- [Errors in the process](https://github.com/create-go-app/cli/wiki/Errors-in-the-process)
- [Frequently asked questions](https://github.com/create-go-app/cli/wiki/FAQ)
- [Logo](https://github.com/create-go-app/cli/wiki/Logo)

[↑ Table of contents](#toc)

<a name="#your-assistance-to-the-project"></a>
## Your assistance to the project

If you want to say **thank you** or/and support active development of project:

- Add a [GitHub Star](https://github.com/create-go-app/cli) to the project.
- Tweet about project [on your Twitter](https://twitter.com/intent/tweet?text=%E2%9C%A8%20Create%20a%20new%20production-ready%20project%20with%20%23Golang%20backend%2C%20%23JavaScript%20or%20%23TypeScript%20frontend%2C%20%23Docker%20and%20%23Ansible%20deploy%20automation%20by%20running%20one%20command.%20%0A%0AFocus%20on%20writing%20code%20and%20thinking%20of%20business-logic%21%0AThe%20CLI%20will%20take%20care%20of%20the%20rest.%0A%0Ahttps%3A%2F%2Fgithub.com%2Fcreate-go-app%2Fcli).
- Write interesting articles about project on [Dev.to](https://dev.to/), [Medium](https://medium.com/) or personal blog.
- Join DigitalOcean at our [referral link](https://m.do.co/c/b41859fa9b6e) (your profit is **$100** and we get $25).

Together, we can make this project **better** every day!

[↑ Table of contents](#toc)

<a name=""></a>
## Photos and videos by

- Vic Shóstak https://shostak.dev

<a name=""></a>
## P.S.

If you want more articles (like this) on this blog, then post a comment below and subscribe to me. Thanks! 😻

And of course, you can help me make developers' lives even better! Just connect to one of my projects as a contributor. It's easy!

My projects that need your help (and stars) 👇

- 🔥 [gowebly][gowebly_url]: A next-generation CLI tool for easily build amazing web applications with Go on the backend, using htmx & hyperscript and the most popular atomic/utility-first CSS frameworks on the frontend.
- ✨ [create-go-app][cgapp_url]: Create a new production-ready project with Go backend, frontend and deploy automation by running one CLI command.
- 🏃 [yatr][yatr_url]: Yet Another Task Runner allows you to organize and automate your routine operations that you normally do in Makefile (or else) for each project.
- 📚 [gosl][gosl_url]: The Go Snippet Library provides snippets collection for working with routine operations in your Go programs with a super user-friendly API and the most efficient performance.
- 🏄‍♂️ [csv2api][csv2api_url]: The parser reads the CSV file with the raw data, filters the records, identifies fields to be changed, and sends a request to update the data to the specified endpoint of your REST API.
- 🚴 [json2csv][json2csv_url]: The parser can read given folder with JSON files, filtering and qualifying input data with intent & stop words dictionaries and save results to CSV files by given chunk size.

<!-- Footer links -->

[gowebly_url]: https://github.com/gowebly
[cgapp_url]: https://github.com/create-go-app
[yatr_url]: https://github.com/koddr/yatr
[gosl_url]: https://github.com/koddr/gosl
[csv2api_url]: https://github.com/koddr/csv2api
[json2csv_url]: https://github.com/koddr/json2csv