有没有编码 url 的 go 包?我需要在参数(类型在 map[string]interface{} 中输入)在 url 中传输之前对其进行编码。
也许参数喜欢:map[string]interface{}{"app_id":"you_api","app_sign":"md5_base_16","timestamp":"1473655478000"}
如何编码它以及编码结果是什么?
这是我的代码,用于将字节数组传输到字符串,但失败了:
package main
import (
"bytes"
"fmt"
)
type IPAddr [4]byte
// TODO: Add a "String() string" method to IPAddr.
func (ip IPAddr) String() string {
s := [][]byte{ip[:]}
//fmt.Println(s)
sep := []byte(".")
return string(bytes.Join(s, sep))
}
func main() {
hosts := map[string]IPAddr{
"loopback": {127, 0, 0, 1},
"googleDNS": {8, 8, 8, 8},
}
for name, ip := range hosts {
fmt.Printf("%v: %v\n", name, ip)
}
}
Run Code Online (Sandbox Code Playgroud)
该程序不会生成预期的输出
loopback: 127.0.0.1
googleDNS: 8.8.8.8
Run Code Online (Sandbox Code Playgroud)
如何在Golang中将[4]byte{1,2,3,4}转换为“1.2.3.4”?
go ×2