1
1
Fork 0
mirror of https://github.com/OJ/gobuster.git synced 2024-05-24 03:46:03 +02:00

chore: use errors.New to replace fmt.Errorf with no parameters

This commit is contained in:
ChengenH 2024-04-20 22:09:03 +08:00
parent 308cf9fbaf
commit 4b72b283c4
11 changed files with 30 additions and 21 deletions

View File

@ -117,7 +117,7 @@ func parseDirOptions() (*libgobuster.Options, *gobusterdir.OptionsDir, error) {
}
if pluginOpts.StatusCodes == "" && pluginOpts.StatusCodesBlacklist == "" {
return nil, nil, fmt.Errorf("status-codes and status-codes-blacklist are both not set, please set one")
return nil, nil, errors.New("status-codes and status-codes-blacklist are both not set, please set one")
}
pluginOpts.UseSlash, err = cmdDir.Flags().GetBool("add-slash")

View File

@ -3,6 +3,7 @@ package cmd
import (
"crypto/tls"
"encoding/pem"
"errors"
"fmt"
"os"
"regexp"
@ -113,7 +114,7 @@ func parseBasicHTTPOptions(cmd *cobra.Command) (libgobuster.BasicHTTPOptions, er
}
if pemFile != "" && p12File != "" {
return options, fmt.Errorf("please supply either a pem or a p12, not both")
return options, errors.New("please supply either a pem or a p12, not both")
}
if pemFile != "" {

View File

@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"net"
"net/http"
@ -43,11 +44,11 @@ type GobusterDir struct {
// NewGobusterDir creates a new initialized GobusterDir
func NewGobusterDir(globalopts *libgobuster.Options, opts *OptionsDir) (*GobusterDir, error) {
if globalopts == nil {
return nil, fmt.Errorf("please provide valid global options")
return nil, errors.New("please provide valid global options")
}
if opts == nil {
return nil, fmt.Errorf("please provide valid plugin options")
return nil, errors.New("please provide valid plugin options")
}
g := GobusterDir{
@ -127,7 +128,7 @@ func (d *GobusterDir) PreRun(ctx context.Context, progress *libgobuster.Progress
return &ErrWildcard{url: url, statusCode: wildcardResp, length: wildcardLength}
}
} else {
return fmt.Errorf("StatusCodes and StatusCodesBlacklist are both not set which should not happen")
return errors.New("StatusCodes and StatusCodesBlacklist are both not set which should not happen")
}
return nil
@ -228,7 +229,7 @@ func (d *GobusterDir) ProcessWord(ctx context.Context, word string, progress *li
resultStatus = true
}
} else {
return fmt.Errorf("StatusCodes and StatusCodesBlacklist are both not set which should not happen")
return errors.New("StatusCodes and StatusCodesBlacklist are both not set which should not happen")
}
if (resultStatus && !d.options.ExcludeLengthParsed.Contains(int(size))) || d.globalopts.Verbose {

View File

@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"net"
"net/netip"
@ -47,11 +48,11 @@ func newCustomDialer(server string) func(ctx context.Context, network, address s
// NewGobusterDNS creates a new initialized GobusterDNS
func NewGobusterDNS(globalopts *libgobuster.Options, opts *OptionsDNS) (*GobusterDNS, error) {
if globalopts == nil {
return nil, fmt.Errorf("please provide valid global options")
return nil, errors.New("please provide valid global options")
}
if opts == nil {
return nil, fmt.Errorf("please provide valid plugin options")
return nil, errors.New("please provide valid plugin options")
}
resolver := net.DefaultResolver

View File

@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"net"
"strings"
@ -35,11 +36,11 @@ type GobusterFuzz struct {
// NewGobusterFuzz creates a new initialized GobusterFuzz
func NewGobusterFuzz(globalopts *libgobuster.Options, opts *OptionsFuzz) (*GobusterFuzz, error) {
if globalopts == nil {
return nil, fmt.Errorf("please provide valid global options")
return nil, errors.New("please provide valid global options")
}
if opts == nil {
return nil, fmt.Errorf("please provide valid plugin options")
return nil, errors.New("please provide valid plugin options")
}
g := GobusterFuzz{

View File

@ -5,6 +5,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"net"
"net/http"
@ -26,11 +27,11 @@ type GobusterGCS struct {
// NewGobusterGCS creates a new initialized GobusterGCS
func NewGobusterGCS(globalopts *libgobuster.Options, opts *OptionsGCS) (*GobusterGCS, error) {
if globalopts == nil {
return nil, fmt.Errorf("please provide valid global options")
return nil, errors.New("please provide valid global options")
}
if opts == nil {
return nil, fmt.Errorf("please provide valid plugin options")
return nil, errors.New("please provide valid plugin options")
}
g := GobusterGCS{

View File

@ -5,6 +5,7 @@ import (
"bytes"
"context"
"encoding/xml"
"errors"
"fmt"
"net"
"net/http"
@ -26,11 +27,11 @@ type GobusterS3 struct {
// NewGobusterS3 creates a new initialized GobusterS3
func NewGobusterS3(globalopts *libgobuster.Options, opts *OptionsS3) (*GobusterS3, error) {
if globalopts == nil {
return nil, fmt.Errorf("please provide valid global options")
return nil, errors.New("please provide valid global options")
}
if opts == nil {
return nil, fmt.Errorf("please provide valid plugin options")
return nil, errors.New("please provide valid plugin options")
}
g := GobusterS3{

View File

@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"strings"
"text/tabwriter"
@ -22,11 +23,11 @@ type GobusterTFTP struct {
// NewGobusterTFTP creates a new initialized NewGobusterTFTP
func NewGobusterTFTP(globalopts *libgobuster.Options, opts *OptionsTFTP) (*GobusterTFTP, error) {
if globalopts == nil {
return nil, fmt.Errorf("please provide valid global options")
return nil, errors.New("please provide valid global options")
}
if opts == nil {
return nil, fmt.Errorf("please provide valid plugin options")
return nil, errors.New("please provide valid plugin options")
}
g := GobusterTFTP{

View File

@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"net"
"net/http"
@ -28,11 +29,11 @@ type GobusterVhost struct {
// NewGobusterVhost creates a new initialized GobusterDir
func NewGobusterVhost(globalopts *libgobuster.Options, opts *OptionsVhost) (*GobusterVhost, error) {
if globalopts == nil {
return nil, fmt.Errorf("please provide valid global options")
return nil, errors.New("please provide valid global options")
}
if opts == nil {
return nil, fmt.Errorf("please provide valid plugin options")
return nil, errors.New("please provide valid plugin options")
}
g := GobusterVhost{

View File

@ -48,7 +48,7 @@ func NewHTTPClient(opt *HTTPOptions) (*HTTPClient, error) {
proxyURLFunc = http.ProxyFromEnvironment
if opt == nil {
return nil, fmt.Errorf("options is nil")
return nil, errors.New("options is nil")
}
if opt.Proxy != "" {

View File

@ -3,6 +3,7 @@ package libgobuster
import (
"bufio"
"context"
"errors"
"fmt"
"os"
"strings"
@ -93,7 +94,7 @@ func (g *Gobuster) getWordlist() (*bufio.Scanner, error) {
}
if lines-g.Opts.WordlistOffset <= 0 {
return nil, fmt.Errorf("offset is greater than the number of lines in the wordlist")
return nil, errors.New("offset is greater than the number of lines in the wordlist")
}
// calcutate expected requests
@ -125,7 +126,7 @@ func (g *Gobuster) getWordlist() (*bufio.Scanner, error) {
if err := wordlistScanner.Err(); err != nil {
return nil, fmt.Errorf("failed to skip lines in wordlist: %w", err)
}
return nil, fmt.Errorf("failed to skip lines in wordlist")
return nil, errors.New("failed to skip lines in wordlist")
}
}