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

net/http: enhanced ServerMux routing #65231

Closed
kassner opened this issue Jan 23, 2024 · 1 comment
Closed

net/http: enhanced ServerMux routing #65231

kassner opened this issue Jan 23, 2024 · 1 comment

Comments

@kassner
Copy link

kassner commented Jan 23, 2024

Go version

go1.22rc1

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/home/kassner/.cache/go-build'
GOENV='/home/kassner/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/kassner/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/kassner/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/kassner/sdk/go1.22rc1'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/kassner/sdk/go1.22rc1/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='go1.22rc1'
GCCGO='gccgo'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/kassner/workspace/go122test/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1457264763=/tmp/go-build -gno-record-gcc-switches'

What did you do?

package main

import (
	"fmt"
	"io"
	"net/http"
	"sync"
	"time"
)

func main() {
	handler := http.NewServeMux()
	handler.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte(r.URL.Path))
	})

	go http.ListenAndServe(":9090", handler)

	wg := sync.WaitGroup{}
	wg.Add(1)

	go func() {
		defer wg.Done()
		time.Sleep(time.Second)

		resp, err := http.Get("http://localhost:9090/")
		if err != nil {
			panic(err)
		}

		body, _ := io.ReadAll(resp.Body)
		if err != nil {
			panic(err)
		}

		fmt.Println("statusCode:", resp.StatusCode)
		fmt.Println("body:", string(body))
	}()

	wg.Wait()
}

What did you see happen?

statusCode: 404
body: 404 page not found

What did you expect to see?

statusCode: 200
body: /

@kassner
Copy link
Author

kassner commented Jan 23, 2024

Nevermind, I just needed that public shaming adrenaline rush to figure it out:

kassner@raspberrypi:~/workspace/go122test $ cat go.mod 
module test

go 1.21
kassner@raspberrypi:~/workspace/go122test $ ~/go/bin/go1.22rc1 run main.go 
statusCode: 404
body: 404 page not found

kassner@raspberrypi:~/workspace/go122test $ cat go.mod 
module test

go 1.22rc1
kassner@raspberrypi:~/workspace/go122test $ ~/go/bin/go1.22rc1 run main.go 
statusCode: 200
body: /

@kassner kassner closed this as completed Jan 23, 2024
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

1 participant