golang.org/x/tools@v0.21.0/go/analysis/passes/httpmux/testdata/src/a/a.go (about)

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // This file contains tests for the httpmux checker.
     6  
     7  package a
     8  
     9  import "net/http"
    10  
    11  func _() {
    12  	http.HandleFunc("GET /x", nil)  // want "enhanced ServeMux pattern"
    13  	http.HandleFunc("/{a}/b/", nil) // want "enhanced ServeMux pattern"
    14  	mux := http.NewServeMux()
    15  	mux.Handle("example.com/c/{d}", nil) // want "enhanced ServeMux pattern"
    16  	mux.HandleFunc("/{x...}", nil)       // want "enhanced ServeMux pattern"
    17  
    18  	// Should not match.
    19  
    20  	// not an enhanced pattern
    21  	http.Handle("/", nil)
    22  
    23  	// invalid wildcard; will panic in 1.22
    24  	http.HandleFunc("/{/a/}", nil)
    25  	mux.Handle("/{1}", nil)
    26  	mux.Handle("/x{a}", nil)
    27  
    28  	// right package, wrong method
    29  	http.ParseTime("GET /")
    30  
    31  	// right function name, wrong package
    32  	Handle("GET /", nil)
    33  	HandleFunc("GET /", nil)
    34  
    35  	// right method name, wrong type
    36  	var sm ServeMux
    37  	sm.Handle("example.com/c/{d}", nil)
    38  	sm.HandleFunc("method /{x...}", nil)
    39  }
    40  
    41  func Handle(pat string, x any)     {}
    42  func HandleFunc(pat string, x any) {}
    43  
    44  type ServeMux struct{}
    45  
    46  func (*ServeMux) Handle(pat string, x any)     {}
    47  func (*ServeMux) HandleFunc(pat string, x any) {}