Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error handling and efficiency in Result methods #413

Open
wants to merge 19 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Example of using uncover as library is provided in [examples](examples/main.go)
The default provider configuration file should be located at `$CONFIG/uncover/provider-config.yaml` and has the following contents as an example.


> **Note**: API keys are required needs to be configured before running uncover.
> **Note**: API keys are required and must be configured before running uncover.

```yaml
shodan:
Expand All @@ -130,7 +130,7 @@ censys:
- CENSYS_API_ID_1:CENSYS_API_SECRET_1
- CENSYS_API_ID_2:CENSYS_API_SECRET_2
fofa:
- FOFA_EMAIL_1:FOFA_KEY_2
- FOFA_EMAIL_1:FOFA_KEY_1
- FOFA_EMAIL_2:FOFA_KEY_2
quake:
- QUAKE_TOKEN_1
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ require (
github.com/projectdiscovery/hmap v0.0.38 // indirect
github.com/projectdiscovery/networkpolicy v0.0.7 // indirect
github.com/projectdiscovery/retryabledns v1.0.55 // indirect
github.com/quic-go/quic-go v0.38.1 // indirect
github.com/quic-go/quic-go v0.38.2 // indirect
github.com/refraction-networking/utls v1.5.4 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/syndtr/goleveldb v1.0.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ github.com/projectdiscovery/retryablehttp-go v1.0.45 h1:rpWHbver3qeFUx0Vf0R7VOag
github.com/projectdiscovery/retryablehttp-go v1.0.45/go.mod h1:vTOfQqJa0S2sSGaBhGbgZKltpWFEj4nZm4XP+tKFf0k=
github.com/projectdiscovery/utils v0.0.77 h1:HPLNY/WgVsLaHPBW1XA5XYMkTo9VRjhbOIZs+Lfww7s=
github.com/projectdiscovery/utils v0.0.77/go.mod h1:XkHTUln/MJaWAgber2C0o1Mqacr2s9JMRhOVBjmII7w=
github.com/quic-go/quic-go v0.38.1 h1:M36YWA5dEhEeT+slOu/SwMEucbYd0YFidxG3KlGPZaE=
github.com/quic-go/quic-go v0.38.1/go.mod h1:ijnZM7JsFIkp4cRyjxJNIzdSfCLmUMg9wdyhGmg+SN4=
github.com/quic-go/quic-go v0.38.2 h1:VWv/6gxIoB8hROQJhx1JEyiegsUQ+zMN3em3kynTGdg=
github.com/quic-go/quic-go v0.38.2/go.mod h1:ijnZM7JsFIkp4cRyjxJNIzdSfCLmUMg9wdyhGmg+SN4=
github.com/refraction-networking/utls v1.5.4 h1:9k6EO2b8TaOGsQ7Pl7p9w6PUhx18/ZCeT0WNTZ7Uw4o=
github.com/refraction-networking/utls v1.5.4/go.mod h1:SPuDbBmgLGp8s+HLNc83FuavwZCFoMmExj+ltUHiHUw=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
Expand Down
28 changes: 20 additions & 8 deletions sources/result.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package sources

import (
"encoding/json"
"fmt"
"net"
"strconv"
)

type Result struct {
Expand All @@ -13,22 +14,33 @@ type Result struct {
Host string `json:"host"`
Url string `json:"url"`
Raw []byte `json:"-"`
Error error `json:"-"`
Err error `json:"-"`
}

func (result *Result) IpPort() string {
return net.JoinHostPort(result.IP, fmt.Sprint(result.Port))
return net.JoinHostPort(result.IP, strconv.Itoa(result.Port))
}

func (result *Result) HostPort() string {
return net.JoinHostPort(result.Host, fmt.Sprint(result.Port))
return net.JoinHostPort(result.Host, strconv.Itoa(result.Port))
}

func (result *Result) RawData() string {
return string(result.Raw)
return string(result.Raw)
}

func (result *Result) JSON() (string, error) {
data, err := json.Marshal(result)
if err != nil {
return "", err
}
return string(data), nil
}

func (result *Result) JSON() string {
data, _ := json.Marshal(result)
return string(data)
// Could also be removed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this -I don't think we need this.

func (result *Result) Error() string {
if result.Err == nil {
return result.Err.Error()
}
return ""
}
Loading