golang multiple-value xxx in single-value context
使用下面的程式碼的時候會出現這樣的錯誤,原因是user.Password()
返回值有兩個,但是隻能在fmt.Println
中一個位置只能使用一個值,所以會出現這樣的問題
user := url.UserPassword("username", "password")
fmt.Println("username: ", user.Username())
fmt.Println("password: ", user.Password())
fmt.Println(user.String())
解決方法
:分別定義多個變數儲存返回值,然後作為函式引數一一傳遞即可
// 建立一個Userinfo物件
user := url.UserPassword("username", "password")
fmt.Println("username: ", user.Username())
password, set := user.Password()
// 這樣傳遞!
fmt.Println("password: ", password, set)
fmt.Println(user.String())
相關文章
- Golang中context使用GolangContext
- Golang Context 包詳解GolangContext
- golang中的context包GolangContext
- 深入理解golang:ContextGolangContext
- Golang Context深入理解GolangContext
- 深入理解 Golang 之 contextGolangContext
- golang Context應用舉例GolangContext
- [Tomcat]嚴重: Context [/xxxx] startup failed due to previous errorsTomcatContextAIError
- GOLANG使用Context管理關聯goroutineGolangContext
- Golang context (上下文)是什麼GolangContext
- Golang 高效實踐之併發實踐context篇GolangContext
- golang從context原始碼領悟介面的設計GolangContext原始碼
- 伺服器開發利器 golang context 用法詳解伺服器GolangContext
- GOLANG使用Context實現傳值、超時和取消GolangContext
- golang 執行系統命令 ps aux | grep "xxxx",總是異常退出GolangUX
- 2020-11-30-golang併發模式contextGolang模式Context
- Error querying database. XXXXXXXXXXXXX, No database selected。ErrorDatabase
- Error building Player: Win32Exception: ApplicationName=‘xxxxxxxxxxxxxxxxxx//sdk\tools\zipalign.exe' ...ErrorUIWin32ExceptionAPP
- Internal Error with background job scheduling XXXXXXXXXXXXX.Error
- // @require file://C:xxxxxxxxx.jsUIJS
- mysql Incorrect key file for table ‘/xxxxxxxx/xxxx.MYI'; try to repair itMySqlAI
- undefine macro xxxxxMac
- Spring:錯誤No bean named 'xxxxxxx' availableSpringBeanAI
- Go進階01:golang context 上下文用法詳解(比較好理解)GolangContext
- (徵文模板參考)xx技能樹/職業路線評測-xxxxxxxx
- ContextContext
- Linux下編譯國標GB28181視訊推流元件EasyGBD報錯undefined reference to `xxxxxxxx@GLIBC_xxxxx‘解決Linux編譯元件Undefined
- Maven專案報錯:No bean named 'xxxxxx' availableMavenBeanAI
- [Linux] mutt /xxxx/xxxx/sent is not a mailbox.LinuxAI
- golang,再也不用管道了,exec.Command("bash", "-c", "ps -elf | grep xxx")Golang
- go 上下文:context.ContextGoContext
- C++ vector<std::tuple<XXX, XXX, XXX>>C++
- could not connect to redis Instance at xxx.xxx.xxx.xxx:6379Redis
- 《Lua-in-ConTeXt》02:ConTeXt 計算機Context計算機
- 報錯xxxx of undefinedUndefined
- 理解ContextContext
- Go ContextGoContext
- context包Context