在函数上需要类型断言

I'm trying to learn type assertion and conversion. It's kinda complicated for me.

I have this example: (I'm using gin framework)

type Env struct {
    db *sql.DB
}

func main() {
    r := gin.Default()

    // Initiate session management (cookie-based)
    store := sessions.NewCookieStore([]byte("secret"))
    r.Use(sessions.Sessions("mysession", store))

    db, _ := sql.Open("sqlite3", "./libreread.db")
    defer db.Close()

    env := &Env{db: db}
    r.GET("/", env.GetHomePage)
}

func (e *Env) _GetUserId(email string) int64 {
    rows, err := e.db.Query("SELECT `id` FROM `user` WHERE `email` = ?", email)
    CheckError(err)

    var userId int64
    if rows.Next() {
        err := rows.Scan(&userId)
        CheckError(err)
    }
    rows.Close()

    return userId
}

func (e *Env) GetHomePage(c *gin.Context) {

    session := sessions.Default(c)
    email := session.Get("email")

    if email != nil {
        name := c.Param("bookname")
        userId := e._GetUserId(email) // I'm stuck here.
}

So, in the above code.. I'm setting db Env type and passing it to router functions. From there, I need to call another function. How to do that?

When I call e._GetUserId(email), it says

cannot convert email (type interface {}) to type Env: need type assertion

How to solve this problem?. Do I need to use inferface{} instead of struct for Env type?

Drafting answer based on conversation from my comments.

Method session.Get("email") returns interface{} type.

And method e._GetUserId() accepts string parameter, so you need to do type assertion as string like -

e._GetUserId(email.(string))