Goformat and build/install instructions are out of date
I'm using Go 1.20.12 on Linux, and am having difficulty following the instructions in README. Is there a way to install this package from source?
My previous attempts:
go install winterdrache.de/goformat/goformat@latest
go: winterdrache.de/goformat/goformat@latest: unrecognized import path "winterdrache.de/goformat/goformat": reading https://winterdrache.de/goformat/goformat?go-get=1: 503 Service Unavailable
go install github.com/mbenkmann/goformat/goformat@latest
go: github.com/mbenkmann/goformat/goformat@latest: module github.com/mbenkmann/goformat/goformat: git ls-remote -q origin in /home/admin/go/pkg/mod/cache/vcs/fc2683508accf05deecb836eb96b5c21a3fff61d855f41731df56a5751e84490: exit status 128: fatal: unable to access 'https://github.com/mbenkmann/goformat/': Encountered end of file
or:
go: finding module for package winterdrache.de/goformat/printer go/pkg/mod/github.com/mbenkmann/[email protected]/goformat/gofmt.go:23:2: cannot find module providing package winterdrache.de/goformat/printer: unrecognized import path "winterdrache.de/goformat/printer": reading https://winterdrache.de/goformat/printer?go-get=1: 503 Service Unavailable
They changed the way "go get" operates at some point and I haven't updated the package in a long time, so the old way is now broken.
However, you can simply download the source and issue the make command in the directory containing the Makefile.
go version; ls; make
go version go1.20.12 linux/amd64 LICENSE Makefile README.md bin get-upstream-changes goformat patch pkg printer src tabwriter go install winterdrache.de/goformat/goformat go: 'go install' requires a version when current directory is not in a module Try 'go install winterdrache.de/goformat/goformat@latest' to install the latest version make: *** [Makefile:7: build] Error 1
Which version of Go was this package built on?
It works with go version go1.13.8 linux/amd64. I just verified on Ubuntu 20.04 that
unset GOPATH
unset GOROOT
cd /tmp
git clone https://github.com/mbenkmann/goformat.git
cd goformat
make
works fine. If it doesn't work with go1.20.12, then they've made breaking changes to how go install works when they introduced modules. I suggest you read the changelog since go1.13.8. They've surely provided some migration instructions to move to the new system. I am not going to look into this and fix it. I haven't used Go in years. If you fix it, please submit a pull request so that other people can benefit.
Note also that because goformat hasn't been updated in years it will be unable to properly format new language features introduced in recent years. So in order to make full use of it, one would have to merge the changes made to gofmt (which goformat is based on). The script
https://github.com/mbenkmann/goformat/blob/master/get-upstream-changes
was written to help in this task. Again, if you undertake this task, please submit a pull request so that other people can benefit.
I've just committed some improvements to get-upstream-changes. If you want to attempt to update goformat to bring it up to par with upstream gofmt, definitely use the new version of get-upstream-changes.