- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在使用 go1.11 net/http 并想检测域是否仅支持 ipv6。
我创建了自己的 DialContext,因为我想检测域是否仅支持 ipv6。下面的代码
package main
import (
"errors"
"fmt"
"net"
"net/http"
"syscall"
"time"
)
func ModifiedTransport() {
var MyTransport = &http.Transport{
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: false,
Control: func(network, address string, c syscall.RawConn) error {
if network == "ipv4" {
// I want to cancel connection here client.Get("http://myexample.com") return a non-nil err.
return errors.New("you should not use ipv4")
}
return nil
},
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
var myClient = http.Client{Transport: MyTransport}
resp, myerr := myClient.Get("http://www.github.com")
if myerr != nil {
fmt.Println("request error")
return
}
var buffer = make([]byte, 1000)
resp.Body.Read(buffer)
fmt.Println(string(buffer))
}
func main(){
ModifiedTransport();
}
我现在不知道如何关闭请求,即使我可以进入 network == "ipv4"
。
Python 可以通过 Force requests to use IPv4 / IPv6 解决问题.我不知道如何在 golang 中做到这一点。有人可以帮助我吗?非常感谢!
最佳答案
传递给 Control
函数的 network
是用于 IPv4 连接的 tcp4
或用于 IPv6 的 tcp6
连接,如果您正在建立传出 TCP 连接。
来自 type Dialer
的评论:
// Network and address parameters passed to Control method are not
// necessarily the ones passed to Dial. For example, passing "tcp" to Dial
// will cause the Control function to be called with "tcp4" or "tcp6".
(在非 TCP 连接的情况下,other strings 是可能的。)
Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only), "udp", "udp4" (IPv4-only), "udp6" (IPv6-only), "ip", "ip4" (IPv4-only), "ip6" (IPv6-only), "unix", "unixgram" and "unixpacket".
关于golang 强制 net/http 客户端使用 IPv4/IPv6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53055808/
目前部署在 Kubernetes 中的服务,通过 Calico BGP 将 Service 与集群外网络打通,并在外部的 nginx 中配置 Service 地址对外进行服务暴露。经过一段时间的观察
如发现here , 有一种新的 kube 服务是 IPVS 并且有很多负载均衡算法。 唯一的问题是我没有找到指定这些算法的位置。 我的理解: rr:循环法->循环调用后端pod lc:最少连接-> 将
我想尝试这种新的代理模式以及它为我们的一些应用程序提供的各种调度程序。到目前为止,我一直无法找到更改默认模式的方法 iptables至 ipvs在 GKE 节点上。 每个人都说通过--proxy-mo
我想在现有集群中为 IPVS 启用 Kube-proxy 模式。目前,它在 IPtables 上运行。如何在不影响现有工作负载的情况下将其更改为 IPVS? 我已经安装了所有必需的模块来启用它。另外,
我正在开发的应用程序作为 Kubernetes 集群中的部署运行。为此部署创建的 Pod 分布在集群中的各个节点上。我们的应用程序一次只能处理一个 TCP 连接,并且会拒绝进一步的连接。目前,我们使用
我是一名优秀的程序员,十分优秀!