第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

docopt.go 奇怪的錯(cuò)誤信息

docopt.go 奇怪的錯(cuò)誤信息

Go
慕妹3242003 2021-09-13 14:48:53
使用 docopt.go 重構(gòu)舊項(xiàng)目并最小化代碼程序如下所示package mainimport (    "fmt"    "github.com/docopt/docopt.go")const Version = `2.0`const Usage = `Usage:    serve [--port] <dir>    serve help | --help    serve --version Options:    -p, --port       port for the sever to listen on    -h, --help       display help information    -v, --version    display Version`func check(err error) {    if err != nil {        panic(err)    }}func main() {    args, err := docopt.Parse(Usage, nil, true, Version, false)    check(err)    port := args["[--port]"].(string)    fmt.Println(args)    fmt.Println(port)v}然而,當(dāng)我運(yùn)行程序go run ./serve.go help期待幫助消息時(shí),我得到了這個(gè)panic: interface conversion: interface is nil, not stringgoroutine 1 [running]:main.main()    /Users/jburns/Development/Gopath/src/github.com/nyumal/serve/serve.go:31 +0x148goroutine 2 [runnable]:runtime.forcegchelper()    /usr/local/Cellar/go/1.4.1/libexec/src/runtime/proc.go:90runtime.goexit()    /usr/local/Cellar/go/1.4.1/libexec/src/runtime/asm_amd64.s:2232 +0x1goroutine 3 [runnable]:runtime.bgsweep()    /usr/local/Cellar/go/1.4.1/libexec/src/runtime/mgc0.go:82runtime.goexit()    /usr/local/Cellar/go/1.4.1/libexec/src/runtime/asm_amd64.s:2232 +0x1goroutine 4 [runnable]:runtime.runfinq()    /usr/local/Cellar/go/1.4.1/libexec/src/runtime/malloc.go:712runtime.goexit()    /usr/local/Cellar/go/1.4.1/libexec/src/runtime/asm_amd64.s:2232 +0x1exit status 2并運(yùn)行g(shù)o run ./serve.go --port 5000它返回相同的東西但是運(yùn)行g(shù)o run ./serve.go --port 5000 .返回Usage:    serve [--port] <dir>    serve help | --help    serve --versionexit status 1我哪里做錯(cuò)了?
查看完整描述

1 回答

?
慕雪6442864

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊

您需要為端口聲明一個(gè)參數(shù):


const Usage = `

Usage:

    serve [--port=<arg>] <dir>

    serve help | --help

    serve --version 


Options:

    -p, --port=<arg> port for the sever to listen on

    -h, --help       display help information

    -v, --version    display Version

使用二值類型斷言來(lái)處理未設(shè)置端口的情況:


port, ok := args["--port"].(string)

if ok {

   // port is set

}

另外,從地圖鍵周圍刪除“[]”。


查看完整回答
反對(duì) 回復(fù) 2021-09-13
  • 1 回答
  • 0 關(guān)注
  • 256 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)