Skip to content

Commit

Permalink
Group Basic/TLS Flag Groupings in Modules and interface{} -> any (#479)
Browse files Browse the repository at this point in the history
* interface{} -> any

* add flag groupings to clean up CLI
  • Loading branch information
phillip-stephens authored Jan 16, 2025
1 parent 1aec142 commit 0f39281
Show file tree
Hide file tree
Showing 72 changed files with 331 additions and 330 deletions.
2 changes: 1 addition & 1 deletion bin/bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func ZGrab2Main() {
if m, ok := flag.(*zgrab2.MultipleCommand); ok {
iniParser := zgrab2.NewIniParser()
var modTypes []string
var flagsReturned []interface{}
var flagsReturned []any
if m.ConfigFileName == "-" {
modTypes, flagsReturned, err = iniParser.Parse(os.Stdin)
} else {
Expand Down
2 changes: 1 addition & 1 deletion conn_bytelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type readLimitTestConfig struct {
// Call sendReceive(), and check that the input/output match, and that any expected errors / truncation occurs.
func checkedSendReceive(t *testing.T, conn *TimeoutConnection, size int) (result error) {
// helper to report + return an error
tErrorf := func(format string, args ...interface{}) error {
tErrorf := func(format string, args ...any) error {
result = fmt.Errorf(format, args)
t.Error(result)
return result
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/.template/module/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func RegisterModule() {
}

// NewFlags returns a default Flags object.
func (module *Module) NewFlags() interface{} {
func (module *Module) NewFlags() any {
return new(Flags)
}

Expand Down Expand Up @@ -96,7 +96,7 @@ func (scanner *Scanner) Protocol() string {
}

// Scan TODO: describe what is scanned
func (scanner *Scanner) Scan(target zgrab2.ScanTarget) (zgrab2.ScanStatus, interface{}, error) {
func (scanner *Scanner) Scan(target zgrab2.ScanTarget) (zgrab2.ScanStatus, any, error) {
conn, err := target.Open(&scanner.config.BaseFlags)
if err != nil {
return zgrab2.TryGetScanStatus(err), nil, err
Expand Down
2 changes: 1 addition & 1 deletion lib/http/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ func (j *RecordingJar) Cookies(u *url.URL) []*Cookie {
return nil
}

func (j *RecordingJar) logf(format string, args ...interface{}) {
func (j *RecordingJar) logf(format string, args ...any) {
j.mu.Lock()
defer j.mu.Unlock()
fmt.Fprintf(&j.log, format, args...)
Expand Down
8 changes: 4 additions & 4 deletions lib/http/clientserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var optQuietLog = func(ts *httptest.Server) {
ts.Config.ErrorLog = quietLog
}

func newClientServerTest(t *testing.T, h2 bool, h Handler, opts ...interface{}) *clientServerTest {
func newClientServerTest(t *testing.T, h2 bool, h Handler, opts ...any) *clientServerTest {
cst := &clientServerTest{
t: t,
h2: h2,
Expand Down Expand Up @@ -185,7 +185,7 @@ type reqFunc func(c *Client, url string) (*Response, error)
ReqFunc reqFunc // optional
CheckResponse func(proto string, res *Response) // optional
EarlyCheckResponse func(proto string, res *Response) // optional; pre-normalize
Opts []interface{}
Opts []any
}
func (tt h12Compare) reqFunc() reqFunc {
Expand Down Expand Up @@ -438,7 +438,7 @@ func TestH12_AutoGzip(t *testing.T) {
func TestH12_AutoGzip_Disabled(t *testing.T) {
h12Compare{
Opts: []interface{}{
Opts: []any{
func(tr *Transport) { tr.DisableCompression = true },
},
Handler: func(w ResponseWriter, r *Request) {
Expand Down Expand Up @@ -1199,7 +1199,7 @@ func TestInterruptWithPanic_ErrAbortHandler_h1(t *testing.T) {
func TestInterruptWithPanic_ErrAbortHandler_h2(t *testing.T) {
testInterruptWithPanic(t, h2Mode, ErrAbortHandler)
}*/
func testInterruptWithPanic(t *testing.T, h2 bool, panicValue interface{}) {
func testInterruptWithPanic(t *testing.T, h2 bool, panicValue any) {
setParallel(t)
const msg = "hello"
defer afterTest(t)
Expand Down
2 changes: 1 addition & 1 deletion lib/http/cookie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ var readSetCookiesTests = []struct {
// Header{"Set-Cookie": {"ASP.NET_SessionId=foo; path=/; HttpOnly, .ASPXAUTH=7E3AA; expires=Wed, 07-Mar-2012 14:25:06 GMT; path=/; HttpOnly"}},
}

func toJSON(v interface{}) string {
func toJSON(v any) string {
b, err := json.Marshal(v)
if err != nil {
return fmt.Sprintf("%#v", v)
Expand Down
2 changes: 1 addition & 1 deletion lib/http/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ type fakeFileInfo struct {
}

func (f *fakeFileInfo) Name() string { return f.basename }
func (f *fakeFileInfo) Sys() interface{} { return nil }
func (f *fakeFileInfo) Sys() any { return nil }
func (f *fakeFileInfo) ModTime() time.Time { return f.modtime }
func (f *fakeFileInfo) IsDir() bool { return f.dir }
func (f *fakeFileInfo) Size() int64 { return int64(len(f.contents)) }
Expand Down
40 changes: 20 additions & 20 deletions lib/http/h2_bundle.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/http/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (s *headerSorter) Swap(i, j int) { s.kvs[i], s.kvs[j] = s.kvs[j], s.kv
func (s *headerSorter) Less(i, j int) bool { return s.kvs[i].key < s.kvs[j].key }

var headerSorterPool = sync.Pool{
New: func() interface{} { return new(headerSorter) },
New: func() any { return new(headerSorter) },
}

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

headerMap := make(map[string]interface{})
headerMap := make(map[string]any)
for k, v := range h {
// Need to special-case unknown header object, since it's not a true header (aka map[string][]string)
if k == "Unknown" && len(v) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion lib/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var aLongTimeAgo = time.Unix(1, 0)
// generic http stuff in random places.

// contextKey is a value for use with context.WithValue. It's used as
// a pointer so it fits in an interface{} without allocation.
// a pointer so it fits in an any without allocation.
type contextKey struct {
name string
}
Expand Down
2 changes: 1 addition & 1 deletion lib/http/httptrace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func WithClientTrace(ctx context.Context, trace *ClientTrace) context.Context {
}
}
if trace.DNSDone != nil {
nt.DNSDone = func(netIPs []interface{}, coalesced bool, err error) {
nt.DNSDone = func(netIPs []any, coalesced bool, err error) {
addrs := make([]net.IPAddr, len(netIPs))
for i, ip := range netIPs {
addrs[i] = ip.(net.IPAddr)
Expand Down
2 changes: 1 addition & 1 deletion lib/http/httputil/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

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

WantDump string
WantDumpOut string
Expand Down
2 changes: 1 addition & 1 deletion lib/http/httputil/non.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func (p *ReverseProxy) copyBuffer(dst io.Writer, src io.Reader, buf []byte) (int
}
}

func (p *ReverseProxy) logf(format string, args ...interface{}) {
func (p *ReverseProxy) logf(format string, args ...any) {
if p.ErrorLog != nil {
p.ErrorLog.Printf(format, args...)
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/http/nettrace/nettrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Trace struct {
// The coalesced parameter is whether singleflight de-dupped
// the call. The addrs are of type net.IPAddr but can't
// actually be for circular dependency reasons.
DNSDone func(netIPs []interface{}, coalesced bool, err error)
DNSDone func(netIPs []any, coalesced bool, err error)

// ConnectStart is called before a Dial, excluding Dials made
// during DNS lookups. In the case of DualStack (Happy Eyeballs)
Expand Down
2 changes: 1 addition & 1 deletion lib/http/requestwrite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

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

// Any of these three may be empty to skip that test.
WantWrite string // Request.Write
Expand Down
16 changes: 8 additions & 8 deletions lib/http/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,8 @@ var readResponseCloseInMiddleTests = []struct {
func TestReadResponseCloseInMiddle(t *testing.T) {
t.Parallel()
for _, test := range readResponseCloseInMiddleTests {
fatalf := func(format string, args ...interface{}) {
args = append([]interface{}{test.chunked, test.compressed}, args...)
fatalf := func(format string, args ...any) {
args = append([]any{test.chunked, test.compressed}, args...)
t.Fatalf("on test chunked=%v, compressed=%v: "+format, args...)
}
checkErr := func(err error, msg string) {
Expand Down Expand Up @@ -722,7 +722,7 @@ func TestReadResponseCloseInMiddle(t *testing.T) {
}
}

func diff(t *testing.T, prefix string, have, want interface{}) {
func diff(t *testing.T, prefix string, have, want any) {
hv := reflect.ValueOf(have).Elem()
wv := reflect.ValueOf(want).Elem()
if hv.Type() != wv.Type() {
Expand Down Expand Up @@ -842,10 +842,10 @@ func TestReadResponseErrors(t *testing.T) {
name string // optional, defaults to in
in string
header Header
wantErr interface{} // nil, err value, or string substring
wantErr any // nil, err value, or string substring
}

status := func(s string, wantErr interface{}) testCase {
status := func(s string, wantErr any) testCase {
if wantErr == true {
wantErr = "malformed HTTP status code"
}
Expand All @@ -856,7 +856,7 @@ func TestReadResponseErrors(t *testing.T) {
}
}

version := func(s string, wantErr interface{}) testCase {
version := func(s string, wantErr any) testCase {
if wantErr == true {
wantErr = "malformed HTTP version"
}
Expand All @@ -867,7 +867,7 @@ func TestReadResponseErrors(t *testing.T) {
}
}

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

// wantErr can be nil, an error value to match exactly, or type string to
// match a substring.
func matchErr(err error, wantErr interface{}) error {
func matchErr(err error, wantErr any) error {
if err == nil {
if wantErr == nil {
return nil
Expand Down
Loading

0 comments on commit 0f39281

Please sign in to comment.