Skip to content

Instantly share code, notes, and snippets.

@ChunkRadius
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save ChunkRadius/e62bdb4059da99d64263 to your computer and use it in GitHub Desktop.

Select an option

Save ChunkRadius/e62bdb4059da99d64263 to your computer and use it in GitHub Desktop.
A sample Gulpfile for use with any Go HTTP server to automatically recompile the Go binary when any file changes.Adjust the projectName and srcDir to match your project's layout. Tested on Linux (Ubuntu) but should work wherever "sh" is available.
var projectName = 'main',
srcDir = './src',
gulp = require('gulp'),
exec = require('gulp-exec');
gulp.task('serve', function() {
var opts = { continueOnError: true, pipeStdout: true },
goCmd = 'sh -c "go run ' + __dirname + '/src/*.go&"',
killCmd = 'killall -q go ' + projectName;
gulp.src(srcDir + '/**/*.go')
.pipe(exec(killCmd, opts))
.pipe(exec(goCmd, opts));
});
gulp.task('watch', function() {
gulp.watch('./**/*.go', ['serve']);
});
gulp.task('default', ['serve', 'watch']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment