gomon

command module
v0.9.1 Latest Latest
Warning

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

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

README

gomon build and test Codacy Badge Go Report Card codecov

how-does-it-work

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.

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:

# The port used for the browser syncing server
port = 3000
[build]
# 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 = ""
# What should we built from?
relative_source_dir = ""
# Where should the build be stored?
relative_build_dir = "tmp/build"
[filter]
# Watch these extensions for changes
include_exts = ["go", "tpl", "tmpl", "html", "css", "js", "env", "yaml"]
# Watch these directories for changes
include_relative_dirs = []
# Ignore these files
exclude_relative_files = []
# Ignore these directories
exclude_relative_dirs = ["assets", "tmp", "vendor", "node_modules", "build"]
[log]
# What should the Build log be named?
build_log_name = "gomon.log"
# Where should the Build log be stored?
relative_build_log_dir = "tmp"
# Should the Main log be enabled?
main = true
# Should the Detection log be enabled?
detection = false
# Should the Build log be enabled?
build = true
# Should the Run log be enabled?
run = false
# Should the Sync log be enabled?
sync = false
# Should the App log be enabled?
app = true
# Should a timestamp be appended to the log?
time = true
[color]
# The Main log color
main = "red"
# The Detection log color
detection = "magenta"
# The Build log color
build = "yellow"
# The Run log color
run = "green"
# The Sync log color
sync = "cyan"
# The App log color
app = "blue"

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