Git Product home page Git Product logo

s3-tools's People

Contributors

beck-8 avatar

Stargazers

 avatar

Watchers

 avatar

s3-tools's Issues

should use transport select ip

type randomRoundTripper struct {
	resolver *net.Resolver
}

func (r *randomRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
	// 解析域名,获取所有 IP 地址
	ips, err := r.resolver.LookupIP(context.Background(), "ip4", req.URL.Hostname())
	if err != nil {
		return nil, err
	}

	// 随机选择一个 IP 地址
	selectedIP := ips[rand.Intn(len(ips))]
	fmt.Println(req.Host, req.URL.Host)

	// 替换请求的 Host 字段为选定的 IP 地址
	req.URL.Host = selectedIP.String()
	fmt.Println(req.Header, req.Host, req.URL.Host, req.Method)

	// 使用默认的 Transport 进行实际的请求
	return http.DefaultTransport.RoundTrip(req)
}
...
func main() {
	// 创建自定义的 RoundTripper
	transport := &randomRoundTripper{
		resolver: net.DefaultResolver,
	}

	// 创建自定义的 Client
	client := &http.Client{
		Transport: transport,
	}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.