亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在這種情況下,Go 在句法上有什么問題?

在這種情況下,Go 在句法上有什么問題?

Go
慕虎7371278 2022-12-19 18:23:14
我正在嘗試編寫一個函數,但這里的問題讓我感到驚訝。userGroup.Use(        middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error)  {            if username == "joe" && password == "123"{                return true, nil            }            return false, nil        })  // <- error happens here    )userGroup.Use(        middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error)  {            if username == "joe" && password == "123"{                return true, nil            }            return false, nil        })) // <- !!花了一個小時來解決一個錯誤,但結果是最后一個右括號不能隨意浮動。這是分號、逗號或縮進的問題嗎? 我記得 JS 不關心這種東西我得到的錯誤是:missing ',' before newline in argument list |syntax
查看完整描述

1 回答

?
大話西游666

TA貢獻1817條經驗 獲得超14個贊

這是 Golang 分號規則的結果:https ://go.dev/doc/effective_go#semicolons ,其中 Go 在掃描源代碼時添加了一個分號,因此原始源代碼沒有分號。


遵循“如果換行符出現在可以結束語句的標記之后,插入分號”的規則,您之前的代碼如下所示:


userGroup.Use(

        middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error)  {

            if username == "joe" && password == "123"{

                return true, nil

            }

            return false, nil

        });  // <- semicolon added here

    )

這當然是錯誤的并導致錯誤。移動該行的右括號而不是修復該問題。


查看完整回答
反對 回復 2022-12-19
  • 1 回答
  • 0 關注
  • 93 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號