From 84b528b4a5ab08fa75a2005d5b99aaeadea4bfc0 Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Tue, 17 Dec 2024 10:46:17 -0800 Subject: [PATCH] internal/http3: new package Create a package for an HTTP/3 implementation. Internal for now, intended to eventually move to x/net/http3. For golang/go#70914 Change-Id: I3a643fe7958cf75b231ca97f25e9f338554f723c Reviewed-on: https://go-review.googlesource.com/c/net/+/641836 Auto-Submit: Damien Neil Reviewed-by: Jonathan Amsterdam Reviewed-by: Brad Fitzpatrick LUCI-TryBot-Result: Go LUCI --- internal/http3/doc.go | 10 +++++++ internal/http3/files_test.go | 56 ++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 internal/http3/doc.go create mode 100644 internal/http3/files_test.go diff --git a/internal/http3/doc.go b/internal/http3/doc.go new file mode 100644 index 00000000..5530113f --- /dev/null +++ b/internal/http3/doc.go @@ -0,0 +1,10 @@ +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package http3 implements the HTTP/3 protocol. +// +// This package is a work in progress. +// It is not ready for production usage. +// Its API is subject to change without notice. +package http3 diff --git a/internal/http3/files_test.go b/internal/http3/files_test.go new file mode 100644 index 00000000..9c97a6ce --- /dev/null +++ b/internal/http3/files_test.go @@ -0,0 +1,56 @@ +// Copyright 2025 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build go1.24 + +package http3 + +import ( + "bytes" + "os" + "strings" + "testing" +) + +// TestFiles checks that every file in this package has a build constraint on Go 1.24. +// +// Package tests rely on testing/synctest, added as an experiment in Go 1.24. +// When moving internal/http3 to an importable location, we can decide whether +// to relax the constraint for non-test files. +// +// Drop this test when the x/net go.mod depends on 1.24 or newer. +func TestFiles(t *testing.T) { + f, err := os.Open(".") + if err != nil { + t.Fatal(err) + } + names, err := f.Readdirnames(-1) + if err != nil { + t.Fatal(err) + } + for _, name := range names { + if !strings.HasSuffix(name, ".go") { + continue + } + b, err := os.ReadFile(name) + if err != nil { + t.Fatal(err) + } + // Check for copyright header while we're in here. + if !bytes.Contains(b, []byte("The Go Authors.")) { + t.Errorf("%v: missing copyright", name) + } + // doc.go doesn't need a build constraint. + if name == "doc.go" { + continue + } + if !bytes.Contains(b, []byte("//go:build go1.24")) { + t.Errorf("%v: missing constraint on go1.24", name) + } + if bytes.Contains(b, []byte(`"testing/synctest"`)) && + !bytes.Contains(b, []byte("//go:build go1.24 && goexperiment.synctest")) { + t.Errorf("%v: missing constraint on go1.24 && goexperiment.synctest", name) + } + } +}