types - Expected pointer to struct slice -


i'm working on server in golang.

i have auth-helper authenticates user secure token (its test). error comes when make query (i'm using dep) in authusingcredentials function, outputs following error:

"expected pointer struct slice *[]struct"

if change var result *entities.user var result []entities.user , print result[0] works outputs:

"cannot use result[0] (type entities.user) type *entities.user in argument ah.userentitytomodel"

the auth helper code:

auth.go

package helpers  import (   "fmt"    "server/data/entities"   "server/data/models"   "server/interfaces" )  var authhelper *authhelper  type authhelper struct{}  func init() {     authhelper = &authhelper{} }  func (ah *authhelper) userentitytomodel(_entity *entities.user) (*models.user, error) {   u := models.newuser(_entity, db)     u.username = _entity.username    return u, nil }  func (ah *authhelper) authenticateusingcredentials(_token string) (interfaces.iuser, error) {   var result *entities.user   err := db.where("token", "=", _token).find(result)   if err != nil {     return nil, err   }   if result == nil {     return nil, fmt.errorf("player '%s' not found", _token)   }    playermodel, err := ah.userentitytomodel(result)   if err != nil {     return nil, err   }    return playermodel, nil } 

something should work.

func (ah *authhelper) authenticateusingcredentials(_token string) (interfaces.iuser, error) {   var result *[]entities.user   err := db.where("token", "=", _token).find(result)   if err != nil {     return nil, err   }   if len(result) <= 0 {     return nil, fmt.errorf("player '%s' not found", _token)   }    playermodel, err := ah.userentitytomodel(&(*result)[0])   if err != nil {     return nil, err   }    return playermodel, nil } 

you trying put slice of users in function takes pointer single user.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -