{"id":21616992,"url":"https://github.com/metal3d/goreorder","last_synced_at":"2026-02-24T12:02:11.620Z","repository":{"id":40446650,"uuid":"482834848","full_name":"metal3d/goreorder","owner":"metal3d","description":"Reorder methods, constructors and structs in Go files","archived":false,"fork":false,"pushed_at":"2024-06-17T06:13:16.000Z","size":238,"stargazers_count":6,"open_issues_count":5,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-25T05:09:12.352Z","etag":null,"topics":["formatter","go","golang","tool"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/metal3d.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"metal3d","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":"metal3d","issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2022-04-18T12:16:08.000Z","updated_at":"2024-08-03T04:41:09.000Z","dependencies_parsed_at":"2024-06-19T19:00:18.977Z","dependency_job_id":"7c263fc9-3772-447b-9e71-8733cc4e9ab9","html_url":"https://github.com/metal3d/goreorder","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metal3d%2Fgoreorder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metal3d%2Fgoreorder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metal3d%2Fgoreorder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metal3d%2Fgoreorder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/metal3d","download_url":"https://codeload.github.com/metal3d/goreorder/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248359048,"owners_count":21090468,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["formatter","go","golang","tool"],"created_at":"2024-11-24T22:16:07.651Z","updated_at":"2025-10-28T03:04:57.382Z","avatar_url":"https://github.com/metal3d.png","language":"Go","funding_links":["https://github.com/sponsors/metal3d","https://liberapay.com/metal3d"],"categories":[],"sub_categories":[],"readme":"# EXPERIMENTAL go source reordering\n\n\u003e This tool is **EXPERIMENTAL!** We **strongly** recommend to back up (or use git to commit your changes) before to try it.\n\nThis tool will \"reorder\" your sources:\n\n- Alphabetic reorder your types, vars, const, methods/functions and constructors (constructors will be also placed above methods)\n- Place methods and constructors below the `type` definition\n- Output the result or write or even generate a patch file\n- Use the default internal \"gofmt\" or use your own. That means that `goreorder` can be used in place of your formatting tool\n\n# Install\n\nThere are several possibilities:\n\n- If you have \"go\" on your machine, simply install using (you can replace \"latest\" by a known tag):\n    ```bash\n    go install github.com/metal3d/goreorder/cmd/goreorder@latest\n    ```\n- Visit the [release page](https://github.com/metal3d/goreorder/releases) to download the desired version (to place inside your `$PATH`)\n- Use the installer:\n    ```bash\n    curl -sSL https://raw.githubusercontent.com/metal3d/goreorder/main/repo-tools/install.sh | bash -s\n    ```\n\nThe installer script detects if you are launching it as root or standard user and installs the tool in:\n\n- `$HOME/.local/bin` or `$HOME/bin` for standard user if it exists (it fails if one of these paths doesn't exist)\n- `/usr/local/bin` if you're root user (or using sudo)\n\nYou can also get this repository and build it with the `Makefile`:\n\n```bash\ngit clone git@github.com:metal3d/goreorder.git\ncd goreorder\nmake install\n```\n\n# Basic Usage\n\n```\ngoreorder reorders the types, methods... in a Go\nsource file. By default, it will print the result to stdout. To allow goreorder\nto write to the file, use the -write flag.\n\nUsage:\n  goreorder [flags] [file.go|directory|stdin]\n  goreorder [command]\n\nExamples:\n$ goreorder reorder --write --reorder-types --format gofmt file.go\n$ goreorder reorder --diff ./mypackage\n$ cat file.go | goreorder reorder\n\nAvailable Commands:\n  completion   Generates completion scripts\n  help         Help about any command\n  print-config Print the configuration\n  reorder      Reorder vars, consts, stucts/types/interaces, methods/functions and constructors in a Go source file.\n\nFlags:\n  -h, --help      help for goreorder\n  -v, --version   version for goreorder\n\nUse \"goreorder [command] --help\" for more information about a command.\n```\n\nThe reorder subcommand is the more important part:\n\n```\nReorder vars, consts, stucts/types/interaces, methods/functions and constructors in a Go source file.\n\nUsage:\n  goreorder reorder [flags] [file.go|directory|stdin]\n\nFlags:\n  -d, --diff            Print diff/patch format instead of rewriting the file\n  -f, --format string   Format tool to use (gofmt or goimports) (default \"gofmt\")\n  -h, --help            help for reorder\n  -o, --order strings   Order of elements when rewriting. You can omit elements, in which case they will \n                        be placed in the default order after those you have specified.\n                        There are two specific cases: main and init - if they are not specified in the list, \n                        then they are considered to be functions and will be ordered as such. If you do specify\n                        them, then they will be positioned in the source code in the place you have specified.\n                        - Allowed values are: main, init, const, var, interface, type, func\n                        - Default order is: const,var,interface,type,func\n  -r, --reorder-types   Reordering types in addition to methods\n  -v, --verbose         Verbose output\n  -w, --write           Write result to (source) file instead of stdout\n```\n\nYou can create a `.goreorder` file containing configuration at the root of your project. Use the `goreorder print-config` command (you can redirect the output to the `.goreorder` file).\n\n\u003e Warning, `print-config` shows the current configuration. If the file doesn't exist, so the default values are displayed. If it exists, so the current values are displayed. To reset the file, remove it and rerun the `print-config` subcommand.\n\n# Specific cases for `main()` and `init()` functions\n\nBy default, `main()` and `init()` functions are part of the functions. So they are sorted with the others functions. If you don't want this behavior, you can specify where to place them using the `--order` argument or using the `.goreorder` configuration file.\n\nFor example, in command line:\n```bash\ngoreorder reorder --order const,var,init,main ./\n```\n\nOr in configuration:\n\n```yaml\nformat: gofmt\nwrite: true\nverbose: true\nreorder-types: true\ndiff: false\norder:\n- const\n- var\n- init\n- main\n```\n\n# Avoid destruction with `--diff`\n\nIf your system provides `diff` and `patch` command, it is safier to use the `--diff` option to geneate\na `patch` file. This file can then be used to apply changes, and to revert your changes if it fails.\n\nExample:\n```bash\ngoreorder reorder --diff ./ \u003e reorder.patch\n\n# try to apply\npatch -p1 --dry-run \u003c ./reorder.patch\n# really apply\npatch -p1  \u003c ./reorder.patch\n\n# revert the changes\npatch -p1 -R \u003c ./reorder.patch\n```\n\n# Releases are GPG signed\n\nThe released binaries are signed with GPG. If you want to verify that the release comes from this repository and was built by the author:\n\n```bash\n\n## Optional, you can get and trust the owner GPG key\n# import the key from github\n# install jq before (apt install -y jq, dnf install -y jq, ...)\ngpg --import \u003c(curl -s https://api.github.com/users/metal3d/gpg_keys | jq -r '.[0].raw_key')\n\n# or use keyserver\n_KEY=\"483493B2DD0845DA8F21A26DF3702E3FAD8F76DC\"\ngpg --keyserver hkps://keys.openpgp.org/ --recv-keys ${_KEY~15}\n\n## optional, trust owner key\n_KEY=\"483493B2DD0845DA8F21A26DF3702E3FAD8F76DC\"\necho ${_KEY}:6: | gpg --import-ownertrust\n\n## Binary signature verification\n# get the signature file (.asc) of the right binary\n_REL=\"goreorder-linux-amd64\"\n_SIGNURL=https://github.com/metal3d/goreorder/releases/download/${_REL}.asc\ncurl ${_SIGNURL} -o /tmp/goreorder.asc \nunset _SIGNURL _REL\n\n# get or set the path to the binary file you downloaded / installed\n# _GOREORDERBIN=/path/to/the/binary\n_GOREORDERBIN=$(command -v goreorder)\n\n# check the signature\ngpg --verify /tmp/goreorder.asc $_GOREORDERBIN\nrm /tmp/goreorder.asc\n```\n\n# Contribute\n\nPlease fill an issue to create a bug report.\n\nIf you want to participate, please fork the repository and propose a pull request **on the \"develop\" branch**.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetal3d%2Fgoreorder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetal3d%2Fgoreorder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetal3d%2Fgoreorder/lists"}