Skip to content

ilourt/goflow

 
 

Repository files navigation

Go Flow

A base workflow for Golang projects, layout inspired by the Golang standards.

Docker + Golang + inspiration from standards.

Quick Start

Goflow must be installed from a clean repository (existing and nothing to validate).

Create a new one if needed:

git init
echo 'TODO' > ./README.md
git add .
git commit -m "Initial commit"

Get goflow directory, in an existing Git repository:

# get the goflow subtree
git remote add goflow git@github.com:Nicolab/goflow.git
git fetch goflow
git subtree add --prefix=goflow --squash goflow master

# create the Docker volume folder
mkdir ./goflow/build/dev/.go

Edit the config file: ./goflow/conf/dev/docker.sh (mainly: dev_container_name).

From now on you need the files of your project (go.mod, main.go).
If your project directory is empty, you can use the minimal Go Flow Project Layout as inspiration (or starter kit).

Then, always from your project directory:

./goflow/build/dev/build-image # create goflow-dev image
./goflow/scripts/dev/console # run the container and get a shell inside

Now, from the container:

./goflow/scripts/dev/install-container-stack
./goflow/scripts/dev/watch # or ./goflow/scripts/dev/watch-debug

It's installed!
Happy Coding in the Go flow ;)

Usage

Config

See the config files.

Host

Run/exec the goflow-dev container:

./goflow/scripts/dev/console

Stop and remove goflow-dev container:

./goflow/scripts/dev/rm-container

Container

Execute the Go program (go run by default):

./goflow/scripts/dev/exec

Run the Go program and watch the code change (for reloading):

./goflow/scripts/dev/watch

Same with Delve:

./goflow/scripts/dev/watch-debug

Now, you can connect your favorite code editor to the Delve server.

From the host you can also exec: dlv connect localhost:2345
or in one: dlv connect localhost:2345 & ./goflow/scripts/dev/console

How to Update

If you need to keep your Go Flow up to date with the recent changes made to Go Flow project, you can always fetch and merge them from this repo back into your own project:

git pull -s subtree goflow master --allow-unrelated-histories

--allow-unrelated-histories prevent that Git refusing to merge unrelated histories.

Update the remote tracking

If you want to add or to update a remote branch to track:

git remote add -t master goflow git@github:Nicolab/goflow.git

git remote add -t remote-branch remote-name remote-url
You can use multiple "-t branch" options to grab multiple branches.

How to uninstall

Remove the goflow directory:

rm -rf goflow

Remove the remote URL:

git remote rm goflow

Verify it's gone: git remote -v
Note: git remote rm does not delete the remote repository from the server. It simply removes the remote and its references from your local repository.

Tips

.bashrc

To customize the .bashrc file, you can mount the .bashrc file in volume via ./goflow/conf/dev/docker.sh file.

Example:

-v "${PWD}"/goflow/build/dev/files/.bashrc:/home/gopher/.bashrc \

You can mount as many files and folders as you want. It's a simple Docker command that you can customize at will!

Troubleshooting

Max user files watches

If you reach the default limit of your OS, you should increase the amount of inotify watchers.

If you are running Debian, RedHat, or another similar Linux distribution, run the following in a terminal that set a new limit temporary:

sudo sysctl fs.inotify.max_user_watches=524288 \
&& sudo sysctl -p \
&& cat /proc/sys/fs/inotify/max_user_watches

TODO

  • Handle locales in build/dev/Dockerfile.
  • Improve the concept (symplify the install, usage and add more docs).

LICENSE

MIT (c) 2018, Nicolas Tallefourtane.

Author

Nicolas Tallefourtane - Nicolab.net
Nicolas Talle
Make a donation via Paypal

About

A base workflow for Golang projects: Docker + Golang + inspiration from standards.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Shell 84.2%
  • Dockerfile 15.8%