How to do a forward compatibility support for go 1.13?

98 views
Skip to first unread message

changkun

unread,
Sep 6, 2019, 10:50:10 AM9/6/19
to golang-nuts
I have upgraded my code to Go 1.13 with newly introduced errors APIs.

However, I am not able to upgrade the production environment Go version which is Go 1.11, which means I have to run Go 1.13 code on a Go 1.11 environment.

What are the way to make my builds both happy on local and production environment with a single code base?

Tyler Compton

unread,
Sep 6, 2019, 12:23:38 PM9/6/19
to changkun, golang-nuts
I think that in general you will have to only use features available to Go 1.11, meaning, of course, that the new methods in the errors package would be off limits. In the mean time you could use golang.org/x/xerrors, which is a superset of the new errors package and I believe will work with 1.11.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/0a915d38-39f4-4083-b730-75320a4eecc6%40googlegroups.com.

Marcin Romaszewicz

unread,
Sep 6, 2019, 12:47:17 PM9/6/19
to changkun, golang-nuts
This may not be the exact answer you're looking for, but there's a package which handles this even better than Go's builtin error package:
Dave Cheney's package is better designed, IMO, and the explicit errors.Wrap() call is more clear than inferring it from your format string.

-- Marcin


--

Tamás Gulácsi

unread,
Sep 6, 2019, 12:59:45 PM9/6/19
to golang-nuts
Use

    import errors "golang.org/x/xerrors"

this way later you only have to replace it with `import "errors"` and `errors.Errorf` with `fmt.Errorf`.
Reply all
Reply to author
Forward
0 new messages