/goreact

Example Go (backend) React (frontend) Application

Primary LanguageGo

Go/React Web app

Overview

This is a web application that can be used to receive data over REST interface, store in a db, and then display it.

Technologies

  • Go (backend)
    • https://golang.org/
    • used on the server (backend)
    • greatly simplifies development and deployment
    • very popular in new companies and startups
    • cross platform -- can easily target Linux, MacOS, or Windows.
    • relatively "safe" language
      • statically typed so compiler catches a lot of problems
      • garbage collected (memory leaks are very rare)
    • Go is efficient and well suited for embedded Linux targets
      • compiles to a single, statically linked binary that is relatively small
      • compiled and runs similar to C/C++
  • React (frontend)
  • Bootstrap 4 (css toolkit)
  • https://parceljs.org/ (frontend build)
    • very powerful and simple frontend build tool
    • development and production modes
    • in development, automatically updates page in browser if sources change.

Additional Note:

  • all assets and files (including the frontend) are embedded in the golang server binary. This makes deployment of new versions very simple for development or production -- all you need is a single binary.
  • There is no separate run-time to install (like Python, Ruby, Nodejs, Java, or C# environments). Everything is statically included in the binary. Again, this makes deployment very simple.
  • there are no dependencies or stack that needs to be installed on the server -- only a single binary.

Setup

To set up a build environment (only tested under Linux):

Production Build

  • app_build (build Linux production binaries)
  • app_build_windows (build windows binaries)
  • ./goreact

Development

Install the following:

The following commands can be run (in separate terminal windows) during development. Any time one of the source files in the project are changed, then appropriate parts of the project are rebuilt, and automatically reloaded (if frontend change).

  • app_watch_backend
  • app_watch_frontend

Editors/Tooling

There are a number of editors that support Golang and React development very well including Vim, Atom, Visual Studio Code, etc. If you don't have a strong preference, Visual Studio Code is a good one to start with.

Visual Studio

Visual Studio Code is an advanced editor that runs well under Linux, and has extensions for both Go and Elm development. It also integrates well with Git and allows you to commit/push changes to a git repo directly from the editor.

To install:

Visual Studio is configured to auto-format Go and Javascript code automatically when saved.
This helps keep code clean looking and consistent.

VS Code also has an integrated terminal that will allow you to run the app_build from within your editor.