Skip to content

Commit 0f39281

Browse files
Group Basic/TLS Flag Groupings in Modules and interface{} -> any (zmap#479)
* interface{} -> any * add flag groupings to clean up CLI
1 parent 1aec142 commit 0f39281

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+331
-330
lines changed

bin/bin.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func ZGrab2Main() {
114114
if m, ok := flag.(*zgrab2.MultipleCommand); ok {
115115
iniParser := zgrab2.NewIniParser()
116116
var modTypes []string
117-
var flagsReturned []interface{}
117+
var flagsReturned []any
118118
if m.ConfigFileName == "-" {
119119
modTypes, flagsReturned, err = iniParser.Parse(os.Stdin)
120120
} else {

conn_bytelimit_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type readLimitTestConfig struct {
6565
// Call sendReceive(), and check that the input/output match, and that any expected errors / truncation occurs.
6666
func checkedSendReceive(t *testing.T, conn *TimeoutConnection, size int) (result error) {
6767
// helper to report + return an error
68-
tErrorf := func(format string, args ...interface{}) error {
68+
tErrorf := func(format string, args ...any) error {
6969
result = fmt.Errorf(format, args)
7070
t.Error(result)
7171
return result

integration_tests/.template/module/scanner.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func RegisterModule() {
4747
}
4848

4949
// NewFlags returns a default Flags object.
50-
func (module *Module) NewFlags() interface{} {
50+
func (module *Module) NewFlags() any {
5151
return new(Flags)
5252
}
5353

@@ -96,7 +96,7 @@ func (scanner *Scanner) Protocol() string {
9696
}
9797

9898
// Scan TODO: describe what is scanned
99-
func (scanner *Scanner) Scan(target zgrab2.ScanTarget) (zgrab2.ScanStatus, interface{}, error) {
99+
func (scanner *Scanner) Scan(target zgrab2.ScanTarget) (zgrab2.ScanStatus, any, error) {
100100
conn, err := target.Open(&scanner.config.BaseFlags)
101101
if err != nil {
102102
return zgrab2.TryGetScanStatus(err), nil, err

lib/http/client_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ func (j *RecordingJar) Cookies(u *url.URL) []*Cookie {
769769
return nil
770770
}
771771

772-
func (j *RecordingJar) logf(format string, args ...interface{}) {
772+
func (j *RecordingJar) logf(format string, args ...any) {
773773
j.mu.Lock()
774774
defer j.mu.Unlock()
775775
fmt.Fprintf(&j.log, format, args...)

lib/http/clientserver_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ var optQuietLog = func(ts *httptest.Server) {
7474
ts.Config.ErrorLog = quietLog
7575
}
7676

77-
func newClientServerTest(t *testing.T, h2 bool, h Handler, opts ...interface{}) *clientServerTest {
77+
func newClientServerTest(t *testing.T, h2 bool, h Handler, opts ...any) *clientServerTest {
7878
cst := &clientServerTest{
7979
t: t,
8080
h2: h2,
@@ -185,7 +185,7 @@ type reqFunc func(c *Client, url string) (*Response, error)
185185
ReqFunc reqFunc // optional
186186
CheckResponse func(proto string, res *Response) // optional
187187
EarlyCheckResponse func(proto string, res *Response) // optional; pre-normalize
188-
Opts []interface{}
188+
Opts []any
189189
}
190190
191191
func (tt h12Compare) reqFunc() reqFunc {
@@ -438,7 +438,7 @@ func TestH12_AutoGzip(t *testing.T) {
438438
439439
func TestH12_AutoGzip_Disabled(t *testing.T) {
440440
h12Compare{
441-
Opts: []interface{}{
441+
Opts: []any{
442442
func(tr *Transport) { tr.DisableCompression = true },
443443
},
444444
Handler: func(w ResponseWriter, r *Request) {
@@ -1199,7 +1199,7 @@ func TestInterruptWithPanic_ErrAbortHandler_h1(t *testing.T) {
11991199
func TestInterruptWithPanic_ErrAbortHandler_h2(t *testing.T) {
12001200
testInterruptWithPanic(t, h2Mode, ErrAbortHandler)
12011201
}*/
1202-
func testInterruptWithPanic(t *testing.T, h2 bool, panicValue interface{}) {
1202+
func testInterruptWithPanic(t *testing.T, h2 bool, panicValue any) {
12031203
setParallel(t)
12041204
const msg = "hello"
12051205
defer afterTest(t)

lib/http/cookie_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ var readSetCookiesTests = []struct {
283283
// Header{"Set-Cookie": {"ASP.NET_SessionId=foo; path=/; HttpOnly, .ASPXAUTH=7E3AA; expires=Wed, 07-Mar-2012 14:25:06 GMT; path=/; HttpOnly"}},
284284
}
285285

286-
func toJSON(v interface{}) string {
286+
func toJSON(v any) string {
287287
b, err := json.Marshal(v)
288288
if err != nil {
289289
return fmt.Sprintf("%#v", v)

lib/http/fs_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ type fakeFileInfo struct {
607607
}
608608

609609
func (f *fakeFileInfo) Name() string { return f.basename }
610-
func (f *fakeFileInfo) Sys() interface{} { return nil }
610+
func (f *fakeFileInfo) Sys() any { return nil }
611611
func (f *fakeFileInfo) ModTime() time.Time { return f.modtime }
612612
func (f *fakeFileInfo) IsDir() bool { return f.dir }
613613
func (f *fakeFileInfo) Size() int64 { return int64(len(f.contents)) }

lib/http/h2_bundle.go

+20-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/http/header.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (s *headerSorter) Swap(i, j int) { s.kvs[i], s.kvs[j] = s.kvs[j], s.kv
194194
func (s *headerSorter) Less(i, j int) bool { return s.kvs[i].key < s.kvs[j].key }
195195

196196
var headerSorterPool = sync.Pool{
197-
New: func() interface{} { return new(headerSorter) },
197+
New: func() any { return new(headerSorter) },
198198
}
199199

200200
// sortedKeyValues returns h's keys sorted in the returned kvs
@@ -338,7 +338,7 @@ func filterHeaders(h Header) {
338338
func (h Header) MarshalJSON() ([]byte, error) {
339339
filterHeaders(h)
340340

341-
headerMap := make(map[string]interface{})
341+
headerMap := make(map[string]any)
342342
for k, v := range h {
343343
// Need to special-case unknown header object, since it's not a true header (aka map[string][]string)
344344
if k == "Unknown" && len(v) > 0 {

lib/http/http.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var aLongTimeAgo = time.Unix(1, 0)
2424
// generic http stuff in random places.
2525

2626
// contextKey is a value for use with context.WithValue. It's used as
27-
// a pointer so it fits in an interface{} without allocation.
27+
// a pointer so it fits in an any without allocation.
2828
type contextKey struct {
2929
name string
3030
}

lib/http/httptrace/trace.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func WithClientTrace(ctx context.Context, trace *ClientTrace) context.Context {
5050
}
5151
}
5252
if trace.DNSDone != nil {
53-
nt.DNSDone = func(netIPs []interface{}, coalesced bool, err error) {
53+
nt.DNSDone = func(netIPs []any, coalesced bool, err error) {
5454
addrs := make([]net.IPAddr, len(netIPs))
5555
for i, ip := range netIPs {
5656
addrs[i] = ip.(net.IPAddr)

lib/http/httputil/dump_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020

2121
type dumpTest struct {
2222
Req http.Request
23-
Body interface{} // optional []byte or func() io.ReadCloser to populate Req.Body
23+
Body any // optional []byte or func() io.ReadCloser to populate Req.Body
2424

2525
WantDump string
2626
WantDumpOut string

lib/http/httputil/non.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func (p *ReverseProxy) copyBuffer(dst io.Writer, src io.Reader, buf []byte) (int
310310
}
311311
}
312312

313-
func (p *ReverseProxy) logf(format string, args ...interface{}) {
313+
func (p *ReverseProxy) logf(format string, args ...any) {
314314
if p.ErrorLog != nil {
315315
p.ErrorLog.Printf(format, args...)
316316
} else {

lib/http/nettrace/nettrace.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Trace struct {
2323
// The coalesced parameter is whether singleflight de-dupped
2424
// the call. The addrs are of type net.IPAddr but can't
2525
// actually be for circular dependency reasons.
26-
DNSDone func(netIPs []interface{}, coalesced bool, err error)
26+
DNSDone func(netIPs []any, coalesced bool, err error)
2727

2828
// ConnectStart is called before a Dial, excluding Dials made
2929
// during DNS lookups. In the case of DualStack (Happy Eyeballs)

lib/http/requestwrite_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020

2121
type reqWriteTest struct {
2222
Req Request
23-
Body interface{} // optional []byte or func() io.ReadCloser to populate Req.Body
23+
Body any // optional []byte or func() io.ReadCloser to populate Req.Body
2424

2525
// Any of these three may be empty to skip that test.
2626
WantWrite string // Request.Write

lib/http/response_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,8 @@ var readResponseCloseInMiddleTests = []struct {
636636
func TestReadResponseCloseInMiddle(t *testing.T) {
637637
t.Parallel()
638638
for _, test := range readResponseCloseInMiddleTests {
639-
fatalf := func(format string, args ...interface{}) {
640-
args = append([]interface{}{test.chunked, test.compressed}, args...)
639+
fatalf := func(format string, args ...any) {
640+
args = append([]any{test.chunked, test.compressed}, args...)
641641
t.Fatalf("on test chunked=%v, compressed=%v: "+format, args...)
642642
}
643643
checkErr := func(err error, msg string) {
@@ -722,7 +722,7 @@ func TestReadResponseCloseInMiddle(t *testing.T) {
722722
}
723723
}
724724

725-
func diff(t *testing.T, prefix string, have, want interface{}) {
725+
func diff(t *testing.T, prefix string, have, want any) {
726726
hv := reflect.ValueOf(have).Elem()
727727
wv := reflect.ValueOf(want).Elem()
728728
if hv.Type() != wv.Type() {
@@ -842,10 +842,10 @@ func TestReadResponseErrors(t *testing.T) {
842842
name string // optional, defaults to in
843843
in string
844844
header Header
845-
wantErr interface{} // nil, err value, or string substring
845+
wantErr any // nil, err value, or string substring
846846
}
847847

848-
status := func(s string, wantErr interface{}) testCase {
848+
status := func(s string, wantErr any) testCase {
849849
if wantErr == true {
850850
wantErr = "malformed HTTP status code"
851851
}
@@ -856,7 +856,7 @@ func TestReadResponseErrors(t *testing.T) {
856856
}
857857
}
858858

859-
version := func(s string, wantErr interface{}) testCase {
859+
version := func(s string, wantErr any) testCase {
860860
if wantErr == true {
861861
wantErr = "malformed HTTP version"
862862
}
@@ -867,7 +867,7 @@ func TestReadResponseErrors(t *testing.T) {
867867
}
868868
}
869869

870-
contentLength := func(status, body string, wantErr interface{}, header Header) testCase {
870+
contentLength := func(status, body string, wantErr any, header Header) testCase {
871871
return testCase{
872872
name: fmt.Sprintf("status %q %q", status, body),
873873
in: fmt.Sprintf("HTTP/1.1 %s\r\n%s", status, body),
@@ -937,7 +937,7 @@ func TestReadResponseErrors(t *testing.T) {
937937

938938
// wantErr can be nil, an error value to match exactly, or type string to
939939
// match a substring.
940-
func matchErr(err error, wantErr interface{}) error {
940+
func matchErr(err error, wantErr any) error {
941941
if err == nil {
942942
if wantErr == nil {
943943
return nil

0 commit comments

Comments
 (0)