Golang development tool that supports project bootstrap, live-reload (tests + application), and auto dependency retrieval based on Go Modules
MIT License
GoDev
GoDev is a live-reload development tool with first class support for Golang development.
Looking for the old Makefile version? You can find it here
You will require Go > 1.11.x for GoDev to work out of the box because of its usage of go mod
.
All releases will also include binaries for all three supported packages with source code so you can build it yourself. See the section on Compilation for details.
For all platforms, simply run the following to install GoDev:
go get github.com/zephinzer/godev
Installation via platform-specific package managers coming soon!
For all the commands below on usage, you may also view them through the help
subcommand:
godev help
Or to check your version for bug reports or functionalities:
godev version
Running godev
without flags is the easiest way to get started with live-reload-enabled development:
godev
GoDev runs
go mod vendor
to install dependencies,go build -o bin/app
to build your application, and lastly it runs your app throughbin/app
. You might have to runchmod +x bin/app
on the first build.
To run the tests, simply specify the test
sub-command.
godev test
To view verbose logs, append the --vv
flag.
godev test --vv
To initialise a directory for development in the Golang language with Go Modules for package management, use the init
sub-command.
godev init
If you'd like to preview files before you install them, you can use the
view
sub-command to check out the file first.
GoDev is also available as a Docker image at zephinzer/godev:latest
. To get started using the Docker image, run:
# create the cache directory because volume definitions
# will cause a directory to be created as `root` which
# you will have trouble deleting on the host
mkdir -p ./.cache/pkg;
# instantiate the docker image into a container
docker run -it \
-u $(id -u) \
-v "$(pwd):/go/src/app" \
-v "$(pwd)/.cache/pkg:/go/pkg" \
zephinzer/godev:latest \
godev ...
# ^ add any other flags you want after godev
While GoDev was written focused on Golang development happiness, it can also be used for projects in other languages. Use the configuration flags to adjust it to your needs.
godev
When run alone, GoDev defaults to running in development mode which means it will run the application in live-reload with automatic dependency retrievals based on your code.
By default, GoDev will run for live-reload in development. This results in the default execution groups of:
go mod vendor
go build -o ${BUILD_OUTPUT}
(see --output
)${BUILD_OUTPUT}
godev
FlagsFlag | Description |
---|---|
--args |
Specifies arguments to pass into commands of the final execution group (the application being live-reloaded) |
--dir |
Specifies the working directory |
--env |
Specifies an environment variable |
--exec |
Specifies comma-delimited commands |
--exec-delim |
Changes the delimiter for the -exec flag |
--exts |
Specifies extensions to watch |
--ignore |
Specifies file/directory names to ignore |
--output |
Specifies the path relative to the working directory where the binary will be put |
--rate |
Specifies the batching duration for file system events |
--silent |
Turns off logging |
--vv |
Turns on verbose logging |
--vvv |
Turns on very verbose logging |
--watch |
Specifies the directory to watch |
test
Tells GoDev to run in test mode. This changes the default execution groups so that the following are run instead:
go mod vendor
go build -o ${BUILD_OUTPUT}
(see --output
)go test ./... -coverprofile c.out
test
FlagsFlag | Description |
---|---|
--dir |
Specifies the working directory |
--env |
Specifies an environment variable |
--exts |
Specifies extensions to watch |
--ignore |
Specifies file/directory names to ignore |
--output |
Specifies the path relative to the working directory where the binary will be put |
--rate |
Specifies the batching duration for file system events |
--silent |
Turns off logging |
--vv |
Turns on verbose logging |
--vvv |
Turns on very verbose logging |
--watch |
Specifies the directory to watch |
init
Specifying this sub-command triggers a directory initialisation flow which asks if you would like to initialise some files/directories if they are not found. These are:
init
FlagsFlag | Description |
---|---|
--dir |
Specifies the working directory |
view
Specifying this flag with the name of a file prints the file to your terminal. For example, godev view main.go
will print the main.go
file which init
will seed for you if you say yes.
view
FlagsNone.
help
Displays the help page.
version
Displays the version of GoDev
version
FlagsFlag | Description |
---|---|
--commit |
Indiciates to only display the commit hash |
--semver |
Indiciates to only display the semver version |
--vv
Defines verbose logs (debug level). Useful for debugging or if you'd like some insights into what triggered your job and to debug the pipeline for your specified execution groups.
--vvv
Defines very verbose logs (trace level). More useful if you're developing GoDev itself to trace the flow of events.
--silent
Tells GoDev to keep completely quiet. Only panic level logs are printed before GoDev exits with a non-zero status code.
--args
Specifies the arguments to be passed into the last execution group which should contain the path to your binary.
Default: None
--dir
Specifies the directory for commands from GoDev to run from.
Default: Current working directory
--watch
Specifies the directory for GoDev to watch for changes recursively in.
Default: Current working directory
--env
Specifies an environment variable to be passed into commands.
Use multiple of these to specify multiple environment variables.
Usage: godev --env ENV=production --env HTTP_PROXY=http://localhost:1111
--exec
Specifies a single execution group. Commands specified in an execution group run in parallel.
Use multiple of these to define multiple execution groups. The execution groups run in sequence themselves.
--exec-delim
Specifies the delimiter used in the --exec
flag for separating commands. This flag finds its use if the command you wish to run contains a command as an argument.
Default: ,
--exts
Defines a comma separated list of extensions (without the dot) to trigger a file system change event.
Default: go,Makefile
--ignore
Defines names of files/directories to ignore.
Default: bin,vendor
--output
Defines the path to the built output
Default: bin/app
--rate
Defines the rate at which file system change events are batched. Modifying this would be useful if you find that commands being run in your execution groups take longer than 2 seconds and modify files resulting in a never-ending file system change trigger loop.
Default: 2s
Start a PR - Before starting on an issue, indicate you're working on it by submitting a PR (either from your own fork, or from a branch of this repository - doesn't matter) with documentation changes. Please also write about what changes you'll be making and analyses of dependencies you're adding (if any).
Pass the automated checks - There's a Travis pipeline check that is mandatory before merges will be allowed.
Squash and merge - This keeps the commit history clean
(For collaborators) - Versioning - On merging, if the PR is related to non-breaking functionality optimisations/additions, do nothing. If it adds something new, consider bumping the minor release if it might change some users' workflows. If it breaks something that people are using, bump the major version.
Run the following to clone this repository:
git clone [email protected]:zephinzer/godev.git;
Then copy the sample.properties
into Makefile.properties
:
cp sample.properties Makefile.properties;
Dependencies are stored in the ./vendor
directory. Run the following to populate the dependencies:
make deps
For static files that GoDev can initialise, a Go generator is used. The files can be found at ./data/generate
and the code to generate the file at ./data.go
can be found at ./data/generate.go
. The ./data.go
is generated with every build, but if you want to generate it manually, run:
make generate
Development is done in the ./dev
directory. Unfortunately, since this is a live-reload tool, there is no live-reload for the live-reload, so we have to re-run the application every time we make changes for them to be visible. The command to re-compile and re-run GoDev while working with ./dev
is:
make start
To run the tests in watch mode:
make test
For running the tests one-off (CI mode):
make test.ci
We try to follow semver versioning as far as possible. This means:
To get the current version:
make version.get
To bump the version:
# bump the patch version
make version.bump
# bump the minor version
make version.bump VERSION=minor
# bump the major version
make version.bump VERSION=major
To compile GoDev simply run make
:
make
# or if you'd like to be specific:
make godev
To build the GoDev image, run:
make docker
We use two tools for continuous integration: Travis (the CI pipeline runner), and CodeClimate (static code analysis).
The pipeline primarily does the following:
The following are variables that need to be defined for your pipeline:
CC_TEST_REPORTER_ID
: Code ClimateDOCKER_IMAGE_REGISTRY
: Hostname of the Docker registry we are pushing toDOCKER_IMAGE_NAMESPACE
: Namespace of the Docker image (docker.io/THIS/image:tag)DOCKER_IMAGE_NAME
: Name of the Docker image (docker.io/namespace/THIS:tagDOCKER_REGISTRY_USERNAME
: Username for the Docker registry (when not specified, does not release to DockerHub)DOCKER_REGISTRY_PASSWORD
: Password for the Docker registry (when not specified, does not release to DockerHub)GITHUB_OAUTH_TOKEN
: GitHub personal access token for deploying binaries to the release pageGITHUB_REPOSITORY_URL
: Clone URL of the GitHub repository (when not specified, does not release to GitHub)GITHUB_SSH_DEPLOY_KEY
: Base64 encoded private key that matches a public key listed in your Deploy Keys for the project. Run make ssh.keys
to generate this.You will also need to go to your GitHub repository's Settings > Deploy keys and add the public key generated from make ssh.keys
(the public key should be at ./bin/id_rsa.pub
, use the ./bin/id_rsa_b64
contents for the GITHUB_SSH_DEPLOY_KEY
variable).
This is a side-project of mine meant to support my own development needs. I have a day job, so unless I have an urgent need while using this in my professional work, most of my code-level work on this repository will be done during weekends. Pull requests are however supported throughout the week!(:
Thanks for understanding!
If you really like my work and would like to support me, you can find my Patreon at:
The binary and source code is licensed under the permissive MIT license. See the LICENSE file for the full text.
Leave me a π or watch this repository to indicate your interest in my sustained development on this. It'll help me decide whether or not I should deprecate this once my own use case for this is over.