How to Use Go E xtensible Monitoring (Goemon)

Mar 25, 2024 | Programming

Are you ready to supercharge your development workflow with Goemon? In this guide, we’ll explore how you can seamlessly monitor your Go applications while taking advantage of features such as automatic page reloading and app recompilation when files are updated. Let’s dive in!

Expected Directory Structure

To get started, make sure your project follows this directory structure:

  • assets
  • index.html
  • app.css
  • app.js
  • main.go

Usage

Goemon provides various command-line options to help you set up live monitoring based on the file types you are working with. Here’s how to run the web server:

$ goemon -g goemon.yml
$ goemon go run main.go

Writing Markdown

If you are working with Markdown files, you can use this command:

$ goemon -g md goemon.yml
$ goemon --

Writing C Code

Similar to Markdown, if you need to work on C code, run:

$ goemon -g c goemon.yml
$ goemon --

Default Configuration Example

Here’s the structure of the default configuration file generated by Goemon:

livereload: :35730
tasks:
  - match: .assets*.js
    commands:
      - minifyjs -m -i $GOEMON_TARGET_FILE $GOEMON_TARGET_DIR$GOEMON_TARGET_NAME.min.js
  - :livereload
  - match: .assets*.css
    commands:
      - :livereload
  - match: .assets*.html
    commands:
      - :livereload
  - match: *.go
    commands:
      - go build
      - :restart
      - :livereload

Understanding the Configuration

Think of Goemon’s configuration as a recipe for your favorite dish. Each line is like an ingredient, specifying how the application should react to different file changes:

  • .assets*.css: Reload the page.
  • .assets*.js: Minify JS/CSS, then reload the page.
  • .assets*.html: Reload the page.
  • *.go: Build the Go app, restart it, and reload the page.

This recipe ensures that any changes made to JavaScript, CSS, HTML, or Go files will lead to the app being updated in real-time, like cooking with fresh ingredients rather than stale ones.

LiveReload Feature

To utilize LiveReload in your HTML files, make sure to include the following script in your index.html file:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <script src="http://localhost:35730/livereload.js"></script>
    <script src="app.css"></script>
    <script src="app.min.js"></script>
    <title>Your App</title>
</head>
<body>
    
</body>
</html>

Using Goemon as a Library

If you wish to use Goemon as part of your code rather than through command-line, start with the following basic structure:

package main

import ( 
  _ "github.com/mattn/goemon/auto"
)

func main() {
  // Your code here
}

Installation

Installing Goemon is easy! Just run the following command in your terminal:

$ go get github.com/mattn/goemon/cmd/goemon

If you want to minify your JavaScript, be sure to install minifyjs:

$ npm install -g minifyjs

Troubleshooting Tips

If you encounter any issues while using Goemon, here are a few troubleshooting steps you can take:

  • Ensure all file paths in your configuration are correct.
  • Double-check if the LiveReload server is running and accessible at the specified port.
  • Make sure to install any required dependencies, such as minifyjs.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox