Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

As a Go "newb" I'm not sure why I'm receiving the errors undefined err and undefinded user in the console when compiling the program.

I have:

if req.Id == nil {
    user, err := signup(C, c, &req)
} else {
    user, err := update(C, c, &req)
}

if err != nil {
    c.JSON(http.StatusOK, err)
    return
}

doSomethingWith(user)

I realise I could probably declare the err and user variables before the conditional block but I would like to know why this doesn't work. Is it something to do with creating two new variables in one go?

UDPATE Getting in a bit of a mess with this.

I've now got:

user := core.User{}
if req.Id == nil {
    user, err := signup(C, c, &req)
} else {
    user, err := update(C, c, &req)
}

cleanUser(&user)

and my errors now are user declared and not used. I'm not tackling the err part at the moment but I'm unsure why I'm getting errors about the user.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.4k views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...