小编sha*_*ren的帖子

如何在golang中编码url参数?

有没有编码 url 的 go 包?我需要在参数(类型在 map[string]interface{} 中输入)在 url 中传输之前对其进行编码。

也许参数喜欢:map[string]interface{}{"app_id":"you_api","app_sign":"md5_base_16","timestamp":"1473655478000"} 如何编码它以及编码结果是什么?

go

4
推荐指数
1
解决办法
9662
查看次数

如何在Golang中将[4]byte{1,2,3,4}转换为“1.2.3.4”?

这是我的代码,用于将字节数组传输到字符串,但失败了:

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

0
推荐指数
2
解决办法
7971
查看次数

标签 统计

go ×2