Skip to content

How the CLI works

Vic Shóstak edited this page May 1, 2021 · 27 revisions

Probably you think that Create Go App CLI is a "black box" that magically creates objects out of thin air. But that's not really true. The whole project is built on UNIX principles that each element must have a clear function that it does well.

So, basically the CLI contains three main parts, which we will describe in more detail below:

  • Pre-configured backend part
  • Frontend part generated by Vite.js
  • Deploy-ready Ansible roles

The backend part

The backend part is full-fledged prepared templates with popular Go web frameworks, which were created by the authors of Create Go App and placed in the project organization on GitHub.

In the background, the usual git clone <URL> will happen, but followed by a cleanup of unnecessary folders so that you can start implementing your logic right away. You get right out of the box: CRUD methods with implementation examples, JWT authorization and token update, database configuration, autogenerated documentation for REST API from Swagger, clear and simple project structure.

You can choose between:

Name Version Link to Go template
Fiber v2.8.0 create-go-app/fiber-go-template
net/http v1.16.3 create-go-app/net_http-go-template

The frontend part

Frontend part will be generate using awesome tool Vite.js under the hood.

Note that the CLI does not do any transformations with this part of your project. That is, you have to write the frontend yourself from scratch, Create Go App only helps in organizing the structure and simplifies project generation.

This will use the usual Node.js command npm init @vitejs/app <FOLDER> -- --template <TEMPLATE>.

Make sure that you have Node.js version 12.x or higher installed on your computer.

You can choose between:

Name Version Link to JavaScript template Link to TypeScript template
Pure (vanilla) - vanilla vanilla-ts
React v17.0.0 react react-ts
Preact v10.5.13 preact preact-ts
Vue.js v3.0.5 vue vue-ts
Svelte v3.37.0 svelte svelte-ts
Lit v2.4.0 lit-element lit-element-ts

Deploy-ready Ansible roles

The most interesting part, which contains several atomic Ansible roles, inventory and playbook for successful deployment your project to a remote server. All the necessary role files are stored in the binary itself and are copied in an instant, which is why the CLI is so fast! Roles were created by the authors of Create Go App and verified by numerous test and production runs on real servers.

The CLI currently includes roles for:

  • Initial configuration of the remote server;
  • Docker settings to create containers;
  • Proxy server settings (Traefik Proxy, Nginx);
  • Settings for creating a container with the backend part;

As with the frontend, make sure you have Ansible version 2.9 or higher and Python 3.8 or higher installed to work successfully.

After filling out the inventory in the hosts.ini file and running the cgapp deploy command from the project root folder, the roles are analyzed and Ansible is called to do the rest of the work. Be patient, because this process can take anywhere from 30 seconds, depending on the performance of your remote server.

Clone this wiki locally