Gomon

command module
v0.0.0-...-941ac12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2021 License: MIT Imports: 8 Imported by: 0

README

Why is it necessary?

Because it also refreshes the browser upon change.

How does it work?

Plain: Watches for code changes, reloads the specified binary e.g. a webserver and calls the client through a websocket to reload.

how-does-it-work

Usage

setup the client

Include the script below to your client e.g. a static main.js & change YOUR_PORT with a free port of your choice. The default port is 3000.

function tryConnectToReload(address) {
  var conn;
  // This is a statically defined port on which the app is hosting the reload service.
  conn = new WebSocket("ws://localhost:3000/sync");

  conn.onclose = function(evt) {
    // The reload endpoint hasn't been started yet, we are retrying in 2 seconds.
    setTimeout(() => tryConnectToReload(), 2000);
  };

  conn.onmessage = function(evt) {
    console.log("Refresh received!");

    // the page will refresh every time a message is received.
    location.reload()
  }; 
}

try {
  if (window["WebSocket"]) {
    tryConnectToReload();
  } else {
    console.log("Your browser does not support WebSocket, cannot connect to the reload service.");
  }
} catch (ex) {
  console.log('Exception during connecting to reload:', ex);
}

install Gomon

go get -u github.com/AlexanderBrese/Gomon

run Gomon

If you want to configure the reload behavior or set change paths then just provide a configuration to the process.

Gomon [-c PATH_TO_YOUR_CONFIG]

configure Gomon

Default configuration:

# What should the build be named?
build_name = "main"
# How should the build be done?
build_command = "go build -o"
# How should the build be run?
execution_command = "./tmp/build/main"
# What should the log be named?
log_name = "Gomon.log"
# What should we built from?
relative_source_dir = ""
# Where should the build be stored?
relative_build_dir = "tmp/build"
# Where should the log be stored?
relative_log_dir = "tmp/Gomon.log"
# The port used for the browser syncing server
port = 3000
# Watch these extensions for changes
watch_relative_ext = ["go", "tpl", "tmpl", "html", "css", "js", "env", "yaml"]
# Watch these directories for changes
watch_relative_dir = []
# Ignore these files
ignore_relative_files = []
# Ignore these directories
ignore_relative_dir = ["assets", "tmp", "vendor", "node_modules", "build"]

What features is it going to provide?

The goals for version 1.0.0 are:

  • Linux/MacOS Support (currently windows only)
  • Colorful log messages
  • Customize binary execution with environmental flags

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL