Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ipv6 and ipv4 #23

Open
aneeshkp opened this issue Mar 16, 2022 · 1 comment
Open

Support ipv6 and ipv4 #23

aneeshkp opened this issue Mar 16, 2022 · 1 comment

Comments

@aneeshkp
Copy link
Member

Something like this so we support both ipv6 and ipv4


func main() {
	finish := make(chan bool)

	mux := http.NewServeMux()
	mux.HandleFunc("/", handleRequest)

	go func() {
		log.Print(http.ListenAndServe("[127.0.0.1:8001](http://127.0.0.1:8001/)", mux))
	}()

	go func() {
		log.Print(http.ListenAndServe("[::1]:8001", mux))
	}()

	<-finish
}


func handleRequest(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte(fmt.Sprintf("Hello %s\n", r.RemoteAddr)))
}
@jzding
Copy link
Member

jzding commented Mar 16, 2022

Just using the port should support both ipv4 and ipv6 cases, right?

http.ListenAndServe(":8001")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants