Coverage Status

EXPERIMENTAL go source reoreding

This tool is EXPERIMENTAL! We strongly recommend to backup (or use git to commit your changes) before to try it.

This tool will “reorder” your sources to do this:

  • alphabetic reorder you methods and constructors (constructors will be also placed above methods)
  • place methods and constructors above the type definition
  • rewrite (or output) the result


Usage of goreorder:
  -dir string
    	directory to scan (default ".")
  -file string
    	file to process, deactivates -dir if set
  -format string
    	the executable to use to format the output (default "gofmt")
  -output string
    	output file (default to the original file, only works with -file)
    	reorder structs by name (default: false)
    	get some informations while processing
    	show version (master)
    	write the output to the file, if not set it will print to stdout (default: false)

By default, the tool will scan everything in the current directory and output result to standard output (no write).


Get release or use go install[email protected] and download corresponding binary inside your $PATH. You can use this script to install goreorder as user or with sudo, the script will detect if you are simple user and will try to install in $HOME/.local/bin then $HOME/bin it the first one doesn’t exists.

curl -sSL | bash

If you want to install from source:

go install -v

You can also get this repository and type:

git clone [email protected]:metal3d/goreorder.git
cd goreorder
make install


Please fill an issue to create a bug report.

If you want to participate, please fork the repository and propose a pull request.


View Github