Comments (6)
I just did go mod init
in a GB-using directory and it automatically picked up vendor/manifest
and created a mostly reasonable go.mod
for me (at least as much as it can given that vendor/manifest
doesn't persist things like tags by default):
$ GO111MODULE=on go mod init
go: creating new go.mod: module foobar
go: copying requirements from vendor/manifest
from gb.
I do this
$ pushd /Users/me/awesome.io/secret/sauce
$ ls
src/
vendor/
static/
bin/
README.md
$ GO111MODULE=on go mod init
go: cannot determine module path for source directory /Users/me/awesome.io/secret/sauce (outside GOPATH, no import comments)
(note: there's some other files that show up in ls that I don't think are relevant - docker, circleci, etc, but this is an inherited codebase, so I don't know too much yet)
I remedy with this:
$ GOPATH=/Users/me
$ export GOPATH
src/sauce/main.go
package sauce // import "awesome.io/secret/sauce"
I get the same result when I rerun.
Now, I don't even know how gb build
knows which files to build or where they are.
from gb.
If you don't understand how gb
currently builds your code, then I'd wager you're going to have a very difficult time understanding how to switch from gb
over to Go modules. Perhaps you need to spend a little more time with the source you're working with first to understand how it works / what it's doing? I'd also recommend spending some time learning how gb
works (it's not very complex at a high level if you understand how go build
works, but it is a little difference since it is a way to avoid the GOPATH
on versions of Go that didn't support modules).
It might also help if you tried a fresh (small) project to get your head wrapped around Go modules before trying to perform this conversion. I'm not a maintainer of gb
(just an interested contributor), but I don't feel like there's really anything for gb
itself to do here (especially since go mod init
already supports gb
's vendor/manifest
file format for conversion).
from gb.
This works fine
gb build
And I am familiar with the current code. And I know how to use go's "normal" way of doing things with abs paths and such. It's important to me to switch the imports over so that I don't have to fight against gb (which, for all the great good it has provided, appears to be unmaintained and is probably not particularly necessary moving forward) for go test
, godoc
, etc, etc.
It seems like gb has brought a lot of value to a lot of people for a long time. I can only imagine it contributed significantly to the community discussion and tooling that has lead to go modules proper.
Could you point me to some small sample projects? I was looking around for quite a bit before I posted here.
from gb.
Sure, just for the sake of illustration (and because it's something I've been meaning to do), I've just converted https://github.com/tianon/gosleep from using gb
to using Go modules:
The only steps I did for the actual conversion were the following:
mv src/gosleep/*.go ./
(so our code isn't using thegb
-introducedsrc/
directory anymore which hides the code from Go's default search paths)- update
main.go
to includepackage main // import "github.com/tianon/gosleep"
(sogo mod
knows where we're supposed to be without aGOPATH
) -
$ GO111MODULE=on go mod init go: creating new go.mod: module github.com/tianon/gosleep go: copying requirements from vendor/manifest $ GO111MODULE=on go mod verify go: finding github.com/jessevdk/go-flags v0.0.0-20170212220246-460c7bb0abd6 go: finding github.com/jinzhu/now v0.0.0-20170212112655-d939ba741945 go: finding go.tianon.xyz/progress v0.0.0-20170120223140-598c27a6e143 go: finding golang.org/x/crypto v0.0.0-20170508154713-122d919ec1ef all modules verified
- as an extra step, I updated
go.mod
to referencegithub.com/jessevdk/go-flags
via thev1.4.0
release version (instead of the commitvendor/manifest
was pointing to) and rango mod tidy
(I also use Docker for building release binaries there, so you can see some Docker-related changes in that commit as well.)
from gb.
Thanks for that. This codebase was heavily steeped in src/
and with so many files and directories a simple mv src/modulename/*.go ./
wasn't the right approach.
FYI: this is what was the most helpful for me after trying govers
and gofmt -w -r '"thing" -> "otherthing"'
, etc:
find . -type f -print0 | xargs -0 sed -i '' 's:"modulename/:"awesome.io/secret/sauce/modulename/:g'
Good old fashioned sed
. Note the sed -i ''
for macOS compat.
I put the leading "
and the trailing /
to disambiguate other occurrences of the module name in the code.
Now that everything compiles again I'll slowly get rid of src/
and refactor the code into separate module repos.
from gb.
Related Issues (20)
- gb should fail early with unknown/unsupported GOOS or GOARCH value
- Error vendoring gb with gb-vendor HOT 2
- gb build does not create bin folder and binary in bin folder HOT 24
- Website needs list of projects using GB
- Gogland (perhaps also others) configuration example HOT 1
- why vendor/src? HOT 1
- gb build fails on centos7 with linking error HOT 6
- have any command copy a package from $GOPATH
- Can't build project in Docker HOT 2
- gb build do not work correctly on windows (can work correctly on linux)
- Build of Go's runtime package fails when cross-compiling with go1.9.4 HOT 6
- horizon HOT 4
- using gb to make a library HOT 2
- Is the gb project dead? HOT 15
- / HOT 1
- gb vendor doesn't work with fish shell HOT 1
- gb + IDE ? HOT 1
- Cross build not working on OSX: cgo_export_static main only allowed in cgo-generated code
- module github.com/constabulary/gb@latest found (v0.4.4), but does not contain package github.com/constabulary/gb/internal/vendor HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gb.