我写了 2 个函数v1GetSessionID和v1SessionIDforBind。/* * v1GetSessionID */func v1GetSessionID(c *gin.Context, app *firebase.App, client *firestore.Client, stripcallGetSession func() func(internalUserID string, customerID string) (sessionid string, err error)) (sessionid string, err error) { defer erapse.ShowErapsedTIme(time.Now()) idToken := c.Param("idToken") user, err := idToken2User(app, idToken) if err != nil {return} customerID, err := user.getCustomerID() if err != nil {return} sessionid, err = stripcallGetSession()(user.getInternalID(), customerID) return}/* * v1SessionIDforBind */func v1SessionIDforBind(c *gin.Context, app *firebase.App, client *firestore.Client) { defer erapse.ShowErapsedTIme(time.Now()) var requestBody JsonPurchaseBindSessionRequest if err := c.ShouldBindJSON(&requestBody); err != nil { okngErrorOut(c, err) return } stripcallGetSession := func() func(internalUserID string, customerID string) (sessionid string, err error) { return func(internalUserID string, customerID string)(sessionid string, err error){return stripeGetSessionIDforBind(requestBody, internalUserID, customerID)} } sessionid, err := v1GetSessionID(c, app, client, stripcallGetSession)() if err != nil { log.Println(err) okngErrorOut(c, err) } else { c.JSON(http.StatusOK, gin.H{ "SessionID": sessionid, }) }}在后一个函数的中间,我将前者称为如下; sessionid, err := v1GetSessionID(c, app, client, stripcallGetSession)()但是 go 编译器在单值上下文中将其指示为多值。go run *.go# command-line-arguments./v1handler.go:332:34: multiple-value v1GetSessionID() in single-value contextv1GetSessionID 返回 sessionid 字符串的 2 个值,err 错误,我已通过sessionid,err收到它。那么为什么我有上面提到的错误呢?go 版本为:go1.14.4 linux/arm。
1 回答
饮歌长啸
TA贡献1951条经验 获得超3个赞
在对 v1GetSessionID() 的调用中有一组额外的括号。你用 4 个参数调用它,它会返回两个这样的值。但是通过在初始调用之后放置额外的括号,您要求 Go 然后执行返回值,就好像它是一个函数一样,这就是编译器似乎在抱怨的。简单示例: https: //play.golang.org/p/ZX9kp6rxA09
只需删除第二组括号,它应该可以编译:
sessionid, err := v1GetSessionID(c, app, client, stripcallGetSession)
- 1 回答
- 0 关注
- 134 浏览
添加回答
举报
0/150
提交
取消