go - Type interface {} is interface with no methods - Golang -


i using https://github.com/kataras/iris golang web framework. follow mail last question asked here - fetching logged in user info display - golang template

i using code mentioned in previous post like:-

ctx.values().get("user")

and value user set or has "struct" type:-

// users struct below  var user users  // details fetched db , assigned user  // mentioned here http://go-database-sql.org/retrieving.html  // value set ctx.values().set("user", user); 

but after getting value, when use in different handler , print:-

user := ctx.values().get("user") fmt.println(user.id) 

i error:-

user.id undefined (type interface {} interface no methods)

i need in "type assertion" interface. how can "type assert" above value.

please let me know, right way it. thanks

a type assertion that, asserts value given type.

userid := user.(users).id 

use type name, , should work.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -