alvaroloes / enumer

A Go tool to auto generate methods for your enums
Other
478 stars 111 forks source link

Doesn't work with go modules #35

Closed gudvinr closed 5 years ago

gudvinr commented 5 years ago

With Go 1.11 release and go mod introduction I moved some projects that uses enumer out of $GOPATH and so now it can't generate code when package has some imports either because of built-in dependencies failing or because it just can't find import out of $GOPATH.

E.g. when I try to generate from this MWE:

Click to expand ```go package mwe import ( "log" ) type Type uint8 //go:generate enumer -type=Type -json -transform=snake const ( ConstOne Type = iota ConstTwo ) func init() { var a = ConstOne log.Println("a", a) } ```

You'll get that:

enumer: checking package: mwe.go:4:2: could not import log (type-checking package "log" failed ($GOPATH/src/log/log.go:18:2: could not import fmt (type-checking package "fmt" failed ($GOPATH/src/fmt/format.go:8:2: could not import strconv (type-checking package "strconv" failed ($GOPATH/src/strconv/atof.go:13:8: could not import math (type-checking package "math" failed ($GOPATH/src/math/exp_asm.go:9:8: could not import internal/cpu (type-checking package "internal/cpu" failed ($GOPATH/src/internal/cpu/cpu_x86.go:9:7: CacheLineSize redeclared in this block))))))))))
mwe.go:9: running "enumer": exit status 1
alvaroloes commented 5 years ago

Thanks for reporting. I will try to get some time to rewrite some parts of enumer, fixing these incompatibilities.

gudvinr commented 5 years ago

@alvaroloes thanks. Actually enumer is some good piece of software. I'm using it in almost every new Go project. A lot more useful than cmd/stringer. Especially the snake transform.

Kudos!

amanbolat commented 5 years ago

I created new pull request, that will make some updates to work with go modules. Please review:

36

alvaroloes commented 5 years ago

@amanbolat Reviewed! please see comments

alvaroloes commented 5 years ago

Everything should be working with the latest version (v1.1.0). Please run:

go get -u github.com/alvaroloes/enumer

and verify it is working. @gudvinr Could you please confirm it is working so that I can close the issue?

gudvinr commented 5 years ago

@alvaroloes yep, works like a charm. Finally I can benefit from the greatest tool in the Go world.

alvaroloes commented 5 years ago

Haha, thanks! I'm glad you like it! 😃 Thank you very much for reporting issues and participating in the discussions 👏