How to convert interface{} to string?

前端 未结 3 880
暖寄归人
暖寄归人 2021-01-30 07:38

I\'m using docopt to parse command-line arguments. This works, and it results in a map, such as

map[:www.google.de :80 --help:false --ver         


        
3条回答
  •  被撕碎了的回忆
    2021-01-30 08:31

    You need to add type assertion .(string). It is necessary because the map is of type map[string]interface{}:

    host := arguments[""].(string) + ":" + arguments[""].(string)
    

    Latest version of Docopt returns Opts object that has methods for conversion:

    host, err := arguments.String("")
    port, err := arguments.String("")
    host_port := host + ":" + port
    

提交回复
热议问题