How to viswanath function?

Hello.
Want to get the value from the database with a separate function.
Here is a query function to the database:
func getusers(login string) string {
 client := redis.NewClient(&redis.Options{
 Addr: conf.DBREDIS_PORT,
 Password: conf.PASSWORD_REDIS,
 DB: 0,
})
 id, _ := client.HGet("admin:"+login, "id").Result()
 return id
}

To enter this function you need to specify the login is taken from the session.
RendMA func(w http.ResponseWriter, r *http.Request) {
 session, _ := store.Get(r, "sess")

 login := session.Values["AName"]
 idp := getusers(login)

 fmt.Println (id, idp)
}


The compiler swears on this part of the idp := getusers(login)
cannot use login (type interface {}) as type string in argument to the getusers: need type assertion (build)at line 25 col 1
Tell me what's wrong?
July 12th 19 at 16:49
1 answer
July 12th 19 at 16:51
Solution
Types different as here the compiler about this and you said.

login := session.Values["AName"] where login you interface{}

While func getusers(login string) takes an argument of type string.

tobish you need to write funco something like that

RendMA func(w http.ResponseWriter, r *http.Request) {
 session, _ := store.Get(r, "sess")

 login := session.Values["AName"]

 if loginStr, ok := login.(string); ok {
 idp := getusers(loginStr)
 fmt.Println (id, idp)
 } else {
//
}
}

Find more questions by tags Go