iris icon indicating copy to clipboard operation
iris copied to clipboard

undefined: iris.Context - has iris.Context changed to context.Context?

Open adamjaso opened this issue 9 years ago • 2 comments

When registering routes on "iris.Application", I get "iris.Context" errors like ".../main.go:14 undefined: iris.Context" even though "github.com/kataras/iris" has been imported. Changing to import "github.com/kataras/iris/context" and using "context.Context" seems to fix this, but I haven't found any docs that explain this change... Is this just a oversight of refactoring, or am I missing something?

adamjaso avatar Sep 11 '17 20:09 adamjaso

Yes, it is now context.Context

krokite avatar Sep 11 '17 21:09 krokite

I assume that you're using the go version 1.8 and try to use the new type alias iris.Context (introduced at go 1.9) instead of the context.Context from "github.com/kataras/iris/context".

The docs are updated to go 1.9, the real context is located at context.Context so use it as import "github.com/kataras/iris/context" BUT if you're using go version 1.9 you can use the iris.Context instead and omit the context import statement because it's a type alias, a new feature.

The iris.Context is described at the README.md under the Hello World with Go 1.8 section, if you're hosting from go 1.8 it tells you why you want to import the context package.

@krokite It was always context.Context the @adamjaso 's question was about docs because they see iris.Context but as I noted at the first paragraph: all docs and examples are updated to go 1.9 with the iris.Context type alias. Although we kept a section on README for new gophers who using the old go version and have no idea about type alias, as well.

At the end, both iris.Context and context.Context works exactly the same, it's the same type, so it's your choice if you want to import the context package or just use the iris.Context (if go >= 1.9). Simple enough.

hiveminded avatar Sep 12 '17 08:09 hiveminded